Skip to contentSkip to conversation

octeontx2-af: Fix uninitialized variables in MCS alloc handlers

PATCH New Ian Rogers 1 participant 1 message Nov 25

Subsystems (3)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH v2 1/1 octeontx2-af: Fix uninitialized variables in MCS alloc handlers

In rvu_mbox_handler_mcs_alloc_ctrl_pkt_rule(), switch (req->rule_type) has no default case; an unrecognized rule_type in a PF/VF mailbox request leaves 'offset' uninitialized when passed to mcs_alloc_ctrlpktrule(), allocating rules from the wrong hardware partition or failing spuriously.

In rvu_mbox_handler_mcs_alloc_resources(), 'rsrc_id' is left uninitialized when !req->all and either req->rsrc_cnt == 0 or req->rsrc_type is not one of the four handled types, evaluating uninitialized stack memory at 'exit:'.

Return -EINVAL for unrecognized rule_type, unrecognized rsrc_type, and zero rsrc_cnt when !req->all, and zero-initialize rsrc_id so Clang's value-insensitive -Wconditional-uninitialized check sees no uninitialized path across the rsrc_cnt loop.

Discovered via Clang -Wconditional-uninitialized on an x86_64 allyesconfig build with AI coding assistant help. Verified by building drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.o with LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized; not runtime-tested on Marvell CN10K hardware.

Fixes cfc14181d497 ("octeontx2-af: cn10k: mcs: Manage the MCS block hardware resources")

---

Notes:
v2:
- Unlock rvu->rsrc_lock and return -EINVAL directly on unrecognized req->rsrc_type instead of jumping to 'exit:' (which returns 0 over the mailbox), and do the same in rvu_mbox_handler_mcs_alloc_ctrl_pkt_rule() (Sashiko AI review).
- Drop the rsp->flow_ids/secy_ids/sc_ids ARRAY_SIZE() checks since rvu_alloc_rsrc() already bounds IDs to rsrc->max <= 128 and rejecting upfront altered partial-allocation behavior (Sashiko AI review).

v1: https://lore.kernel.org/r/[email protected]

 .../net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c    | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c +10 -1
index cd9cca5a9cf5..92c987134436 100644
@@ -682,12 +682,15 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
 {
 	u16 pcifunc = req->hdr.pcifunc;
 	struct mcs_rsrc_map *map;
+	int rsrc_id = 0, i;
 	struct mcs *mcs;
-	int rsrc_id, i;
 
 	if (req->mcs_id >= rvu->mcs_blk_cnt)
 		return MCS_AF_ERR_INVALID_MCSID;
 
+	if (!req->all && !req->rsrc_cnt)
+		return -EINVAL;
+
 	mcs = mcs_get_pdata(req->mcs_id);
 
 	if (req->dir == MCS_RX)
@@ -744,6 +747,9 @@ int rvu_mbox_handler_mcs_alloc_resources(struct rvu *rvu,
 			rsp->rsrc_cnt++;
 		}
 		break;
+	default:
+		mutex_unlock(&rvu->rsrc_lock);
+		return -EINVAL;
 	}
 
 	rsp->rsrc_type = req->rsrc_type;
@@ -793,6 +799,9 @@ int rvu_mbox_handler_mcs_alloc_ctrl_pkt_rule(struct rvu *rvu,
 	case MCS_CTRL_PKT_RULE_TYPE_MAC:
 		offset = MCS_CTRLPKT_MAC_EN_RULE_OFFSET;
 		break;
+	default:
+		mutex_unlock(&rvu->rsrc_lock);
+		return -EINVAL;
 	}
 
 	rsrc_id = mcs_alloc_ctrlpktrule(&map->ctrlpktrule, map->ctrlpktrule2pf_map, offset,
Signature · 1 line
2.56.1.831.g720f3f5937-goog