RE: [EXTERNAL] [PATCH net] octeontx2-pf: handle cn20k_pfvf_mbox_alloc() failure in otx2_pfvf_mbox_init()
From: Geethasowjanya Akula
Date: Mon Nov 23 2026 - 22:32:29 EST
>-----Original Message-----
>From: Elkin Cruz <elkin@xxxxxxxxxx>
>Sent: Saturday, November 21, 2026 12:54 AM
>To: Sunil Kovvuri Goutham <sgoutham@xxxxxxxxxxx>; Geethasowjanya Akula
><gakula@xxxxxxxxxxx>; Ratheesh Kannoth <rkannoth@xxxxxxxxxxx>;
>Subbaraya Sundeep Bhatta <sbhatta@xxxxxxxxxxx>; Bharat Bhushan
><bbhushan2@xxxxxxxxxxx>; Andrew Lunn <andrew+netdev@xxxxxxx>; David
>S. Miller <davem@xxxxxxxxxxxxx>; Eric Dumazet <edumazet@xxxxxxxxxx>;
>Jakub Kicinski <kuba@xxxxxxxxxx>; Paolo Abeni <pabeni@xxxxxxxxxx>
>Cc: netdev@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx;
>llvm@xxxxxxxxxxxxxxx; irogers@xxxxxxxxxx; Elkin Cruz <elkin@xxxxxxxxxx>
>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@xxxxxxxxxx>
>---
>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@xxxxxxxxxxx>