public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gui-Dong Han" <hanguidong02@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 3/3] hwmon: (adm1031) Serialize update rate changes
Date: Thu, 16 Apr 2026 12:21:31 +0000	[thread overview]
Message-ID: <20260416122131.A220FC2BCAF@smtp.kernel.org> (raw)
In-Reply-To: <20260416091754.310-3-hanguidong02@gmail.com>

Sashiko AI review found 1 potential issue(s):
- [High] Missing I2C error handling leads to hardware register corruption and state desynchronization.
--

commit ffbce3cc3043a4bfb1c8f7ba4a9010b9c8a23c2c
Author: Gui-Dong Han <hanguidong02@gmail.com>

hwmon: (adm1031) Serialize update rate changes

This commit expands the locked section in update_interval_store() to cover
the hardware register read-modify-write sequence and the software state
update. This ensures the hardware updates and cached state updates occur
together.

> diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
> index 887fba9ea149f..a46db83471f2c 100644
> --- a/drivers/hwmon/adm1031.c
> +++ b/drivers/hwmon/adm1031.c
[ ... ]
> @@ -897,13 +897,14 @@ static ssize_t update_interval_store(struct device *dev,
>  	}
>  	/* if not found, we point to the last entry (lowest update interval) */
>  
> +	mutex_lock(&data->update_lock);
> +
>  	/* set the new update rate while preserving other settings */
>  	reg = adm1031_read_value(client, ADM1031_REG_FAN_FILTER);

Could the truncation of the error code lead to register corruption?

Looking at adm1031_read_value(), it returns a u8:

static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg)
{
        return i2c_smbus_read_byte_data(client, reg);
}

If i2c_smbus_read_byte_data() returns a negative error code like -EIO, it gets
silently truncated to an 8-bit value (like 0xFB). This garbage value is then
masked, modified, and written back to the register.

>  	reg &= ~ADM1031_UPDATE_RATE_MASK;
>  	reg |= i << ADM1031_UPDATE_RATE_SHIFT;
>  	adm1031_write_value(client, ADM1031_REG_FAN_FILTER, reg);

Does ignoring the return value of adm1031_write_value() leave the software
and hardware states desynchronized?

If the I2C write fails, data->update_interval is updated anyway, meaning
the cached software state no longer matches the actual hardware state
despite the expanded lock.

> -	mutex_lock(&data->update_lock);
>  	data->update_interval = update_intervals[i];
>  	mutex_unlock(&data->update_lock);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260416091754.310-1-hanguidong02@gmail.com?part=3

  reply	other threads:[~2026-04-16 12:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16  9:17 [PATCH 1/3] hwmon: (adm1031) Convert macros to functions to avoid TOCTOU Gui-Dong Han
2026-04-16  9:17 ` [PATCH 2/3] hwmon: (adm1031) Hold lock while reading cached data Gui-Dong Han
2026-04-16 11:57   ` sashiko-bot
2026-04-16 13:02     ` Gui-Dong Han
2026-04-16  9:17 ` [PATCH 3/3] hwmon: (adm1031) Serialize update rate changes Gui-Dong Han
2026-04-16 12:21   ` sashiko-bot [this message]
2026-04-16 13:05     ` Gui-Dong Han
2026-04-16 14:05       ` Guenter Roeck
2026-04-16 14:32         ` Gui-Dong Han

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=20260416122131.A220FC2BCAF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hanguidong02@gmail.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox