Skip to contentSkip to conversation

platform/x86: thinkpad_acpi: Fix compiler warning about uninitialized err variable

PATCH In review Hans de Goede 3 participants 6 messages Mar 9, 2022 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 platform/x86: thinkpad_acpi: Fix compiler warning about uninitialized err variable

err is always set because if we get here then dytc_profile_available is always one of DYTC_FUNCMODE_MMC or DYTC_FUNCMODE_PSC, but the compiler cannot now that, so initialize err to 0 to avoid a compiler warning about err being uninitialized.

---
 drivers/platform/x86/thinkpad_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +1 -1
index cb8f52be8253..7016c7fc3440 100644
@@ -10344,7 +10344,7 @@ static int dytc_profile_set(struct platform_profile_handler *pprof,
 static void dytc_profile_refresh(void)
 {
 	enum platform_profile_option profile;
-	int output, err;
+	int output, err = 0;
 	int perfmode;
 
 	mutex_lock(&dytc_mutex);
Signature · 1 line
2.35.1
#1 lore raw

PATCH 2/2 platform/x86: thinkpad_acpi: Don't use test_bit on an integer

test_bit can only be used on longs not on ints, fix this.

---
p.s. Mark, the need for the (void *) case in the code this replaces should have been a hint that something was not right; and I should have spotted that during review...

---
 drivers/platform/x86/thinkpad_acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +2 -2
index 7016c7fc3440..c476a78599d6 100644
@@ -10399,7 +10399,7 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 	if (err)
 		return err;
 
-	if (test_bit(DYTC_FC_MMC, (void *)&output)) { /* MMC MODE */
+	if (output & BIT(DYTC_FC_MMC)) { /* MMC MODE */
 		dytc_profile_available = DYTC_FUNCMODE_MMC;
 
 		/*
@@ -10412,7 +10412,7 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 			if (!err && ((output & DYTC_ERR_MASK) == DYTC_ERR_SUCCESS))
 				dytc_mmc_get_available = true;
 		}
-	} else if (test_bit(DYTC_FC_PSC, (void *)&output)) { /*PSC MODE */
+	} else if (output & BIT(DYTC_FC_PSC)) { /* PSC MODE */
 		dytc_profile_available = DYTC_FUNCMODE_PSC;
 	} else {
 		dbg_printk(TPACPI_DBG_INIT, "No DYTC support available\n");
Signature · 1 line
2.35.1
#2 lore raw

Re: [External] [PATCH 2/2] platform/x86: thinkpad_acpi: Don't use test_bit on an integer

Thanks Hans,

I hadn't realised that was the case - appreciate the fix

Mark

Quoted 34 lines · Hans de Goede

test_bit can only be used on longs not on ints, fix this.

---
p.s. Mark, the need for the (void *) case in the code this replaces should have been a hint that something was not right; and I should have spotted that during review...

---
 drivers/platform/x86/thinkpad_acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +2 -2
index 7016c7fc3440..c476a78599d6 100644
@@ -10399,7 +10399,7 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 	if (err)
 		return err;
 
-	if (test_bit(DYTC_FC_MMC, (void *)&output)) { /* MMC MODE */
+	if (output & BIT(DYTC_FC_MMC)) { /* MMC MODE */
 		dytc_profile_available = DYTC_FUNCMODE_MMC;
 
 		/*
@@ -10412,7 +10412,7 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 			if (!err && ((output & DYTC_ERR_MASK) == DYTC_ERR_SUCCESS))
 				dytc_mmc_get_available = true;
 		}
-	} else if (test_bit(DYTC_FC_PSC, (void *)&output)) { /*PSC MODE */
+	} else if (output & BIT(DYTC_FC_PSC)) { /* PSC MODE */
 		dytc_profile_available = DYTC_FUNCMODE_PSC;
 	} else {
 		dbg_printk(TPACPI_DBG_INIT, "No DYTC support available\n");
#3 lore raw

Re: [External] [PATCH 2/2] platform/x86: thinkpad_acpi: Don't use test_bit on an integer

Quoted 3 lines · Mark Pearson

Thanks Hans,

I hadn't realised that was the case - appreciate the fix

There are three hidden issues with bit operations being used over non-unsigned long types: a) big-endianness (wrong bit order); b) out of boundaries access due to BE or types when sizeof() < sizeof(unsigned long); c) unaligned access.

All of them are potential security holes and/or crashes.

Quoted 6 lines · Hans de Goede
Quoted 5 lines

test_bit can only be used on longs not on ints, fix this.

p.s. Mark, the need for the (void *) case in the code this replaces should have been a hint that something was not right; and I should have spotted that during review...

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Hans de Goede

Thanks Hans,

This was on my todo list but appreciate you doing it so fast :) Change looks good.

Mark

Quoted 24 lines · Hans de Goede

err is always set because if we get here then dytc_profile_available is always one of DYTC_FUNCMODE_MMC or DYTC_FUNCMODE_PSC, but the compiler cannot now that, so initialize err to 0 to avoid a compiler warning about err being uninitialized.

---
 drivers/platform/x86/thinkpad_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +1 -1
index cb8f52be8253..7016c7fc3440 100644
@@ -10344,7 +10344,7 @@ static int dytc_profile_set(struct platform_profile_handler *pprof,
 static void dytc_profile_refresh(void)
 {
 	enum platform_profile_option profile;
-	int output, err;
+	int output, err = 0;
 	int perfmode;
 
 	mutex_lock(&dytc_mutex);
#5 lore raw
In reply to Hans de Goede

Hi,

Quoted 7 lines · Hans de Goede

err is always set because if we get here then dytc_profile_available is always one of DYTC_FUNCMODE_MMC or DYTC_FUNCMODE_PSC, but the compiler cannot now that, so initialize err to 0 to avoid a compiler warning about err being uninitialized.

I've added these 2 patches to my review-hans (soon to be for-next) branch now.

Regards,

Hans

Quoted 17 lines
---
 drivers/platform/x86/thinkpad_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +1 -1
index cb8f52be8253..7016c7fc3440 100644
@@ -10344,7 +10344,7 @@ static int dytc_profile_set(struct platform_profile_handler *pprof,
 static void dytc_profile_refresh(void)
 {
 	enum platform_profile_option profile;
-	int output, err;
+	int output, err = 0;
 	int perfmode;
 
 	mutex_lock(&dytc_mutex);