Skip to content

Commit 5aa7eea

Browse files
arndbpmladek
authored andcommitted
printk: avoid -Wsometimes-uninitialized warning
clang notices that the pi_get_entry() function would use uninitialized data if it was called with a non-NULL module pointer on a kernel that does not support modules: kernel/printk/index.c:32:6: error: variable 'nr_entries' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] if (!mod) { ^~~~ kernel/printk/index.c:38:13: note: uninitialized use occurs here if (pos >= nr_entries) ^~~~~~~~~~ kernel/printk/index.c:32:2: note: remove the 'if' if its condition is always true if (!mod) { Rework the condition to make it clear to the compiler that we are always in the second case. Unfortunately the #ifdef is still required as the definition of 'struct module' is hidden when modules are disabled. Fixes: 3370155 ("printk: Userspace format indexing support") Suggested-by: Steven Rostedt <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9980c42 commit 5aa7eea

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

kernel/printk/index.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ static struct pi_entry *pi_get_entry(const struct module *mod, loff_t pos)
2626
if (mod) {
2727
entries = mod->printk_index_start;
2828
nr_entries = mod->printk_index_size;
29-
}
29+
} else
3030
#endif
31-
32-
if (!mod) {
31+
{
3332
/* vmlinux, comes from linker symbols */
3433
entries = __start_printk_index;
3534
nr_entries = __stop_printk_index - __start_printk_index;

0 commit comments

Comments
 (0)