Skip to contentSkip to conversation

hwmon: (nct6775) Fix incorrect parenthesization in nct6775_write_fan_div()

PATCH Applied Zev Weiss 2 participants 2 messages Jan 2, 2023 – Jan 3, 2023 Hardware monitoring

lore
Share & tools
lore

Zev Weiss

author
#0 lore raw

PATCH 1/1 hwmon: (nct6775) Fix incorrect parenthesization in nct6775_write_fan_div()

Commit 4ef2774511dc ("hwmon: (nct6775) Convert register access to regmap API") fumbled the shifting & masking of the fan_div values such that odd-numbered fan divisors would always be set to zero. Fix it so that we actually OR in the bits we meant to.

Fixes 4ef2774511dc ("hwmon: (nct6775) Convert register access to regmap API")
Cc [email protected] # v5.19+

---

This bug got noticed during review [0] and the fix was incorporated into v3 of the patch series [1], but then I somehow managed to accidentally revert the fix in v4 [2] that actually got applied.

I'm fairly confident this is correct, but I don't have any nct6775 hardware to test on (this code path is only used on that specific chip, not others in the family). If any one who does can try it out and report back that would of course be welcome.

[0] https://lore.kernel.org/linux-hwmon/[email protected]/
[1] https://lore.kernel.org/linux-hwmon/[email protected]/
[2] https://lore.kernel.org/linux-hwmon/[email protected]/

 drivers/hwmon/nct6775-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/nct6775-core.c +1 -1
index da9ec6983e13..c54233f0369b 100644
@@ -1150,7 +1150,7 @@ static int nct6775_write_fan_div(struct nct6775_data *data, int nr)
 	if (err)
 		return err;
 	reg &= 0x70 >> oddshift;
-	reg |= data->fan_div[nr] & (0x7 << oddshift);
+	reg |= (data->fan_div[nr] & 0x7) << oddshift;
 	return nct6775_write_value(data, fandiv_reg, reg);
 }
 
Signature · 1 line
2.39.0
maintainer Applied
#1 lore raw
Quoted 8 lines · Zev Weiss

Commit 4ef2774511dc ("hwmon: (nct6775) Convert register access to regmap API") fumbled the shifting & masking of the fan_div values such that odd-numbered fan divisors would always be set to zero. Fix it so that we actually OR in the bits we meant to.

Fixes 4ef2774511dc ("hwmon: (nct6775) Convert register access to regmap API")
Cc [email protected] # v5.19+

Applied.

Thanks,
Guenter

Quoted 31 lines

---

This bug got noticed during review [0] and the fix was incorporated into v3 of the patch series [1], but then I somehow managed to accidentally revert the fix in v4 [2] that actually got applied.

I'm fairly confident this is correct, but I don't have any nct6775 hardware to test on (this code path is only used on that specific chip, not others in the family). If any one who does can try it out and report back that would of course be welcome.

[0] https://lore.kernel.org/linux-hwmon/[email protected]/
[1] https://lore.kernel.org/linux-hwmon/[email protected]/
[2] https://lore.kernel.org/linux-hwmon/[email protected]/

 drivers/hwmon/nct6775-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/nct6775-core.c +1 -1
index da9ec6983e13..c54233f0369b 100644
@@ -1150,7 +1150,7 @@ static int nct6775_write_fan_div(struct nct6775_data *data, int nr)
 	if (err)
 		return err;
 	reg &= 0x70 >> oddshift;
-	reg |= data->fan_div[nr] & (0x7 << oddshift);
+	reg |= (data->fan_div[nr] & 0x7) << oddshift;
 	return nct6775_write_value(data, fandiv_reg, reg);
 }