eal/option: fix option register duplicate detection
PATCH 1/1 eal/option: fix option register duplicate detection
Missing brackets around the if means that the loop will end at its first iteration.
--- lib/librte_eal/common/rte_option.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_eal/common/rte_option.c +2 -1
@@ -35,10 +35,11 @@ void __rte_experimental rte_option_register(struct rte_option *opt) { TAILQ_FOREACH(option, &rte_option_list, next) { -if (strcmp (opt->opt_str, option->opt_str) ==0 ) +if (strcmp (opt->opt_str, option->opt_str) ==0 ) {RTE_LOG (INFO ,EAL ,"Option %s has already been registered." , opt->opt_str);return ; + } }TAILQ_INSERT_HEAD (&rte_option_list, opt, next);
Signature · 1 line
2.19.1
Quoted 19 lines · Gaetan Rivet
Missing brackets around the if means that the loop will end at its first iteration.
Fixes 2395332798d0 ("eal: add option register infrastructure")Signed-off-by Gaetan Rivet <[email protected]>--- lib/librte_eal/common/rte_option.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/librte_eal/common/rte_option.c +0
-0@@ -35,10 +35,11 @@ void __rte_experimental rte_option_register(struct rte_option *opt) {
lib/librte_eal/common/rte_option.c void __rte_experimental · line 45
Quoted 10 lines
lib/librte_eal/common/rte_option.c +2
-1TAILQ_FOREACH(option, &rte_option_list, next) { -if (strcmp (opt->opt_str, option->opt_str) ==0 ) +if (strcmp (opt->opt_str, option->opt_str) ==0 ) {RTE_LOG (INFO ,EAL ,"Option %s has already been registered." , opt->opt_str);return ; + } }TAILQ_INSERT_HEAD (&rte_option_list, opt, next);
This is why i don't like the "no brackets on single-statement if clause" rule in our coding style guide - it makes mistakes like these easier to do. This wouldn't have happened if we mandated to have brackets always, for everything.
Signature · 2 lines
Thanks, Anatoly
PATCH 1/1 mk: use misleading indentation warning when available
-Wmisleading-indentation was introduced in GCC 6.0.
Use it at least when available. This should catch most common error of the types (due to the codebase being properly tabbed), but will still miss patterns such as
if (!condition)
// commented_fn_call();
do_stuff();---
I completely agree that we should change the coding style and force all if()s to have brackets.
In the meantime, this patch might help alleviate the issue.
mk/toolchain/gcc/rte.vars.mk | 4 ++++ 1 file changed, 4 insertions(+)
mk/toolchain/gcc/rte.vars.mk +4 -0
@@ -87,5 +87,9 @@ WERROR_FLAGS += -Wimplicit-fallthrough=2 WERROR_FLAGS += -Wno-format-truncation endif +ifeq ($(shell test $(GCC_VERSION) -gt 60 && echo 1), 1) +WERROR_FLAGS += -Wmisleading-indentation +endif + export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
Signature · 1 line
2.19.1
Re: [PATCH] mk: use misleading indentation warning when available
Quoted 1 line · Gaetan Rivet
-Wmisleading-indentation was introduced in GCC 6.0.
It seems '-Wmisleading-indentation' is part of -Wall, which we already set by default. If so no need to explicitly add it.
The link I found:
https://www.gnu.org/software/gcc/gcc-6/porting_to.html
copy-paste:
"
A new warning -Wmisleading-indentation was added to -Wall, warning about places where the indentation of the code might mislead a human reader about the control flow:
"
Is there a way to confirm it is part of -Wall?
Quoted 35 lines
Use it at least when available. This should catch most common error of the types (due to the codebase being properly tabbed), but will still miss patterns such as
if (!condition) // commented_fn_call(); do_stuff();Signed-off-by Gaetan Rivet <[email protected]>---
I completely agree that we should change the coding style and force all if()s to have brackets.
In the meantime, this patch might help alleviate the issue.
mk/toolchain/gcc/rte.vars.mk | 4 ++++ 1 file changed, 4 insertions(+)mk/toolchain/gcc/rte.vars.mk +4
-0@@ -87,5 +87,9 @@ WERROR_FLAGS += -Wimplicit-fallthrough=2 WERROR_FLAGS += -Wno-format-truncation endif +ifeq ($(shell test $(GCC_VERSION) -gt 60 && echo 1), 1) +WERROR_FLAGS += -Wmisleading-indentation +endif + export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
Re: [PATCH] mk: use misleading indentation warning when available
Quoted 9 lines · Ferruh Yigit
Quoted 1 line · Gaetan Rivet
-Wmisleading-indentation was introduced in GCC 6.0.
It seems '-Wmisleading-indentation' is part of -Wall, which we already set by default. If so no need to explicitly add it.
The link I found:
https://www.gnu.org/software/gcc/gcc-6/porting_to.html
Quoted 9 lines
copy-paste:
"
A new warning -Wmisleading-indentation was added to -Wall, warning about places where the indentation of the code might mislead a human reader about the control flow:
"Is there a way to confirm it is part of -Wall?
I think you are right, actually the check was already used. This is worrying, given that the original bug was not seen.
This patch can be left out then, but the problem remains. Maybe an update to coding style is needed, or an evolution to checkpatch // preferably something else.
Quoted 36 lines
Quoted 35 lines
Use it at least when available. This should catch most common error of the types (due to the codebase being properly tabbed), but will still miss patterns such as
if (!condition) // commented_fn_call(); do_stuff();Signed-off-by Gaetan Rivet <[email protected]>---
I completely agree that we should change the coding style and force all if()s to have brackets.
In the meantime, this patch might help alleviate the issue.
mk/toolchain/gcc/rte.vars.mk | 4 ++++ 1 file changed, 4 insertions(+)mk/toolchain/gcc/rte.vars.mk +4
-0@@ -87,5 +87,9 @@ WERROR_FLAGS += -Wimplicit-fallthrough=2 WERROR_FLAGS += -Wno-format-truncation endif +ifeq ($(shell test $(GCC_VERSION) -gt 60 && echo 1), 1) +WERROR_FLAGS += -Wmisleading-indentation +endif + export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
Signature · 2 lines
Gaëtan Rivet 6WIND
Re: [PATCH] mk: use misleading indentation warning when available
Quoted 20 lines · Gaëtan Rivet
Quoted 9 lines · Ferruh Yigit
Quoted 1 line · Gaetan Rivet
-Wmisleading-indentation was introduced in GCC 6.0.
It seems '-Wmisleading-indentation' is part of -Wall, which we already set by default. If so no need to explicitly add it.
The link I found:
https://www.gnu.org/software/gcc/gcc-6/porting_to.htmlQuoted 9 lines
copy-paste:
"
A new warning -Wmisleading-indentation was added to -Wall, warning about places where the indentation of the code might mislead a human reader about the control flow:
"Is there a way to confirm it is part of -Wall?
Quoted 6 lines
I think you are right, actually the check was already used. This is worrying, given that the original bug was not seen.
This patch can be left out then, but the problem remains. Maybe an update to coding style is needed, or an evolution to checkpatch // preferably something else.
clang-format? It's not exactly a style *checker*, but if we had a .clang-format config file included with DPDK, it would be easy to 1) format the code properly before sending out the patches, and 2) convert the entire DPDK codebase to the new style, should such need arise.
(also, uncrustify and other code beautifiers...)
Signature · 2 lines
Thanks, Anatoly
Quoted 29 lines · Gaetan Rivet
Missing brackets around the if means that the loop will end at its first iteration.
Fixes 2395332798d0 ("eal: add option register infrastructure")Signed-off-by Gaetan Rivet <[email protected]>--- lib/librte_eal/common/rte_option.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/librte_eal/common/rte_option.c +2
-1@@ -35,10 +35,11 @@ void __rte_experimental rte_option_register(struct rte_option *opt) { TAILQ_FOREACH(option, &rte_option_list, next) { -if (strcmp (opt->opt_str, option->opt_str) ==0 ) +if (strcmp (opt->opt_str, option->opt_str) ==0 ) { RTE_LOG(INFO, EAL, "Option %s has already been registered.", opt->opt_str);return ; + } }
Quoted 2 lines
TAILQ_INSERT_HEAD(&rte_option_list, opt, next);
Different topic but having a return code would be better than a simple log.
Signature · 1 line
David Marchand
Thomas Monjalon
Applied17/12/2018 11:19, David Marchand:
Quoted 23 lines
Quoted 15 lines · Gaetan Rivet
Missing brackets around the if means that the loop will end at its first iteration.
Fixes 2395332798d0 ("eal: add option register infrastructure")Signed-off-by Gaetan Rivet <[email protected]>---
rte_option_register(struct rte_option *opt){ TAILQ_FOREACH(option, &rte_option_list, next) {lib/librte_eal/common/rte_option.c +1
-1-if (strcmp (opt->opt_str, option->opt_str) ==0 ) +if (strcmp (opt->opt_str, option->opt_str) ==0 ) { RTE_LOG(INFO, EAL, "Option %s has already beenregistered.",
Quoted 4 lines
opt->opt_str); return; + } }
Quoted 1 line
Reviewed-by David Marchand <[email protected]>
Applied, thanks
Quoted 1 line
Different topic but having a return code would be better than a simple log.
+1