Skip to contentSkip to conversation

common/cnxk: fix E-tag pattern parsing

PATCH New [email protected] 1 participant 1 message May 22, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/cnxk: fix E-tag pattern parsing

From: Satheesh Paul <[email protected]>

E-tag pattern parsing was using wrong length leading to a segfault. Fixing this by using the correct length of the pattern item.

Fixes c34ea71b878d ("common/cnxk: add NPC parsing API")
---
 drivers/common/cnxk/roc_npc.c       | 5 +++--
 drivers/common/cnxk/roc_npc_parse.c | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/common/cnxk/roc_npc.c +3 -2
index 3fd59667d8..3fa3ddcbfc 100644
@@ -995,10 +995,11 @@ npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
 	pst->mcam_data = (uint8_t *)flow->mcam_data;
 	pst->mcam_mask = (uint8_t *)flow->mcam_mask;
 
-	while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
-	       layer < PLT_DIM(parse_stage_funcs)) {
+	while (pattern->type != ROC_NPC_ITEM_TYPE_END && layer < PLT_DIM(parse_stage_funcs)) {
 		/* Skip place-holders */
 		pattern = npc_parse_skip_void_and_any_items(pattern);
+		if (pattern->type == ROC_NPC_ITEM_TYPE_END)
+			break;
 
 		pst->pattern = pattern;
 		rc = parse_stage_funcs[layer](pst);
drivers/common/cnxk/roc_npc_parse.c +1 -1
index b52024f434..37b43995db 100644
@@ -531,6 +531,7 @@ npc_parse_lb(struct npc_parse_state *pst)
 		 */
 		lt = NPC_LT_LB_ETAG;
 		lflags = 0;
+		info.len = pattern->size;
 
 		last_pattern = pst->pattern;
 		pattern = npc_parse_skip_void_and_any_items(pst->pattern + 1);
@@ -545,7 +546,6 @@ npc_parse_lb(struct npc_parse_state *pst)
 			lflags = NPC_F_ETAG_CTAG;
 			last_pattern = pattern;
 		}
-		info.len = pattern->size;
 	} else if (pst->pattern->type == ROC_NPC_ITEM_TYPE_QINQ) {
 		info.hw_mask = NULL;
 		info.len = pattern->size;
Signature · 1 line
2.42.0