* [PATCH] hwmon: (it87) Lock the device while reading the temperature sensor type
@ 2026-12-04 18:44 Praneeth Balasubramanian
2026-12-04 18:57 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:44 UTC (permalink / raw)
To: Guenter Roeck, Jean Delvare
Cc: Frank Crawford, linux-hwmon, linux-kernel,
Praneeth Balasubramanian, stable
show_temp_type() calls it87_update_device() and then get_temp_type().
it87_update_device() drops data->update_lock before it returns. Since
commit 6593eac89920 ("hwmon: (it87) Add support to detect sensor type
AMDTSI"), get_temp_type() no longer uses the cached register values but
reads IT87_REG_IFSEL, IT87_REG_TEMP_ENABLE and IT87_REG_TEMP_EXTRA from
the chip. These reads therefore run without update_lock and with SMBus
access enabled, while the comment above it87_read_value() requires both.
it87_read_value() and it87_write_value() go through one address/data
port pair. If a read of tempN_type races with a sysfs store that holds
the lock, for example set_temp_type(), the address write of one side can
land between the address and data accesses of the other. The store can
then write its value to a different register, or the read returns the
wrong register.
Take the lock with it87_lock() around get_temp_type(), as
set_temp_type() does.
The missing lock was found by a static check that turns the locking rule
in a function's comment into a Clang context-analysis requirement on its
callers.
Fixes: 6593eac89920 ("hwmon: (it87) Add support to detect sensor type AMDTSI")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by a compiler-based check, part of research at UCSB SecLab.
The locking rule stated in the kernel-doc comment of the called function
was turned into a Clang context-analysis requirement (__must_hold) on that
function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
caller. An LLM was used only to turn the comment into a machine-readable
rule; the report itself comes from the compiler. The patch and changelog
were drafted with Claude Opus 5.5. I reviewed the patch and take
responsibility for it.
Testing: builds without new warnings with W=1 (x86_64, clang 23,
allmodconfig). Not runtime-tested; I do not have this hardware, and I
have not observed the race myself.
drivers/hwmon/it87.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index c6cdb04add1a..067a92716ea6 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -1398,11 +1398,18 @@ static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
{
struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
struct it87_data *data = it87_update_device(dev);
+ int type, err;
if (IS_ERR(data))
return PTR_ERR(data);
- return sprintf(buf, "%d\n", get_temp_type(data, sensor_attr->index));
+ err = it87_lock(data);
+ if (err)
+ return err;
+ type = get_temp_type(data, sensor_attr->index);
+ it87_unlock(data);
+
+ return sprintf(buf, "%d\n", type);
}
static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (it87) Lock the device while reading the temperature sensor type
2026-12-04 18:44 [PATCH] hwmon: (it87) Lock the device while reading the temperature sensor type Praneeth Balasubramanian
@ 2026-12-04 18:57 ` sashiko-bot
2026-12-04 19:02 ` Guenter Roeck
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-12-04 18:57 UTC (permalink / raw)
To: Praneeth Balasubramanian; +Cc: linux-hwmon
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] hwmon: (it87) redundant it87_update_device() in show_temp_type()
--
commit 1ff8697a4a76a81f49f4fdc1383612abf09626c6
Author: Praneeth Balasubramanian <praneethb2002@gmail.com>
hwmon: (it87) Lock the device while reading the temperature sensor type
This commit acquires it87_lock() around get_temp_type() in show_temp_type()
so direct chip register reads are serialized with other accesses and run
with SMBus disabled.
> diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
> index fa4fcd5f685f9..210927a50cd8f 100644
> --- a/drivers/hwmon/it87.c
> +++ b/drivers/hwmon/it87.c
> @@ -1411,11 +1411,18 @@ static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
> {
> struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> struct it87_data *data = it87_update_device(dev);
> + int type, err;
>
> if (IS_ERR(data))
> return PTR_ERR(data);
>
> - return sprintf(buf, "%d\n", get_temp_type(data, sensor_attr->index));
> + err = it87_lock(data);
> + if (err)
> + return err;
> + type = get_temp_type(data, sensor_attr->index);
> + it87_unlock(data);
> +
> + return sprintf(buf, "%d\n", type);
> }
[Severity: Low]
Does show_temp_type() still need to call it87_update_device()?
get_temp_type() reads the hardware registers directly and does not use
any cached fields from it87_update_device(). Keeping it takes
data->update_lock twice on every read and, when the cache is stale, does
an unused full-chip refresh and an extra smbus_disable()/smbus_enable().
Using dev_get_drvdata(dev) directly, as set_temp_type() does, avoids the
redundant refresh and lock round-trip.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204184447.1685572-1-praneethb2002@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (it87) Lock the device while reading the temperature sensor type
2026-12-04 18:57 ` sashiko-bot
@ 2026-12-04 19:02 ` Guenter Roeck
0 siblings, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-12-04 19:02 UTC (permalink / raw)
To: sashiko-reviews, Praneeth Balasubramanian; +Cc: linux-hwmon
On 12/4/26 10:57, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] hwmon: (it87) redundant it87_update_device() in show_temp_type()
> --
>
> commit 1ff8697a4a76a81f49f4fdc1383612abf09626c6
> Author: Praneeth Balasubramanian <praneethb2002@gmail.com>
>
> hwmon: (it87) Lock the device while reading the temperature sensor type
>
> This commit acquires it87_lock() around get_temp_type() in show_temp_type()
> so direct chip register reads are serialized with other accesses and run
> with SMBus disabled.
>
>> diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
>> index fa4fcd5f685f9..210927a50cd8f 100644
>> --- a/drivers/hwmon/it87.c
>> +++ b/drivers/hwmon/it87.c
>> @@ -1411,11 +1411,18 @@ static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
>> {
>> struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
>> struct it87_data *data = it87_update_device(dev);
>> + int type, err;
>>
>> if (IS_ERR(data))
>> return PTR_ERR(data);
>>
>> - return sprintf(buf, "%d\n", get_temp_type(data, sensor_attr->index));
>> + err = it87_lock(data);
>> + if (err)
>> + return err;
>> + type = get_temp_type(data, sensor_attr->index);
>> + it87_unlock(data);
>> +
>> + return sprintf(buf, "%d\n", type);
>> }
>
> [Severity: Low]
> Does show_temp_type() still need to call it87_update_device()?
>
> get_temp_type() reads the hardware registers directly and does not use
> any cached fields from it87_update_device(). Keeping it takes
> data->update_lock twice on every read and, when the cache is stale, does
> an unused full-chip refresh and an extra smbus_disable()/smbus_enable().
>
> Using dev_get_drvdata(dev) directly, as set_temp_type() does, avoids the
> redundant refresh and lock round-trip.
>
Agreed.
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 19:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:44 [PATCH] hwmon: (it87) Lock the device while reading the temperature sensor type Praneeth Balasubramanian
2026-12-04 18:57 ` sashiko-bot
2026-12-04 19:02 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox