From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9872A224B05; Tue, 21 Jul 2026 22:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784673986; cv=none; b=G/SajC811DtgVisLDxJ/+RmPJJQlktkgguMtWLko0wVvCBVX2S3+Jf80UuAQSKRAq9mWAcXV62vzJc0jfJ0PivdzadhKsEv0WCtNGV2TZtzXLYk/ikJmqm/5kEuCylyGkctGZCdjzvhU/RPDgivihiS8z+NLR7efQAKz5SunZK4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784673986; c=relaxed/simple; bh=x0RPrHiskJg2v+J4ws8Pq7xTCaDhXpbTev+yh+hI1kc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b+KcbAbfB/gCC6j+zauQYvRRnD6x2oNBawkSHwKU7g5bRD3GAGZBZAiD/Gz6cMCAEoKaf6zjNcV0FKqbfXh58hqEpOZzlcTfF9xe4bnRfVcPFFG9Cr3V5ha9leVxrnZZAs2MMtPjsDQ6fb7f38mgRpEnTYx5fMwZWXvcHYjQ0fQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Z9mMXB3Z; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Z9mMXB3Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AFEC1F000E9; Tue, 21 Jul 2026 22:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784673985; bh=Fk+s/aXXEY8N5o+KdxAwdvQFJt2RhN+aRuHwpSFl9eo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Z9mMXB3ZriCpZ8SkUtwtt8MWl1qrK8CRNJScCGbv4toZVOHxPoLqZ1iOl6KsjrWJe LJa02mwYIAT461eZ5RWcQn+fVXpRVWMT39+8/79lLEHuIuK+Wl5NMDq0zEXlU4SDL/ zMBCAK2AgfRUNucyUdfxPOoNSIxLl9m0eHKYLp9Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ruoyu Wang , Simon Horman , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 371/699] net: sungem: fix probe error cleanup Date: Tue, 21 Jul 2026 17:22:10 +0200 Message-ID: <20260721152404.063695991@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152355.667394603@linuxfoundation.org> References: <20260721152355.667394603@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ruoyu Wang [ Upstream commit 36dea2f639249460d13f6ca66b2a9064187cd34d ] gem_init_one() calls gem_remove_one() when register_netdev() fails. gem_remove_one() unregisters and frees resources owned by the net_device, including the DMA block, MMIO mapping, PCI regions, and the net_device itself. gem_init_one() then falls through to its own cleanup labels and frees the same resources again. Keep the register_netdev() error path in gem_init_one(): clear drvdata so PM/remove paths do not see a half-registered device, remove the NAPI instance added during probe, and let the existing cleanup labels release the resources once. The issue was found by a local static-analysis checker for probe error paths. The reported path was manually inspected before sending this fix. Compile-tested with CONFIG_SUNGEM=y. Runtime testing was not performed because no sungem hardware is available. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Ruoyu Wang Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260623025759.3468566-1-ruoyuw560@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/sun/sungem.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/sun/sungem.c b/drivers/net/ethernet/sun/sungem.c index 4d6a9f02c7388d..0cd80b27d8598c 100644 --- a/drivers/net/ethernet/sun/sungem.c +++ b/drivers/net/ethernet/sun/sungem.c @@ -2983,10 +2983,10 @@ static int gem_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->max_mtu = GEM_MAX_MTU; /* Register with kernel */ - if (register_netdev(dev)) { + err = register_netdev(dev); + if (err) { pr_err("Cannot register net device, aborting\n"); - err = -ENOMEM; - goto err_out_free_consistent; + goto err_out_clear_drvdata; } /* Undo the get_cell with appropriate locking (we could use @@ -3000,8 +3000,13 @@ static int gem_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->dev_addr); return 0; +err_out_clear_drvdata: + pci_set_drvdata(pdev, NULL); + netif_napi_del(&gp->napi); + err_out_free_consistent: - gem_remove_one(pdev); + dma_free_coherent(&pdev->dev, sizeof(struct gem_init_block), + gp->init_block, gp->gblock_dvma); err_out_iounmap: gem_put_cell(gp); iounmap(gp->regs); -- 2.53.0