From nobody Mon Apr 11 14:11:21 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4A0591A992AF; Mon, 11 Apr 2022 14:11:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KcW4B0ShHz3KCx; Mon, 11 Apr 2022 14:11:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649686282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pL6k2TSDtLmdhPoMnOzU/igtKJRSomvWH4FkAiPjFpU=; b=AzsBMMw5GQNprcQi4wdH/OVj1FSF+TqasVU9mac9jlFNMMBjxLd5FuccNgXIUnzatINe9y jiGzXmj9+uJVxqjHqQ1JEkzU5JVbwCjZ21/ta1ibYEjNva3xFftn2xooAdO/P5GrL921mw GR4nwk9O9Iy/Qjb5H9bJoDsHK2XI3cUx+t55y1fJA/A6iSw7HDZGqV7oKaS9fmKoQLyF35 5Klugri/UbYMX+Ky326kZKWISlNTeExy/GPxzDq0kxrvGMt/F4wP0qfe8HfAxDgeYMKqxz A+gu+nifhW5kyRexMbEgB6LBVwjqx+NZNFUyjpjXFcxQ5eJ8Veyi7FZ+FIUHdQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DAC3623CE5; Mon, 11 Apr 2022 14:11:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23BEBLri069555; Mon, 11 Apr 2022 14:11:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23BEBL7T069554; Mon, 11 Apr 2022 14:11:21 GMT (envelope-from git) Date: Mon, 11 Apr 2022 14:11:21 GMT Message-Id: <202204111411.23BEBL7T069554@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 57f7a82fbb42 - main - if_axgbe: properly release resource in error case List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 57f7a82fbb4299a255c2c20ec812258004a90631 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649686282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pL6k2TSDtLmdhPoMnOzU/igtKJRSomvWH4FkAiPjFpU=; b=huVhab5AbIXt8OWW6mRK9WFnwzzefYQSWQuWljo58fB6wTYqHq7NES8G6u3q9/yJ3Wg6ly hV2DF/C0EMUaBQ4gLN2fM+dlA3L7bKKXsjRY1HOEP2bc/Y9a8GIdhk6VcuYayiGZS0HLli 9u3PojO+ZTfP8WojcIZb6uASCeFejYb/5WW0HN/orrJqYQDbZqFwzqzmFmcH8pNrRl5BHG wEqHhGln2aESGuAUA8yno+xy7ZglNTrvZNJLE1C61dbc9PBq46TiidOhioVAtli+aGirB2 42MFBOmHrj+GHyEf4Du5/yOasck2YCzYTVU9HyguAMh8HaRbe/6fjwgrk376pQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649686282; a=rsa-sha256; cv=none; b=rsEeLbXMrp0vra+ce5671OAR/kBbcLmuVNa4gauQ2TEbylCEkijY7c8R6avAZASd01ekEq j0UIfep2pe6GGt+NCMFABxaHiEmAOsx9JcPlnz//MKSuMHFc4eFXL2KWJmnDckDdgqIq9W 1OJ2a3htQI53Ty5yEm6J22o9OXCXvV8qwgMW5Zl3WMix1x/0Qyno8dQb+VTJRbYvxX+C2H 2Rb+UyYJ7GWj3AO3YySJYep59MZh9vWk/qXBp/c4J7smbhuhQIMxe5L3bJrYmmI+lE6osY +UCG/pabSCTzeY0aJXwv9QvpXmn1PPeRQuLa+F6YZizwTjDJ+rVrEKfZIY0xUA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=57f7a82fbb4299a255c2c20ec812258004a90631 commit 57f7a82fbb4299a255c2c20ec812258004a90631 Author: Tong Zhang AuthorDate: 2022-04-11 13:51:53 +0000 Commit: Mark Johnston CommitDate: 2022-04-11 13:52:32 +0000 if_axgbe: properly release resource in error case PR: 262899 Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D34628 --- sys/dev/axgbe/if_axgbe_pci.c | 65 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/sys/dev/axgbe/if_axgbe_pci.c b/sys/dev/axgbe/if_axgbe_pci.c index 9ac640bac846..2a3911cf93cd 100644 --- a/sys/dev/axgbe/if_axgbe_pci.c +++ b/sys/dev/axgbe/if_axgbe_pci.c @@ -77,6 +77,7 @@ static void axgbe_if_init(if_ctx_t); static int axgbe_if_tx_queues_alloc(if_ctx_t, caddr_t *, uint64_t *, int, int); static int axgbe_if_rx_queues_alloc(if_ctx_t, caddr_t *, uint64_t *, int, int); static int axgbe_alloc_channels(if_ctx_t); +static void axgbe_free_channels(struct axgbe_if_softc *); static void axgbe_if_queues_free(if_ctx_t); static int axgbe_if_tx_queue_intr_enable(if_ctx_t, uint16_t); static int axgbe_if_rx_queue_intr_enable(if_ctx_t, uint16_t); @@ -394,6 +395,7 @@ axgbe_if_attach_pre(if_ctx_t ctx) device_t dev; unsigned int ma_lo, ma_hi; unsigned int reg; + int ret; sc = iflib_get_softc(ctx); sc->pdata.dev = dev = iflib_get_dev(ctx); @@ -423,8 +425,11 @@ axgbe_if_attach_pre(if_ctx_t ctx) sc->pdata.vdata = &xgbe_v2b; /* PCI setup */ - if (bus_alloc_resources(dev, axgbe_pci_mac_spec, mac_res)) - return (ENXIO); + if (bus_alloc_resources(dev, axgbe_pci_mac_spec, mac_res)) { + axgbe_error("Unable to allocate bus resources\n"); + ret = ENXIO; + goto free_vlans; + } sc->pdata.xgmac_res = mac_res[0]; sc->pdata.xpcs_res = mac_res[1]; @@ -465,7 +470,8 @@ axgbe_if_attach_pre(if_ctx_t ctx) pdata->mac_addr[5] = (ma_hi >> 8) & 0xff; if (!XP_GET_BITS(ma_hi, XP_MAC_ADDR_HI, VALID)) { axgbe_error("Invalid mac address\n"); - return (EINVAL); + ret = EINVAL; + goto release_bus_resource; } iflib_set_mac(ctx, pdata->mac_addr); @@ -527,7 +533,8 @@ axgbe_if_attach_pre(if_ctx_t ctx) /* Alloc channels */ if (axgbe_alloc_channels(ctx)) { axgbe_error("Unable to allocate channel memory\n"); - return (ENOMEM); + ret = ENOMEM; + goto release_bus_resource; } TASK_INIT(&pdata->service_work, 0, xgbe_service, pdata); @@ -535,13 +542,37 @@ axgbe_if_attach_pre(if_ctx_t ctx) /* create the workqueue */ pdata->dev_workqueue = taskqueue_create("axgbe", M_WAITOK, taskqueue_thread_enqueue, &pdata->dev_workqueue); - taskqueue_start_threads(&pdata->dev_workqueue, 1, PI_NET, + if (pdata->dev_workqueue == NULL) { + axgbe_error("Unable to allocate workqueue\n"); + ret = ENOMEM; + goto free_channels; + } + ret = taskqueue_start_threads(&pdata->dev_workqueue, 1, PI_NET, "axgbe dev taskq"); + if (ret) { + axgbe_error("Unable to start taskqueue\n"); + ret = ENOMEM; + goto free_task_queue; + } /* Init timers */ xgbe_init_timers(pdata); return (0); + +free_task_queue: + taskqueue_free(pdata->dev_workqueue); + +free_channels: + axgbe_free_channels(sc); + +release_bus_resource: + bus_release_resources(dev, axgbe_pci_mac_spec, mac_res); + +free_vlans: + free(pdata->active_vlans, M_AXGBE); + + return (ret); } /* axgbe_if_attach_pre */ static void @@ -739,6 +770,21 @@ axgbe_alloc_channels(if_ctx_t ctx) return (0); } /* axgbe_alloc_channels */ +static void +axgbe_free_channels(struct axgbe_if_softc *sc) +{ + struct xgbe_prv_data *pdata = &sc->pdata; + int i; + + for (i = 0; i < pdata->total_channel_count ; i++) { + free(pdata->channel[i], M_AXGBE); + pdata->channel[i] = NULL; + } + + pdata->total_channel_count = 0; + pdata->channel_count = 0; +} + static void xgbe_service(void *ctx, int pending) { @@ -1785,14 +1831,7 @@ axgbe_if_queues_free(if_ctx_t ctx) channel->rx_ring = NULL; } - /* Free Channels */ - for (i = 0; i < pdata->total_channel_count ; i++) { - free(pdata->channel[i], M_AXGBE); - pdata->channel[i] = NULL; - } - - pdata->total_channel_count = 0; - pdata->channel_count = 0; + axgbe_free_channels(sc); } /* axgbe_if_queues_free */ static void