Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

module: Fix selfAssignment cppcheck warning

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.

Transform strict_align() macro into an inline function. It will
allow type checking and avoid the selfAssignment warning.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

authored by

Christophe Leroy and committed by
Luis Chamberlain
cfa94c53 35adf9a4

+8 -5
+8 -5
kernel/module/internal.h
··· 11 11 #include <linux/mutex.h> 12 12 #include <linux/rculist.h> 13 13 #include <linux/rcupdate.h> 14 + #include <linux/mm.h> 14 15 15 16 #ifndef ARCH_SHF_SMALL 16 17 #define ARCH_SHF_SMALL 0 ··· 31 30 * to ensure complete separation of code and data, but 32 31 * only when CONFIG_STRICT_MODULE_RWX=y 33 32 */ 34 - #ifdef CONFIG_STRICT_MODULE_RWX 35 - # define strict_align(X) PAGE_ALIGN(X) 36 - #else 37 - # define strict_align(X) (X) 38 - #endif 33 + static inline unsigned int strict_align(unsigned int size) 34 + { 35 + if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) 36 + return PAGE_ALIGN(size); 37 + else 38 + return size; 39 + } 39 40 40 41 extern struct mutex module_mutex; 41 42 extern struct list_head modules;