mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] octeontx2-pf: handle cn20k_pfvf_mbox_alloc() failure in otx2_pfvf_mbox_init()
@ 2026-11-20 19:24 Elkin Cruz
  0 siblings, 0 replies; only message in thread
From: Elkin Cruz @ 2026-11-20 19:24 UTC (permalink / raw)
  To: Sunil Goutham, Geetha sowjanya, Ratheesh Kannoth,
	Subbaraya Sundeep, Bharat Bhushan, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, llvm, irogers, Elkin Cruz

On CN20K, cn20k_pfvf_mbox_alloc() returns ERR_PTR(-ENOMEM) when
qmem_alloc() fails, but otx2_pfvf_mbox_init() assigns hwbase without
checking IS_ERR(hwbase). On allocation failure, the error pointer is
passed directly into otx2_mbox_init(), which writes reset headers to
hwbase + devid * MBOX_SIZE and crashes the kernel.

In addition, if otx2_mbox_init() fails on CN20K after
cn20k_pfvf_mbox_alloc() succeeded, free_iomem: skips
qmem_free(&pf->pdev->dev, pf->pfvf_mbox_addr), leaking the DMA mailbox
allocation, and if the second otx2_mbox_init(&mbox->mbox_up, ...) call
fails, &mbox->mbox is not destroyed.

Check IS_ERR(hwbase) and update error unwind in otx2_pfvf_mbox_init()
to properly clean up &mbox->mbox, free mailbox memory on CN20K, and
clear pf->mbox_pfvf_wq.

Fixes: 70f8986ecef1 ("octeontx2-pf: CN20K mbox implementation between PF-VF")
Signed-off-by: Elkin Cruz <elkin@google.com>
---
I am trying out a new Clang static analysis linter for ERR_PTR/NULL
handling, and it flagged this code as possibly buggy. The findings were triaged
and fixed with an AI coding assistant, then checked against linux-next (not
runtime-tested on hardware).

Thanks,
Elkin

 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c  | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
index cb602a4adcfb..e6722751de7b 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
@@ -618,6 +618,10 @@ static int otx2_pfvf_mbox_init(struct otx2_nic *pf, int numvfs)
 	 */
 	if (is_cn20k(pf->pdev)) {
 		hwbase = (void __iomem *)cn20k_pfvf_mbox_alloc(pf, numvfs);
+		if (IS_ERR(hwbase)) {
+			err = PTR_ERR(hwbase);
+			goto free_wq;
+		}
 	} else {
 		/* On CN10K platform, PF <-> VF mailbox region follows after
 		 * PF <-> AF mailbox region.
@@ -644,7 +648,7 @@ static int otx2_pfvf_mbox_init(struct otx2_nic *pf, int numvfs)
 	err = otx2_mbox_init(&mbox->mbox_up, hwbase, pf->pdev, pf->reg_base,
 			     MBOX_DIR_PFVF_UP, numvfs);
 	if (err)
-		goto free_iomem;
+		goto destroy_mbox;
 
 	for (vf = 0; vf < numvfs; vf++) {
 		mbox->pfvf = pf;
@@ -655,11 +659,18 @@ static int otx2_pfvf_mbox_init(struct otx2_nic *pf, int numvfs)
 
 	return 0;
 
+destroy_mbox:
+	otx2_mbox_destroy(&mbox->mbox);
 free_iomem:
-	if (hwbase && !(is_cn20k(pf->pdev)))
+	if (is_cn20k(pf->pdev)) {
+		qmem_free(&pf->pdev->dev, pf->pfvf_mbox_addr);
+		pf->pfvf_mbox_addr = NULL;
+	} else if (hwbase) {
 		iounmap(hwbase);
+	}
 free_wq:
 	destroy_workqueue(pf->mbox_pfvf_wq);
+	pf->mbox_pfvf_wq = NULL;
 	return err;
 }
 
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20 19:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 19:24 [PATCH net] octeontx2-pf: handle cn20k_pfvf_mbox_alloc() failure in otx2_pfvf_mbox_init() Elkin Cruz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®