Skip to contentSkip to conversation

pipeline: remove unreachable branch

PATCH Applied David Marchand 3 participants 3 messages Nov 3, 2021 – Nov 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pipeline: remove unreachable branch

A previous change blamed it on compiler/ASan, while this is a real (yet minor) issue.

This return -EINVAL is never reached since we test all combinations of fidx and fcin booleans.
All branches end up with a return 0, factorize them.

Fixes 84f5ac9418ea ("pipeline: fix build with ASan")
Fixes f38913b7fb8e ("pipeline: add meter array to SWX")

---

---
 lib/pipeline/rte_swx_pipeline.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
lib/pipeline/rte_swx_pipeline.c +1 -9
index 1afaffefd4..0bdda7e0b3 100644
@@ -4539,8 +4539,6 @@ instr_meter_translate(struct rte_swx_pipeline *p,
 		instr->meter.color_out.struct_id = (uint8_t)color_out_struct_id;
 		instr->meter.color_out.n_bits = fcout->n_bits;
 		instr->meter.color_out.offset = fcout->offset / 8;
-
-		return 0;
 	}
 
 	/* index = HMEFT, length = HMEFT, color_in = I, color_out = MEF. */
@@ -4575,8 +4573,6 @@ instr_meter_translate(struct rte_swx_pipeline *p,
 		instr->meter.color_out.struct_id = (uint8_t)color_out_struct_id;
 		instr->meter.color_out.n_bits = fcout->n_bits;
 		instr->meter.color_out.offset = fcout->offset / 8;
-
-		return 0;
 	}
 
 	/* index = I, length = HMEFT, color_in = MEFT, color_out = MEF. */
@@ -4607,8 +4603,6 @@ instr_meter_translate(struct rte_swx_pipeline *p,
 		instr->meter.color_out.struct_id = (uint8_t)color_out_struct_id;
 		instr->meter.color_out.n_bits = fcout->n_bits;
 		instr->meter.color_out.offset = fcout->offset / 8;
-
-		return 0;
 	}
 
 	/* index = I, length = HMEFT, color_in = I, color_out = MEF. */
@@ -4638,11 +4632,9 @@ instr_meter_translate(struct rte_swx_pipeline *p,
 		instr->meter.color_out.struct_id = (uint8_t)color_out_struct_id;
 		instr->meter.color_out.n_bits = fcout->n_bits;
 		instr->meter.color_out.offset = fcout->offset / 8;
-
-		return 0;
 	}
 
-	return -EINVAL;
+	return 0;
 }
 
 static inline void
Signature · 1 line
2.23.0
Acked-by on v1 1/1
#1 lore raw
Quoted 73 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, November 3, 2021 6:57 AM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Lin, Xueqin <[email protected]>; Peng, ZhihongX <[email protected]>
Subject: [PATCH] pipeline: remove unreachable branch

A previous change blamed it on compiler/ASan, while this is a real (yet minor) issue.

This return -EINVAL is never reached since we test all combinations of fidx and fcin booleans.
All branches end up with a return 0, factorize them.

Fixes 84f5ac9418ea ("pipeline: fix build with ASan")
Fixes f38913b7fb8e ("pipeline: add meter array to SWX")

---

---
 lib/pipeline/rte_swx_pipeline.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
lib/pipeline/rte_swx_pipeline.c +0 -2
index 1afaffefd4..0bdda7e0b3 100644
@@ -4539,8 +4539,6 @@ instr_meter_translate(struct rte_swx_pipeline *p,
 		instr->meter.color_out.struct_id =
 (uint8_t)color_out_struct_id;
 		instr->meter.color_out.n_bits = fcout->n_bits;
 		instr->meter.color_out.offset = fcout->offset / 8;
-
-		return 0;
 	}
 
lib/pipeline/rte_swx_pipeline.c +0 -2
 	/* index = HMEFT, length = HMEFT, color_in = I, color_out = MEF. */
@@ -4575,8 +4573,6 @@ instr_meter_translate(struct rte_swx_pipeline *p,
 		instr->meter.color_out.struct_id =
 (uint8_t)color_out_struct_id;
 		instr->meter.color_out.n_bits = fcout->n_bits;
 		instr->meter.color_out.offset = fcout->offset / 8;
-
-		return 0;
 	}
 
lib/pipeline/rte_swx_pipeline.c +0 -2
 	/* index = I, length = HMEFT, color_in = MEFT, color_out = MEF. */
@@ -4607,8 +4603,6 @@ instr_meter_translate(struct rte_swx_pipeline *p,
 		instr->meter.color_out.struct_id =
 (uint8_t)color_out_struct_id;
 		instr->meter.color_out.n_bits = fcout->n_bits;
 		instr->meter.color_out.offset = fcout->offset / 8;
-
-		return 0;
 	}
 
lib/pipeline/rte_swx_pipeline.c +1 -3
 	/* index = I, length = HMEFT, color_in = I, color_out = MEF. */
@@ -4638,11 +4632,9 @@ instr_meter_translate(struct rte_swx_pipeline *p,
 		instr->meter.color_out.struct_id =
 (uint8_t)color_out_struct_id;
 		instr->meter.color_out.n_bits = fcout->n_bits;
 		instr->meter.color_out.offset = fcout->offset / 8;
-
-		return 0;
 	}
 
-	return -EINVAL;
+	return 0;
 }
 
Quoted 3 lines

static inline void
--
2.23.0

This is a great idea, thanks David!

I think it is a good compromise between keeping Coverity happy and preserving the code structure and readability, so

#2 lore raw
Quoted 7 lines
Quoted 7 lines

A previous change blamed it on compiler/ASan, while this is a real (yet minor) issue.

This return -EINVAL is never reached since we test all combinations of fidx and fcin booleans.
All branches end up with a return 0, factorize them.

Quoted 6 lines
Quoted 4 lines
Fixes 84f5ac9418ea ("pipeline: fix build with ASan")
Fixes f38913b7fb8e ("pipeline: add meter array to SWX")

Applied, thanks