* [PATCH v2] platform/x86/intel/tpmi/plr: Fix output in plr_print_bits()
@ 2024-07-15 20:22 Dan Carpenter
2024-07-16 10:05 ` Ilpo Järvinen
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2024-07-15 20:22 UTC (permalink / raw)
To: Tero Kristo
Cc: Hans de Goede, Ilpo Järvinen, Andy Shevchenko,
platform-driver-x86, linux-kernel, kernel-janitors
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>
---
v2: initialize str at the start of each iteration
drivers/platform/x86/intel/intel_plr_tpmi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/intel/intel_plr_tpmi.c b/drivers/platform/x86/intel/intel_plr_tpmi.c
index c1aa52c23d25..69ace6a629bc 100644
--- a/drivers/platform/x86/intel/intel_plr_tpmi.c
+++ b/drivers/platform/x86/intel/intel_plr_tpmi.c
@@ -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];
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] platform/x86/intel/tpmi/plr: Fix output in plr_print_bits()
2024-07-15 20:22 [PATCH v2] platform/x86/intel/tpmi/plr: Fix output in plr_print_bits() Dan Carpenter
@ 2024-07-16 10:05 ` Ilpo Järvinen
0 siblings, 0 replies; 2+ messages in thread
From: Ilpo Järvinen @ 2024-07-16 10:05 UTC (permalink / raw)
To: Dan Carpenter
Cc: Tero Kristo, Hans de Goede, Andy Shevchenko, platform-driver-x86,
LKML, kernel-janitors
On Mon, 15 Jul 2024, Dan Carpenter wrote:
> 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>
> ---
> v2: initialize str at the start of each iteration
Thanks for the update, I've applied this fix now (will go along with the
for-next PR to Linus).
--
i.
>
> drivers/platform/x86/intel/intel_plr_tpmi.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/intel/intel_plr_tpmi.c b/drivers/platform/x86/intel/intel_plr_tpmi.c
> index c1aa52c23d25..69ace6a629bc 100644
> --- a/drivers/platform/x86/intel/intel_plr_tpmi.c
> +++ b/drivers/platform/x86/intel/intel_plr_tpmi.c
> @@ -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];
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-07-16 10:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-15 20:22 [PATCH v2] platform/x86/intel/tpmi/plr: Fix output in plr_print_bits() Dan Carpenter
2024-07-16 10:05 ` Ilpo Järvinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox