octeontx2: Fix Klocwork issues in AF and PF drivers
Subsystems (4)
Ratheesh Kannoth
maintainerPATCH 1/1 octeontx2: Fix Klocwork issues in AF and PF drivers
From: Suman Ghosh <[email protected]>
Fix null dereference, uninitialized variable, and error-path resource leak findings reported by Klocwork across the OcteonTX2 AF and PF code.
--- 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(-)
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +9 -3
@@ -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);
drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c +5 -3
@@ -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++) {
drivers/net/ethernet/marvell/octeontx2/af/npc.h +3 -3
@@ -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 {
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +10 -1
@@ -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)
drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c +1 -1
@@ -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);
drivers/net/ethernet/marvell/octeontx2/af/rvu_cpt.c +1 -1
@@ -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));
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +7 -1
@@ -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
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +1 -1
@@ -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) {
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +1 -1
@@ -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 ; }
drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c +1 -0
@@ -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)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +3 -0
@@ -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); }
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +1 -0
@@ -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);
Signature · 1 line
2.43.0
Quoted 36 lines · Ratheesh Kannoth
From: Suman Ghosh <[email protected]>
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 <[email protected]>Signed-off-by Suman Ghosh <[email protected]>Signed-off-by Ratheesh Kannoth <[email protected]>--- 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(-)drivers/net/ethernet/marvell/octeontx2/af/cgx.c +1
-1@@ -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;
drivers/net/ethernet/marvell/octeontx2/af/cgx.c int cgx_lmac_addr_max_entries_get(u8 cgx_id, u8 lmac_id) · line 506
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +7
-0u64 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.
[...]