pipeline: remove unreachable branch
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.
---
--- lib/pipeline/rte_swx_pipeline.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
lib/pipeline/rte_swx_pipeline.c +1 -9
@@ -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
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 branchA previous change blamed it on compiler/ASan, while this is a real (yet minor) issue.
This return
-EINVALis 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")Signed-off-by David Marchand <[email protected]>---
--- lib/pipeline/rte_swx_pipeline.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)lib/pipeline/rte_swx_pipeline.c +0
-2@@ -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
Thomas Monjalon
AppliedQuoted 7 lines
Quoted 7 lines
A previous change blamed it on compiler/ASan, while this is a real (yet minor) issue.
This return
-EINVALis 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")Signed-off-by David Marchand <[email protected]>
Applied, thanks