linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: (nct6775) Fix incorrect parenthesization in nct6775_write_fan_div()
@ 2023-01-02 21:28 Zev Weiss
  2023-01-03 21:20 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Zev Weiss @ 2023-01-02 21:28 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare, linux-hwmon
  Cc: Zev Weiss, Joel Stanley, Denis Pauk, Dmitry Baryshkov,
	linux-kernel, stable

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.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Fixes: 4ef2774511dc ("hwmon: (nct6775) Convert register access to regmap API")
Cc: stable@kernel.org # 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/YiiMfJV3bjUmoUcV@hatter.bewilderbeest.net/
[1] https://lore.kernel.org/linux-hwmon/20220426071848.11619-3-zev@bewilderbeest.net/
[2] https://lore.kernel.org/linux-hwmon/20220427010154.29749-3-zev@bewilderbeest.net/

 drivers/hwmon/nct6775-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/nct6775-core.c b/drivers/hwmon/nct6775-core.c
index da9ec6983e13..c54233f0369b 100644
--- a/drivers/hwmon/nct6775-core.c
+++ b/drivers/hwmon/nct6775-core.c
@@ -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);
 }
 
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwmon: (nct6775) Fix incorrect parenthesization in nct6775_write_fan_div()
  2023-01-02 21:28 [PATCH] hwmon: (nct6775) Fix incorrect parenthesization in nct6775_write_fan_div() Zev Weiss
@ 2023-01-03 21:20 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2023-01-03 21:20 UTC (permalink / raw)
  To: Zev Weiss
  Cc: Jean Delvare, linux-hwmon, Joel Stanley, Denis Pauk,
	Dmitry Baryshkov, linux-kernel, stable

On Mon, Jan 02, 2023 at 01:28:57PM -0800, Zev Weiss wrote:
> 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.
> 
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
> Fixes: 4ef2774511dc ("hwmon: (nct6775) Convert register access to regmap API")
> Cc: stable@kernel.org # v5.19+

Applied.

Thanks,
Guenter

> ---
> 
> 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/YiiMfJV3bjUmoUcV@hatter.bewilderbeest.net/
> [1] https://lore.kernel.org/linux-hwmon/20220426071848.11619-3-zev@bewilderbeest.net/
> [2] https://lore.kernel.org/linux-hwmon/20220427010154.29749-3-zev@bewilderbeest.net/
> 
>  drivers/hwmon/nct6775-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/nct6775-core.c b/drivers/hwmon/nct6775-core.c
> index da9ec6983e13..c54233f0369b 100644
> --- a/drivers/hwmon/nct6775-core.c
> +++ b/drivers/hwmon/nct6775-core.c
> @@ -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);
>  }
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-03 21:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-02 21:28 [PATCH] hwmon: (nct6775) Fix incorrect parenthesization in nct6775_write_fan_div() Zev Weiss
2023-01-03 21:20 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).