]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
platform/x86/intel/tpmi/plr: Fix output in plr_print_bits()
authorDan Carpenter <dan.carpenter@linaro.org>
Mon, 15 Jul 2024 20:22:55 +0000 (15:22 -0500)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 16 Jul 2024 08:42:56 +0000 (11:42 +0300)
Smatch complains that 'str' can be used without being initialized:

    drivers/platform/x86/intel/intel_plr_tpmi.c:178 plr_print_bits()
    error: uninitialized symbol 'str'.

In this loop, we iterate over all the set bits and print the name of the
bit.  The intention is that if there is a bit which is between 0-31 we
look for the name in the first array plr_coarse_reasons[] which has 10
elements.  If the bit is in the 32-63 range we look for it in the
plr_fine_reasons[] array which has 30 elements.  If the bit is in the
invalid ranges, 10-31 or 62-63, then we should print "UNKNOWN(%d)".

The problem is that 'str' needs to be initialized at the start of each
iteration, otherwise if we can't find the string then instead of printing
"UNKNOWN(%d)", we will re-print whatever the previous bit was.

Fixes: 9e9397a41b7b ("platform/x86/intel/tpmi/plr: Add support for the plr mailbox")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/b0084e70-4144-445a-9b89-fb19f6b8336a@stanley.mountain
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/intel/intel_plr_tpmi.c

index c1aa52c23d25643e433b3a8c90bb247f03dba5db..69ace6a629bc7959792bd34ba03bb037065b5b24 100644 (file)
@@ -162,10 +162,11 @@ static int plr_clear_cpu_status(struct tpmi_plr_die *plr_die, int cpu)
 static void plr_print_bits(struct seq_file *s, u64 val, int bits)
 {
        const unsigned long mask[] = { BITMAP_FROM_U64(val) };
-       const char *str;
        int bit, index;
 
        for_each_set_bit(bit, mask, bits) {
+               const char *str = NULL;
+
                if (bit < PLR_COARSE_REASON_BITS) {
                        if (bit < ARRAY_SIZE(plr_coarse_reasons))
                                str = plr_coarse_reasons[bit];