summaryrefslogtreecommitdiffstats
path: root/kernel/printk
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2021-09-28 11:34:33 +0200
committerPetr Mladek <pmladek@suse.com>2021-10-04 10:28:43 +0200
commit5aa7eea9316ceb4b57175ce04b39e498105b7e92 (patch)
tree90257d9953e8fc1ef7b609fbaa6fc70bc816bd67 /kernel/printk
parent9980c4251f8ddfcf0617ed5724e4df5bd1f69c85 (diff)
downloadlinux-stable-5aa7eea9316ceb4b57175ce04b39e498105b7e92.tar.gz
linux-stable-5aa7eea9316ceb4b57175ce04b39e498105b7e92.tar.bz2
linux-stable-5aa7eea9316ceb4b57175ce04b39e498105b7e92.zip
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: 337015573718 ("printk: Userspace format indexing support") Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20210928093456.2438109-1-arnd@kernel.org
Diffstat (limited to 'kernel/printk')
-rw-r--r--kernel/printk/index.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/kernel/printk/index.c b/kernel/printk/index.c
index d3709408debe..c85be186a783 100644
--- a/kernel/printk/index.c
+++ b/kernel/printk/index.c
@@ -26,10 +26,9 @@ static struct pi_entry *pi_get_entry(const struct module *mod, loff_t pos)
if (mod) {
entries = mod->printk_index_start;
nr_entries = mod->printk_index_size;
- }
+ } else
#endif
-
- if (!mod) {
+ {
/* vmlinux, comes from linker symbols */
entries = __start_printk_index;
nr_entries = __stop_printk_index - __start_printk_index;