linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] module: Fix selfAssignment cppcheck warning
@ 2022-06-12 10:46 Alexey Dobriyan
  2022-06-12 15:21 ` Christophe Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2022-06-12 10:46 UTC (permalink / raw)
  To: christophe.leroy; +Cc: linux-kernel, linux-modules

> @@ -33,7 +33,8 @@
> #ifdef CONFIG_STRICT_MODULE_RWX
> # define strict_align(X) PAGE_ALIGN(X)
> #else
> -# define strict_align(X) (X)
> +/* OR with zero to avoid cppcheck selfAssignment warning */
> +# define strict_align(X) ((X) | 0)
>  #endif

Can these myopic tools be taught to see around and notice second
definition which does mutate variable so there is no self-assignment?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] module: Fix selfAssignment cppcheck warning
  2022-06-12 10:46 [PATCH] module: Fix selfAssignment cppcheck warning Alexey Dobriyan
@ 2022-06-12 15:21 ` Christophe Leroy
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2022-06-12 15:21 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel, linux-modules



Le 12/06/2022 à 12:46, Alexey Dobriyan a écrit :
>> @@ -33,7 +33,8 @@
>> #ifdef CONFIG_STRICT_MODULE_RWX
>> # define strict_align(X) PAGE_ALIGN(X)
>> #else
>> -# define strict_align(X) (X)
>> +/* OR with zero to avoid cppcheck selfAssignment warning */
>> +# define strict_align(X) ((X) | 0)
>>   #endif
> 
> Can these myopic tools be taught to see around and notice second
> definition which does mutate variable so there is no self-assignment?

I guess not.

However, usually we use static inlines to avoid that. I'll send v2, will 
be cleaner.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] module: Fix selfAssignment cppcheck warning
@ 2022-06-12 10:17 Christophe Leroy
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2022-06-12 10:17 UTC (permalink / raw)
  To: Luis Chamberlain, linux-modules
  Cc: Christophe Leroy, linux-kernel, kernel test robot

cppcheck reports the following warnings:

kernel/module/main.c:1455:26: warning: Redundant assignment of 'mod->core_layout.size' to itself. [selfAssignment]
   mod->core_layout.size = strict_align(mod->core_layout.size);
                         ^
kernel/module/main.c:1489:26: warning: Redundant assignment of 'mod->init_layout.size' to itself. [selfAssignment]
   mod->init_layout.size = strict_align(mod->init_layout.size);
                         ^
kernel/module/main.c:1493:26: warning: Redundant assignment of 'mod->init_layout.size' to itself. [selfAssignment]
   mod->init_layout.size = strict_align(mod->init_layout.size);
                         ^
kernel/module/main.c:1504:26: warning: Redundant assignment of 'mod->init_layout.size' to itself. [selfAssignment]
   mod->init_layout.size = strict_align(mod->init_layout.size);
                         ^
kernel/module/main.c:1459:26: warning: Redundant assignment of 'mod->data_layout.size' to itself. [selfAssignment]
   mod->data_layout.size = strict_align(mod->data_layout.size);
                         ^
kernel/module/main.c:1463:26: warning: Redundant assignment of 'mod->data_layout.size' to itself. [selfAssignment]
   mod->data_layout.size = strict_align(mod->data_layout.size);
                         ^
kernel/module/main.c:1467:26: warning: Redundant assignment of 'mod->data_layout.size' to itself. [selfAssignment]
   mod->data_layout.size = strict_align(mod->data_layout.size);
                         ^

This is due to strict_align() being a no-op when
CONFIG_STRICT_MODULE_RWX is not selected.

Change strict_align() to a bitwise OR with 0 in order to feint cppcheck.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 kernel/module/internal.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/module/internal.h b/kernel/module/internal.h
index bc5507ab8450..8396d5f5daa0 100644
--- a/kernel/module/internal.h
+++ b/kernel/module/internal.h
@@ -33,7 +33,8 @@
 #ifdef CONFIG_STRICT_MODULE_RWX
 # define strict_align(X) PAGE_ALIGN(X)
 #else
-# define strict_align(X) (X)
+/* OR with zero to avoid cppcheck selfAssignment warning */
+# define strict_align(X) ((X) | 0)
 #endif
 
 extern struct mutex module_mutex;
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-12 15:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-12 10:46 [PATCH] module: Fix selfAssignment cppcheck warning Alexey Dobriyan
2022-06-12 15:21 ` Christophe Leroy
  -- strict thread matches above, loose matches on Subject: below --
2022-06-12 10:17 Christophe Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).