* [PATCH net] octeontx2: Fix Klocwork issues in AF and PF drivers
@ 2026-07-14 2:02 Ratheesh Kannoth
2026-07-14 15:50 ` Vadim Fedorenko
0 siblings, 1 reply; 2+ messages in thread
From: Ratheesh Kannoth @ 2026-07-14 2:02 UTC (permalink / raw)
To: davem, linux-kernel, naveenm, netdev, sgoutham
Cc: andrew+netdev, edumazet, kuba, pabeni, richardcochran,
Suman Ghosh, Ratheesh Kannoth
From: Suman Ghosh <sumang@marvell.com>
Fix null dereference, uninitialized variable, and error-path resource
leak findings reported by Klocwork across the OcteonTX2 AF and PF code.
Fixes: 818ed8933bd1 ("octeontx2-af: Re-enable MAC TX in otx2_stop processing")
Cc: Naveen Mamindlapalli <naveenm@marvell.com>
Signed-off-by: Suman Ghosh <sumang@marvell.com>
Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
---
drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 12 +++++++++---
.../net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c | 8 +++++---
drivers/net/ethernet/marvell/octeontx2/af/npc.h | 6 +++---
drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 11 ++++++++++-
drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c | 2 +-
drivers/net/ethernet/marvell/octeontx2/af/rvu_cpt.c | 2 +-
.../net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 8 +++++++-
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 2 +-
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c | 2 +-
.../net/ethernet/marvell/octeontx2/nic/otx2_flows.c | 1 +
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 3 +++
drivers/net/ethernet/marvell/octeontx2/nic/qos.c | 1 +
12 files changed, 43 insertions(+), 15 deletions(-)
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
index 2e94d5105016..70c8ef5f0be0 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
@@ -491,12 +491,19 @@ int cgx_lmac_addr_max_entries_get(u8 cgx_id, u8 lmac_id)
u64 cgx_lmac_addr_get(u8 cgx_id, u8 lmac_id)
{
struct cgx *cgx_dev = cgx_get_pdata(cgx_id);
- struct lmac *lmac = lmac_pdata(lmac_id, cgx_dev);
struct mac_ops *mac_ops;
+ struct lmac *lmac;
int index;
u64 cfg;
int id;
+ if (!cgx_dev)
+ return 0;
+
+ lmac = lmac_pdata(lmac_id, cgx_dev);
+ if (!lmac)
+ return 0;
+
mac_ops = cgx_dev->mac_ops;
id = get_sequence_id_of_lmac(cgx_dev, lmac_id);
@@ -1709,10 +1716,10 @@ unsigned long cgx_get_lmac_bmap(void *cgxd)
static int cgx_lmac_init(struct cgx *cgx)
{
u8 max_dmac_filters;
+ u64 lmac_list = 0;
struct lmac *lmac;
int err, filter;
unsigned int i;
- u64 lmac_list;
/* lmac_list specifies which lmacs are enabled
* when bit n is set to 1, LMAC[n] is enabled
@@ -2021,7 +2028,6 @@ static int cgx_probe(struct pci_dev *pdev, const struct pci_device_id *id)
list_add(&cgx->cgx_list, &cgx_list);
-
cgx_populate_features(cgx);
mutex_init(&cgx->lock);
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c b/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c
index d98b49f47970..cc19d16e660f 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c
@@ -632,8 +632,8 @@ int rvu_mbox_handler_mcs_free_resources(struct rvu *rvu,
{
u16 pcifunc = req->hdr.pcifunc;
struct mcs_rsrc_map *map;
+ int rc = -EINVAL;
struct mcs *mcs;
- int rc = 0;
if (req->mcs_id >= rvu->mcs_blk_cnt)
return MCS_AF_ERR_INVALID_MCSID;
@@ -682,8 +682,8 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
{
u16 pcifunc = req->hdr.pcifunc;
struct mcs_rsrc_map *map;
+ int rsrc_id = -EINVAL, i;
struct mcs *mcs;
- int rsrc_id, i;
if (req->mcs_id >= rvu->mcs_blk_cnt)
return MCS_AF_ERR_INVALID_MCSID;
@@ -744,6 +744,8 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
rsp->rsrc_cnt++;
}
break;
+ default:
+ goto exit;
}
rsp->rsrc_type = req->rsrc_type;
@@ -856,7 +858,7 @@ int rvu_mbox_handler_mcs_ctrl_pkt_rule_write(struct rvu *rvu,
static void rvu_mcs_set_lmac_bmap(struct rvu *rvu)
{
struct mcs *mcs = mcs_get_pdata(0);
- unsigned long lmac_bmap;
+ unsigned long lmac_bmap = 0;
int cgx, lmac, port;
for (port = 0; port < mcs->hw->lmac_cnt; port++) {
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/npc.h b/drivers/net/ethernet/marvell/octeontx2/af/npc.h
index eaed172f1606..402cd56b835e 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/npc.h
+++ b/drivers/net/ethernet/marvell/octeontx2/af/npc.h
@@ -522,7 +522,7 @@ struct npc_coalesced_kpu_prfl {
u8 name[NPC_NAME_LEN]; /* KPU Profile name */
u64 version; /* KPU firmware/profile version */
u8 num_prfl; /* No of NPC profiles. */
- u16 prfl_sz[];
+ u16 prfl_sz[0];
};
struct npc_mcam_kex {
@@ -549,7 +549,7 @@ struct npc_kpu_fwdata {
* struct npc_kpu_profile_cam[entries];
* struct npc_kpu_profile_action[entries];
*/
- u8 data[];
+ u8 data[0];
} __packed;
struct npc_lt_def {
@@ -639,7 +639,7 @@ struct npc_kpu_profile_fwdata {
* Custom KPU CAM and ACTION configuration entries.
* struct npc_kpu_fwdata kpu[kpus];
*/
- u8 data[];
+ u8 data[0];
} __packed;
struct rvu_npc_mcam_rule {
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c
index 58e62e955554..6ccaa9de998c 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c
@@ -517,6 +517,7 @@ static int ptp_pps_on(struct ptp *ptp, int on, u64 period)
static int ptp_probe(struct pci_dev *pdev,
const struct pci_device_id *ent)
{
+ void __iomem * const *base;
struct ptp *ptp;
int err;
@@ -536,7 +537,15 @@ static int ptp_probe(struct pci_dev *pdev,
if (err)
goto error_free;
- ptp->reg_base = pcim_iomap_table(pdev)[PCI_PTP_BAR_NO];
+ base = pcim_iomap_table(pdev);
+ if (!base)
+ goto error_free;
+
+ ptp->reg_base = base[PCI_PTP_BAR_NO];
+ if (!ptp->reg_base) {
+ err = -ENODEV;
+ goto error_free;
+ }
pci_set_drvdata(pdev, ptp);
if (!first_ptp_block)
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
index 4ff3935ed3fe..3b1f1dbfc27e 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
@@ -507,7 +507,7 @@ int rvu_cgx_tx_enable(struct rvu *rvu, u16 pcifunc, bool enable)
void *cgxd;
if (!is_cgx_config_permitted(rvu, pcifunc))
- return LMAC_AF_ERR_PERM_DENIED;
+ return 0;
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
cgxd = rvu_cgx_pdata(cgx_id, rvu);
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cpt.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cpt.c
index f404117bf6c8..fbe41537ea9a 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cpt.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cpt.c
@@ -83,8 +83,8 @@ static irqreturn_t cpt_af_flt_intr_handler(int vec, void *ptr)
struct rvu_block *block = ptr;
struct rvu *rvu = block->rvu;
int blkaddr = block->addr;
+ int i, eng = 0;
u64 reg, val;
- int i, eng;
u8 grp;
reg = rvu_read64(rvu, blkaddr, CPT_AF_FLTX_INT(vec));
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
index 3456313d3b3c..230794abbb4f 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
@@ -496,13 +496,17 @@ RVU_DEBUG_SEQ_FOPS(mcs_rx_secy_stats, mcs_rx_secy_stats_display, NULL);
static void rvu_dbg_mcs_init(struct rvu *rvu)
{
+ char *dname = NULL;
struct mcs *mcs;
- char dname[10];
int i;
if (!rvu->mcs_blk_cnt)
return;
+ dname = kmalloc_array(rvu->mcs_blk_cnt, sizeof(char), GFP_KERNEL);
+ if (!dname)
+ return;
+
rvu->rvu_dbg.mcs_root = debugfs_create_dir("mcs", rvu->rvu_dbg.root);
for (i = 0; i < rvu->mcs_blk_cnt; i++) {
@@ -546,6 +550,8 @@ static void rvu_dbg_mcs_init(struct rvu *rvu)
debugfs_create_file("port", 0600, rvu->rvu_dbg.mcs_tx, mcs,
&rvu_dbg_mcs_tx_port_stats_fops);
}
+
+ kfree(dname);
}
#define LMT_MAPTBL_ENTRY_SIZE 16
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
index 6a0ce2665031..c1333c4d45ec 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
@@ -5540,7 +5540,7 @@ static void nix_inline_ipsec_cfg(struct rvu *rvu, struct nix_inline_ipsec_cfg *r
int blkaddr)
{
u8 cpt_idx, cpt_blkaddr;
- u64 val;
+ u64 val = 0;
cpt_idx = (blkaddr == BLKADDR_NIX0) ? 0 : 1;
if (req->enable) {
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
index c7bc0b3a29b9..6b3ad91bb903 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
@@ -2210,8 +2210,8 @@ static int npc_load_kpu_profile_from_fw(struct rvu *rvu)
rvu->kpu_prfl_addr = NULL;
} else {
kfree(rvu->kpu_fwdata);
+ rvu->kpu_fwdata = NULL;
}
- rvu->kpu_fwdata = NULL;
rvu->kpu_fwdata_sz = 0;
}
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c
index 5dd0591fed99..99d78fc5a2c4 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c
@@ -272,6 +272,7 @@ int otx2_alloc_mcam_entries(struct otx2_nic *pfvf, u16 count)
if (allocated) {
pfvf->flags |= OTX2_FLAG_MCAM_ENTRIES_ALLOC;
pfvf->flags |= OTX2_FLAG_NTUPLE_SUPPORT;
+ pfvf->flags |= OTX2_FLAG_TC_FLOWER_SUPPORT;
}
if (allocated != count)
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
index 2e33b33ec993..33577a90fc1e 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
@@ -489,6 +489,9 @@ static void otx2_pfvf_mbox_handler(struct work_struct *work)
return;
inval_msg:
+ if (!msg)
+ return;
+
otx2_reply_invalid_msg(mbox, vf_idx, 0, msg->id);
otx2_mbox_msg_send(mbox, vf_idx);
}
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/qos.c b/drivers/net/ethernet/marvell/octeontx2/nic/qos.c
index 69c0911e28e9..02e593017556 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/qos.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/qos.c
@@ -533,6 +533,7 @@ otx2_qos_sw_create_leaf_node(struct otx2_nic *pfvf,
err = otx2_qos_add_child_node(parent, node);
if (err) {
mutex_unlock(&pfvf->qos.qos_lock);
+ kfree(node);
return ERR_PTR(err);
}
mutex_unlock(&pfvf->qos.qos_lock);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] octeontx2: Fix Klocwork issues in AF and PF drivers
2026-07-14 2:02 [PATCH net] octeontx2: Fix Klocwork issues in AF and PF drivers Ratheesh Kannoth
@ 2026-07-14 15:50 ` Vadim Fedorenko
0 siblings, 0 replies; 2+ messages in thread
From: Vadim Fedorenko @ 2026-07-14 15:50 UTC (permalink / raw)
To: Ratheesh Kannoth, davem, linux-kernel, naveenm, netdev, sgoutham
Cc: andrew+netdev, edumazet, kuba, pabeni, richardcochran,
Suman Ghosh
On 14.07.2026 03:02, Ratheesh Kannoth wrote:
> From: Suman Ghosh <sumang@marvell.com>
>
> Fix null dereference, uninitialized variable, and error-path resource
> leak findings reported by Klocwork across the OcteonTX2 AF and PF code.
>
> Fixes: 818ed8933bd1 ("octeontx2-af: Re-enable MAC TX in otx2_stop processing")
> Cc: Naveen Mamindlapalli <naveenm@marvell.com>
> Signed-off-by: Suman Ghosh <sumang@marvell.com>
> Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
> ---
> drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 12 +++++++++---
> .../net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c | 8 +++++---
> drivers/net/ethernet/marvell/octeontx2/af/npc.h | 6 +++---
> drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 11 ++++++++++-
> drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c | 2 +-
> drivers/net/ethernet/marvell/octeontx2/af/rvu_cpt.c | 2 +-
> .../net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 8 +++++++-
> drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 2 +-
> drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c | 2 +-
> .../net/ethernet/marvell/octeontx2/nic/otx2_flows.c | 1 +
> drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 3 +++
> drivers/net/ethernet/marvell/octeontx2/nic/qos.c | 1 +
> 12 files changed, 43 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
> index 2e94d5105016..70c8ef5f0be0 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
> @@ -491,12 +491,19 @@ int cgx_lmac_addr_max_entries_get(u8 cgx_id, u8 lmac_id)
> u64 cgx_lmac_addr_get(u8 cgx_id, u8 lmac_id)
> {
> struct cgx *cgx_dev = cgx_get_pdata(cgx_id);
> - struct lmac *lmac = lmac_pdata(lmac_id, cgx_dev);
> struct mac_ops *mac_ops;
> + struct lmac *lmac;
> int index;
> u64 cfg;
> int id;
>
> + if (!cgx_dev)
> + return 0;
> +
> + lmac = lmac_pdata(lmac_id, cgx_dev);
> + if (!lmac)
> + return 0;
> +
this 2 checks are added for impossible cases. both values are checked for
existence in a signle caller of cgx_lmac_addr_get(). Please, do not add
defensive code for no reason. I didn't check other changes, but I believe they
are of the same quality coming from yet-anothener-anaylizing tool.
Please, provide stack traces if these checks are really needed.
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-14 15:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14 2:02 [PATCH net] octeontx2: Fix Klocwork issues in AF and PF drivers Ratheesh Kannoth
2026-07-14 15:50 ` Vadim Fedorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox