* [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms
@ 2024-07-13 21:34 Guenter Roeck
2024-07-13 21:34 ` [PATCH 2/2] hwmon: (max6697) Fix underflow when writing limit attributes Guenter Roeck
2024-07-14 7:06 ` [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms Tzung-Bi Shih
0 siblings, 2 replies; 5+ messages in thread
From: Guenter Roeck @ 2024-07-13 21:34 UTC (permalink / raw)
To: linux-hwmon; +Cc: Guenter Roeck
The critical alarm bit for the local temperature sensor (temp1) is in
bit 7 of register 0x45 (not bit 6), and the critical alarm bit for remote
temperature sensor 7 (temp8) is in bit 6 (not bit 7).
This only affects MAX6581 since all other chips supported by this driver
do not support those critical alarms.
Fixes: 5372d2d71c46 ("hwmon: Driver for Maxim MAX6697 and compatibles")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/max6697.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c
index b28b7b9448aa..1111b2ea55ee 100644
--- a/drivers/hwmon/max6697.c
+++ b/drivers/hwmon/max6697.c
@@ -428,14 +428,14 @@ static SENSOR_DEVICE_ATTR_RO(temp6_max_alarm, alarm, 20);
static SENSOR_DEVICE_ATTR_RO(temp7_max_alarm, alarm, 21);
static SENSOR_DEVICE_ATTR_RO(temp8_max_alarm, alarm, 23);
-static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 14);
+static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 15);
static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, 8);
static SENSOR_DEVICE_ATTR_RO(temp3_crit_alarm, alarm, 9);
static SENSOR_DEVICE_ATTR_RO(temp4_crit_alarm, alarm, 10);
static SENSOR_DEVICE_ATTR_RO(temp5_crit_alarm, alarm, 11);
static SENSOR_DEVICE_ATTR_RO(temp6_crit_alarm, alarm, 12);
static SENSOR_DEVICE_ATTR_RO(temp7_crit_alarm, alarm, 13);
-static SENSOR_DEVICE_ATTR_RO(temp8_crit_alarm, alarm, 15);
+static SENSOR_DEVICE_ATTR_RO(temp8_crit_alarm, alarm, 14);
static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 1);
static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 2);
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] hwmon: (max6697) Fix underflow when writing limit attributes
2024-07-13 21:34 [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms Guenter Roeck
@ 2024-07-13 21:34 ` Guenter Roeck
2024-07-14 7:07 ` Tzung-Bi Shih
2024-07-14 7:06 ` [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms Tzung-Bi Shih
1 sibling, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2024-07-13 21:34 UTC (permalink / raw)
To: linux-hwmon; +Cc: Guenter Roeck
Using DIV_ROUND_CLOSEST() on an unbound value can result in underflows.
Indeed, module test scripts report:
temp1_max: Suspected underflow: [min=0, read 255000, written -9223372036854775808]
temp1_crit: Suspected underflow: [min=0, read 255000, written -9223372036854775808]
Fix by introducing an extra set of clamping.
Fixes: 5372d2d71c46 ("hwmon: Driver for Maxim MAX6697 and compatibles")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/max6697.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c
index 1111b2ea55ee..20981f9443dd 100644
--- a/drivers/hwmon/max6697.c
+++ b/drivers/hwmon/max6697.c
@@ -311,6 +311,7 @@ static ssize_t temp_store(struct device *dev,
return ret;
mutex_lock(&data->update_lock);
+ temp = clamp_val(temp, -1000000, 1000000); /* prevent underflow */
temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset;
temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127);
data->temp[nr][index] = temp;
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms
2024-07-13 21:34 [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms Guenter Roeck
2024-07-13 21:34 ` [PATCH 2/2] hwmon: (max6697) Fix underflow when writing limit attributes Guenter Roeck
@ 2024-07-14 7:06 ` Tzung-Bi Shih
2024-07-14 18:47 ` Guenter Roeck
1 sibling, 1 reply; 5+ messages in thread
From: Tzung-Bi Shih @ 2024-07-14 7:06 UTC (permalink / raw)
To: Guenter Roeck; +Cc: linux-hwmon
On Sat, Jul 13, 2024 at 02:34:01PM -0700, Guenter Roeck wrote:
> The critical alarm bit for the local temperature sensor (temp1) is in
> bit 7 of register 0x45 (not bit 6), and the critical alarm bit for remote
> temperature sensor 7 (temp8) is in bit 6 (not bit 7).
>
> This only affects MAX6581 since all other chips supported by this driver
> do not support those critical alarms.
>
> Fixes: 5372d2d71c46 ("hwmon: Driver for Maxim MAX6697 and compatibles")
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Double checked with the datasheet[1],
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
[1]: https://www.analog.com/media/en/technical-documentation/data-sheets/max6581.pdf
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] hwmon: (max6697) Fix underflow when writing limit attributes
2024-07-13 21:34 ` [PATCH 2/2] hwmon: (max6697) Fix underflow when writing limit attributes Guenter Roeck
@ 2024-07-14 7:07 ` Tzung-Bi Shih
0 siblings, 0 replies; 5+ messages in thread
From: Tzung-Bi Shih @ 2024-07-14 7:07 UTC (permalink / raw)
To: Guenter Roeck; +Cc: linux-hwmon
On Sat, Jul 13, 2024 at 02:34:02PM -0700, Guenter Roeck wrote:
> Using DIV_ROUND_CLOSEST() on an unbound value can result in underflows.
> Indeed, module test scripts report:
>
> temp1_max: Suspected underflow: [min=0, read 255000, written -9223372036854775808]
> temp1_crit: Suspected underflow: [min=0, read 255000, written -9223372036854775808]
>
> Fix by introducing an extra set of clamping.
>
> Fixes: 5372d2d71c46 ("hwmon: Driver for Maxim MAX6697 and compatibles")
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms
2024-07-14 7:06 ` [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms Tzung-Bi Shih
@ 2024-07-14 18:47 ` Guenter Roeck
0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2024-07-14 18:47 UTC (permalink / raw)
To: Tzung-Bi Shih; +Cc: linux-hwmon
On 7/14/24 00:06, Tzung-Bi Shih wrote:
> On Sat, Jul 13, 2024 at 02:34:01PM -0700, Guenter Roeck wrote:
>> The critical alarm bit for the local temperature sensor (temp1) is in
>> bit 7 of register 0x45 (not bit 6), and the critical alarm bit for remote
>> temperature sensor 7 (temp8) is in bit 6 (not bit 7).
>>
>> This only affects MAX6581 since all other chips supported by this driver
>> do not support those critical alarms.
>>
>> Fixes: 5372d2d71c46 ("hwmon: Driver for Maxim MAX6697 and compatibles")
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>
> Double checked with the datasheet[1],
I checked this several times because I couldn't believe that I got it wrong
when I wrote the driver. Thanks a lot for the reviews and for cross-checking !
Guenter
> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
>
> [1]: https://www.analog.com/media/en/technical-documentation/data-sheets/max6581.pdf
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-07-14 18:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-13 21:34 [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms Guenter Roeck
2024-07-13 21:34 ` [PATCH 2/2] hwmon: (max6697) Fix underflow when writing limit attributes Guenter Roeck
2024-07-14 7:07 ` Tzung-Bi Shih
2024-07-14 7:06 ` [PATCH 1/2] hwmon: (max6697) Fix swapped temp{1,8} critical alarms Tzung-Bi Shih
2024-07-14 18:47 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox