Message ID | 20221220085100.22848-9-luca.fancellu@arm.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | cppcheck rule 20.7 fixes | expand |
On 20.12.2022 09:50, Luca Fancellu wrote: > --- a/xen/include/xen/init.h > +++ b/xen/include/xen/init.h > @@ -15,6 +15,7 @@ > #define __initconstrel __section(".init.rodata.rel") > #define __exitdata __used_section(".exit.data") > #define __initsetup __used_section(".init.setup") > +/* SAF-1-false-positive-cppcheck R20.7 argument as text substitution */ > #define __init_call(lvl) __used_section(".initcall" lvl ".init") Would cppcheck also complain about #define __init_call(lvl) __used_section(".initcall" #lvl ".init") ? If not, removing the double quotes at the two invocation sites to balance the addition of # here might be the better route here. Jan
diff --git a/xen/include/xen/init.h b/xen/include/xen/init.h index 0af0e234ec80..7c072b7c8cf8 100644 --- a/xen/include/xen/init.h +++ b/xen/include/xen/init.h @@ -15,6 +15,7 @@ #define __initconstrel __section(".init.rodata.rel") #define __exitdata __used_section(".exit.data") #define __initsetup __used_section(".init.setup") +/* SAF-1-false-positive-cppcheck R20.7 argument as text substitution */ #define __init_call(lvl) __used_section(".initcall" lvl ".init") #define __exit_call __used_section(".exitcall.exit") @@ -65,11 +66,11 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); #define presmp_initcall(fn) \ - const static initcall_t __initcall_##fn __init_call("presmp") = fn + const static initcall_t __initcall_##fn __init_call("presmp") = (fn) #define __initcall(fn) \ - const static initcall_t __initcall_##fn __init_call("1") = fn + const static initcall_t __initcall_##fn __init_call("1") = (fn) #define __exitcall(fn) \ - static exitcall_t __exitcall_##fn __exit_call = fn + static exitcall_t __exitcall_##fn __exit_call = (fn) void do_presmp_initcalls(void); void do_initcalls(void);
Cppcheck has found violations of rule 20.7 for the macros __init_call, presmp_initcall, __initcall and __exitcall. For the first one, the macro parameter is never used as an expression, it is used for text substitution but cppcheck is not taking into account the context of use of the argument, so we can suppress the finding. For the other findings, the argument is not used as an expression, but adding parenthesis doesn't harm the code or the readability, hence add parenthesis on the argument. Eclair and coverity does not report these findings. Signed-off-by: Luca Fancellu <luca.fancellu@arm.com> --- xen/include/xen/init.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)