All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luiz Angelo Daros de Luca" <luizluca@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [hwmon PATCH v3 2/6] hwmon: (adt7470) Fix cache updated before hardware write on I2C error
Date: Mon, 27 Jul 2026 03:50:19 +0000	[thread overview]
Message-ID: <20260727035020.1CF6F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727-adt7470_thermalzone-v3-2-21424d550c3d@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The PWM enable mask logic swaps the bitmasks for channels 2 and 3 (PWM3 and PWM4).
--

--- Patch [2]: [hwmon PATCH v3 2/6] hwmon: (adt7470) Fix cache updated before hardware write on I2C error ---
commit 6776a671fbb0d95bfa3d1f5ca2bae943732d5533
Author: Luiz Angelo Daros de Luca <luizluca@gmail.com>

hwmon: (adt7470) Fix cache updated before hardware write on I2C error

This commit ensures the driver's cached values are only updated after a
successful regmap_write. By checking the return value, the cache accurately
reflects the actual hardware state even if an I2C transaction fails.

> diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
> index 481d51617f4be..62ec68ea0a406 100644
> --- a/drivers/hwmon/adt7470.c
> +++ b/drivers/hwmon/adt7470.c

[ ... ]

> @@ -847,10 +850,11 @@ static int adt7470_pwm_write(struct device *dev, u32 attr, int channel, long val
>  		val--;
>  
>  		mutex_lock(&data->lock);
> -		data->pwm_automatic[channel] = val;
>  		err = regmap_update_bits(data->regmap, ADT7470_REG_PWM_CFG(channel),
>  					 pwm_auto_reg_mask,

[Severity: High]
This is a pre-existing issue, but does this modulo logic for the PWM enable 
mask swap the bitmasks for channels 2 and 3 (PWM3 and PWM4)?

Earlier in adt7470_pwm_write(), the mask is assigned using modulo arithmetic:

    case hwmon_pwm_enable:
        if (channel % 2)
            pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK;
        else
            pwm_auto_reg_mask = ADT7470_PWM1_AUTO_MASK;

This assigns the mask for PWM4 (0x80) to channel 2 (PWM3) and the mask for 
PWM3 (0x40) to channel 3 (PWM4) during sysfs write. As a result, operations 
intended for PWM3 modify the hardware state of PWM4, and vice versa.

The same pattern is used during the periodic sensor state update in 
adt7470_update_sensors():

    if (i % 2)
        mask = ADT7470_PWM2_AUTO_MASK;
    else
        mask = ADT7470_PWM1_AUTO_MASK;

Could this cause fans to fail to enter the commanded automatic or manual mode, 
potentially leading to improper cooling?

>  					 val ? pwm_auto_reg_mask : 0);
> +		if (!err)
> +			data->pwm_automatic[channel] = val;
>  		mutex_unlock(&data->lock);
>  		break;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260727-adt7470_thermalzone-v3-0-21424d550c3d@gmail.com?part=2

  reply	other threads:[~2026-07-27  3:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27  3:34 [hwmon PATCH v3 0/6] hwmon: (adt7470): Multiple fixes Luiz Angelo Daros de Luca
2026-07-27  3:34 ` [hwmon PATCH v3 1/6] hwmon: (adt7470) Fix fans stuck in manual mode on I2C errors Luiz Angelo Daros de Luca
2026-07-27  3:49   ` sashiko-bot
2026-07-27  3:34 ` [hwmon PATCH v3 2/6] hwmon: (adt7470) Fix cache updated before hardware write on I2C error Luiz Angelo Daros de Luca
2026-07-27  3:50   ` sashiko-bot [this message]
2026-07-27  5:03     ` Luiz Angelo Daros de Luca
2026-07-27  3:34 ` [hwmon PATCH v3 3/6] hwmon: (adt7470) Fix busy-loop and I2C flooding in update thread Luiz Angelo Daros de Luca
2026-07-27  3:49   ` sashiko-bot
2026-07-27  3:34 ` [hwmon PATCH v3 4/6] hwmon: (adt7470) Fix swapped PWM3 and PWM4 auto mode masks Luiz Angelo Daros de Luca
2026-07-27  3:46   ` sashiko-bot
2026-07-27  3:34 ` [hwmon PATCH v3 5/6] hwmon: (adt7470) Fix temperature alarm logic in hwmon_temp_read() Luiz Angelo Daros de Luca
2026-07-27  3:44   ` sashiko-bot
2026-07-27  4:29     ` Luiz Angelo Daros de Luca
2026-07-27  3:34 ` [hwmon PATCH v3 6/6] hwmon: (adt7470) Use cached PWM frequency value Luiz Angelo Daros de Luca
2026-07-27  3:45   ` sashiko-bot
2026-07-27  5:10     ` Luiz Angelo Daros de Luca
2026-07-27  3:44 ` [hwmon PATCH v3 0/6] hwmon: (adt7470): Multiple fixes Luiz Angelo Daros de Luca

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260727035020.1CF6F1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=luizluca@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.