• Arnd Bergmann's avatar
    printk: avoid -Wsometimes-uninitialized warning · 5aa7eea9
    Arnd Bergmann authored
    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: 33701557 ("printk: Userspace format indexing support")
    Suggested-by: default avatarSteven Rostedt <rostedt@goodmis.org>
    Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
    Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20210928093456.2438109-1-arnd@kernel.org
    5aa7eea9
index.c 4.3 KB