Building the Linux kernel with Clang and LLVM
 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
  2026-11-24  3:31 ` [EXTERNAL] " Geethasowjanya Akula
  2026-12-01  3:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages 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 related	[flat|nested] 3+ messages in thread

* RE: [EXTERNAL] [PATCH net] octeontx2-pf: handle cn20k_pfvf_mbox_alloc() failure in otx2_pfvf_mbox_init()
  2026-11-20 19:24 [PATCH net] octeontx2-pf: handle cn20k_pfvf_mbox_alloc() failure in otx2_pfvf_mbox_init() Elkin Cruz
@ 2026-11-24  3:31 ` Geethasowjanya Akula
  2026-12-01  3:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Geethasowjanya Akula @ 2026-11-24  3:31 UTC (permalink / raw)
  To: Elkin Cruz, Sunil Kovvuri Goutham, Ratheesh Kannoth,
	Subbaraya Sundeep Bhatta, Bharat Bhushan, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, irogers@google.com



>-----Original Message-----
>From: Elkin Cruz <elkin@google.com>
>Sent: Saturday, November 21, 2026 12:54 AM
>To: Sunil Kovvuri Goutham <sgoutham@marvell.com>; Geethasowjanya Akula
><gakula@marvell.com>; Ratheesh Kannoth <rkannoth@marvell.com>;
>Subbaraya Sundeep Bhatta <sbhatta@marvell.com>; Bharat Bhushan
><bbhushan2@marvell.com>; Andrew Lunn <andrew+netdev@lunn.ch>; David
>S. Miller <davem@davemloft.net>; Eric Dumazet <edumazet@kernel.org>;
>Jakub Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>
>Cc: netdev@vger.kernel.org; linux-kernel@vger.kernel.org;
>llvm@lists.linux.dev; irogers@google.com; Elkin Cruz <elkin@google.com>
>Subject: [EXTERNAL] [PATCH net] octeontx2-pf: handle
>cn20k_pfvf_mbox_alloc() failure in otx2_pfvf_mbox_init()
>
>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

Thanks for the patch.
Reviewed-by: Geetha sowjanya <gakula@marvell.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] octeontx2-pf: handle cn20k_pfvf_mbox_alloc() failure in otx2_pfvf_mbox_init()
  2026-11-20 19:24 [PATCH net] octeontx2-pf: handle cn20k_pfvf_mbox_alloc() failure in otx2_pfvf_mbox_init() Elkin Cruz
  2026-11-24  3:31 ` [EXTERNAL] " Geethasowjanya Akula
@ 2026-12-01  3:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-12-01  3:00 UTC (permalink / raw)
  To: Elkin Cruz
  Cc: sgoutham, gakula, rkannoth, sbhatta, bbhushan2, andrew+netdev,
	davem, edumazet, kuba, pabeni, netdev, linux-kernel, llvm,
	irogers

Hello:

This patch was applied to netdev/net-next.git (main)
by Willem de Bruijn <willemb@google.com>:

On Fri, 20 Nov 2026 19:24:08 +0000 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net] octeontx2-pf: handle cn20k_pfvf_mbox_alloc() failure in otx2_pfvf_mbox_init()
    https://git.kernel.org/netdev/net-next/c/1fdb3da048ab

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-01  3:00 UTC | newest]

Thread overview: 3+ messages (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
2026-11-24  3:31 ` [EXTERNAL] " Geethasowjanya Akula
2026-12-01  3:00 ` patchwork-bot+netdevbpf

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