Skip to contentSkip to conversation

hwmon: (nct6775) Fix loop limit

PATCH In review Guenter Roeck 2 participants 3 messages Jun 13, 2018 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/1 hwmon: (nct6775) Fix loop limit

Commit cc66b3038254 ("hwmon: (nct6775) Rework temperature source and label handling") changed a loop limit from "data->temp_label_num - 1" to "32", as part of moving from a string array to a bit mask. This results in the following error, reported by UBSAN.

UBSAN: Undefined behaviour in drivers/hwmon/nct6775.c:4179:27

shift exponent 32 is too large for 32-bit type 'long unsigned int'

Similar to the original loop, the limit has to be one less than the number of bits.

Fixes cc66b3038254 ("hwmon: (nct6775) Rework temperature source and label handling")
Cc Paul Menzel <[email protected]>
---
 drivers/hwmon/nct6775.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/nct6775.c +1 -1
index aebce560bfaf..b14eb73bc3c9 100644
@@ -4175,7 +4175,7 @@ static int nct6775_probe(struct platform_device *pdev)
 	 * The temperature is already monitored if the respective bit in <mask>
 	 * is set.
 	 */
-	for (i = 0; i < 32; i++) {
+	for (i = 0; i < 31; i++) {
 		if (!(data->temp_mask & BIT(i + 1)))
 			continue;
 		if (!reg_temp_alternate[i])
Signature · 1 line
2.7.4
Tested-by on v1 1/1
#1 lore raw

Dear Guenter,

Am 13.06.2018 um 17:10 schrieb Guenter Roeck:

Quoted 24 lines

Commit cc66b3038254 ("hwmon: (nct6775) Rework temperature source and label handling") changed a loop limit from "data->temp_label_num - 1" to "32", as part of moving from a string array to a bit mask. This results in the following error, reported by UBSAN.

UBSAN: Undefined behaviour in drivers/hwmon/nct6775.c:4179:27

shift exponent 32 is too large for 32-bit type 'long unsigned int'

Similar to the original loop, the limit has to be one less than the number of bits.

Fixes cc66b3038254 ("hwmon: (nct6775) Rework temperature source and label handling")
Cc Paul Menzel <[email protected]>
---
  drivers/hwmon/nct6775.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/nct6775.c +0 -0
index aebce560bfaf..b14eb73bc3c9 100644

drivers/hwmon/nct6775.c static int nct6775_probe(struct platform_device *pdev) · line 4181

Quoted 8 lines
drivers/hwmon/nct6775.c +1 -1
@@ -4175,7 +4175,7 @@ static int nct6775_probe(struct platform_device *pdev)
  	 * The temperature is already monitored if the respective bit in <mask>
  	 * is set.
  	 */
-	for (i = 0; i < 32; i++) {
+	for (i = 0; i < 31; i++) {
  		if (!(data->temp_mask & BIT(i + 1)))
  			continue;
  		if (!reg_temp_alternate[i])

Thank you for the patch. I tested that the UBSAN message is gone, and that the module loads.

Kind regards

Paul

author maintainer
#2 lore raw
Quoted 40 lines · Paul Menzel

Dear Guenter,

Am 13.06.2018 um 17:10 schrieb Guenter Roeck:

Quoted 24 lines

Commit cc66b3038254 ("hwmon: (nct6775) Rework temperature source and label handling") changed a loop limit from "data->temp_label_num - 1" to "32", as part of moving from a string array to a bit mask. This results in the following error, reported by UBSAN.

UBSAN: Undefined behaviour in drivers/hwmon/nct6775.c:4179:27

shift exponent 32 is too large for 32-bit type 'long unsigned int'

Similar to the original loop, the limit has to be one less than the number of bits.

Fixes cc66b3038254 ("hwmon: (nct6775) Rework temperature source and label handling")
Cc Paul Menzel <[email protected]>
---
 drivers/hwmon/nct6775.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/nct6775.c +0 -0
index aebce560bfaf..b14eb73bc3c9 100644

drivers/hwmon/nct6775.c static int nct6775_probe(struct platform_device *pdev) · line 4181

Quoted 8 lines
drivers/hwmon/nct6775.c +1 -1
@@ -4175,7 +4175,7 @@ static int nct6775_probe(struct platform_device *pdev)
 	 * The temperature is already monitored if the respective bit in <mask>
 	 * is set.
 	 */
-	for (i = 0; i < 32; i++) {
+	for (i = 0; i < 31; i++) {
 		if (!(data->temp_mask & BIT(i + 1)))
 			continue;
 		if (!reg_temp_alternate[i])

Thank you for the patch. I tested that the UBSAN message is gone, and that the module loads.

Quoted 2 lines

Thanks!

Guenter