From nobody Wed Apr 20 14:31:00 2022 X-Original-To: dev-commits-src-all@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 DDC9C11E0FD7; Wed, 20 Apr 2022 14:31:00 +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 4Kk34h5zPgz3Qqf; Wed, 20 Apr 2022 14:31:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650465060; 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=S8dh84YE0r2fat/Ufy9natFyXDbeDx5Py84M3f3qlHo=; b=gy99X8cuZ6/tmV1zwHXG4FPNjJJu5t2izi54eH6jeq71knmZLh/fQ6d7NuyW8cFKvMGu9f brMWB+yVdHddu3mxeQZfPjRt3zqKDTeRtsPzQBOILow2MqCO+gtrj1lQisw4QVIqCyCejZ 6e4RVfMOMf+j7I+5m9qN+08j5y18eurIe0Sla50MT5JTgswEa/F1Y9Utit7WQRqjVS7EXv Ul4VFRwDhhWZ0w72lJ5jQTpWPeU0E3pNUEFxKqVJm2O8nIw012tuPdwGL7rc7gfi/tdJcK u1fI8w5RY9vu0/yJ9BOd8vC1/IYcfMAO5IlLtAGnYYy66y5CCpGNjMj1+d14AQ== 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 ADF7A1557B; Wed, 20 Apr 2022 14:31:00 +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 23KEV023021802; Wed, 20 Apr 2022 14:31:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23KEV0JH021801; Wed, 20 Apr 2022 14:31:00 GMT (envelope-from git) Date: Wed, 20 Apr 2022 14:31:00 GMT Message-Id: <202204201431.23KEV0JH021801@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 7a4790dc83d7 - stable/13 - if_axgbe: properly release resource in error case List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 7a4790dc83d7bf58b18ba0920a64d54253e30b92 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650465060; 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=S8dh84YE0r2fat/Ufy9natFyXDbeDx5Py84M3f3qlHo=; b=BFKP1Yvxvny7p0qPYJjseunCPrPxamEtrfAc0L9G7o3gJFSYIJqD6RMlaZyKBeC/LUJVD3 o7AJtF0+UkVN9NLgV7dFnHqtyrkzMu1emruVMLoe3iQMTVSc4dylc4pgw+fi9iES19w0Fn zJiSh4WMiUdxFGU4/B2OnPm2y5f+TlPOEJ3QhEY7uokwxVZavCsj+ZezjxO0vFvodo0LoC 1DpsDzfSd+SFAk5dW4T4AzcYYTC54JxHEi0VJwYyFyd1CxFi36E7Qi+wPdjWncmKQLzet+ I1FXqnoJ+MSqzOg4vqM6fMOamt+8UJvd9u2XsgvkB+wDMmmHSUjt24qRGe+ghQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650465060; a=rsa-sha256; cv=none; b=suKgBCN+PvD/uPyYUef8gUgRtXygFuUbrpEPmRN4rMSP7zQ4L+QQvZXrJAXsJpXP9BYMMu 3TZ3vfOJpNR0qzjltpkFDygqkFv8g+rqpJrRZSm5jvQF7ZjJhgBaiLShnRWdGrJU4xyOXM kkGvvaGfXkPiQEyS85CKn9mJvBY7VHCtIC+tHRsh15muSsJet5dyRjs3TqglepN9suEt35 /hs2v0hUqmxTExWu9NuzUO+oxXsjZDnBTFeIh99VGzGiLQZQkxll4fj9otW2lZXlVw3YtZ aBVjiRmwTxu8j2aX0S8auq9neCTKhECop7tLVGqCbKMl14XgnkiS6Pbpzc3tsQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7a4790dc83d7bf58b18ba0920a64d54253e30b92 commit 7a4790dc83d7bf58b18ba0920a64d54253e30b92 Author: Tong Zhang AuthorDate: 2022-04-11 13:51:53 +0000 Commit: Mark Johnston CommitDate: 2022-04-20 14:14:39 +0000 if_axgbe: properly release resource in error case PR: 262899 Reviewed by: markj (cherry picked from commit 57f7a82fbb4299a255c2c20ec812258004a90631) --- 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 fe42aaac6568..7d7c1acb792b 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) { @@ -1799,14 +1845,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