Skip to content

Commit cfa94c5

Browse files
chleroymcgrof
authored andcommitted
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 <[email protected]> Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 35adf9a commit cfa94c5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

kernel/module/internal.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/mutex.h>
1212
#include <linux/rculist.h>
1313
#include <linux/rcupdate.h>
14+
#include <linux/mm.h>
1415

1516
#ifndef ARCH_SHF_SMALL
1617
#define ARCH_SHF_SMALL 0
@@ -30,11 +31,13 @@
3031
* to ensure complete separation of code and data, but
3132
* only when CONFIG_STRICT_MODULE_RWX=y
3233
*/
33-
#ifdef CONFIG_STRICT_MODULE_RWX
34-
# define strict_align(X) PAGE_ALIGN(X)
35-
#else
36-
# define strict_align(X) (X)
37-
#endif
34+
static inline unsigned int strict_align(unsigned int size)
35+
{
36+
if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
37+
return PAGE_ALIGN(size);
38+
else
39+
return size;
40+
}
3841

3942
extern struct mutex module_mutex;
4043
extern struct list_head modules;

0 commit comments

Comments
 (0)