From: Guenter Roeck <linux@roeck-us.net>
To: Tzung-Bi Shih <tzungbi@kernel.org>
Cc: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Subject: Re: [PATCH 4/6] hwmon: (lm95234) Convert to with_info hwmon API
Date: Thu, 18 Jul 2024 10:47:55 -0700 [thread overview]
Message-ID: <89c18e08-3a98-4c33-bca4-ea5acba9f6f2@roeck-us.net> (raw)
In-Reply-To: <ZplFeHMIKjHPiwTc@tzungbi-laptop>
On 7/18/24 09:40, Tzung-Bi Shih wrote:
> On Wed, Jul 17, 2024 at 08:39:33PM -0700, Guenter Roeck wrote:
>> +static int lm95234_temp_write(struct device *dev, u32 attr, int channel, long val)
>> {
> [...]
>> + case hwmon_temp_max:
>> + val = clamp_val(val, 0, channel ? 255000 : 127000);
>
> Perhaps I am misunderstanding, but this looks weird to me. By applying
> the patch, the maximum values are:
>
> static SENSOR_DEVICE_ATTR_RW(temp1_max, tcrit1, 0); -> 127000
> static SENSOR_DEVICE_ATTR_RW(temp2_max, tcrit2, 0); -> 255000
> static SENSOR_DEVICE_ATTR_RW(temp3_max, tcrit2, 1); -> 255000
> static SENSOR_DEVICE_ATTR_RW(temp4_max, tcrit1, 3); -> 255000
> static SENSOR_DEVICE_ATTR_RW(temp5_max, tcrit1, 4); -> 255000
>
>
> However, it was originally:
>
> static ssize_t tcrit1_store(struct device *dev, struct device_attribute *attr,
> const char *buf, size_t count)
> {
> [...]
> val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 255000), 1000);
>
> static ssize_t tcrit2_store(struct device *dev, struct device_attribute *attr,
> const char *buf, size_t count)
> {
> [...]
> val = DIV_ROUND_CLOSEST(clamp_val(val, 0, (index ? 255 : 127) * 1000),
> 1000);
>
> static SENSOR_DEVICE_ATTR_RW(temp1_max, tcrit1, 0); -> 255000
> static SENSOR_DEVICE_ATTR_RW(temp2_max, tcrit2, 0); -> 127000
> static SENSOR_DEVICE_ATTR_RW(temp3_max, tcrit2, 1); -> 255000
> static SENSOR_DEVICE_ATTR_RW(temp4_max, tcrit1, 3); -> 255000
> static SENSOR_DEVICE_ATTR_RW(temp5_max, tcrit1, 4); -> 255000
>
>> + val = DIV_ROUND_CLOSEST(val, 1000);
>> + return regmap_write(regmap, lm95234_crit_reg(channel), val);
>
That is indeed a bug. Here is the fix:
diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c
index c3c68c196479..7da6c8f07332 100644
--- a/drivers/hwmon/lm95234.c
+++ b/drivers/hwmon/lm95234.c
@@ -150,7 +150,7 @@ static int lm95234_temp_write(struct device *dev, u32 attr, int channel, long va
val = DIV_ROUND_CLOSEST(clamp_val(val, -64000, 63500), 500);
return regmap_write(regmap, LM95234_REG_OFFSET(channel - 1), val);
case hwmon_temp_max:
- val = clamp_val(val, 0, channel ? 255000 : 127000);
+ val = clamp_val(val, 0, channel == 1 ? 127000 : 255000);
val = DIV_ROUND_CLOSEST(val, 1000);
return regmap_write(regmap, lm95234_crit_reg(channel), val);
case hwmon_temp_max_hyst:
Thanks a lot for the detailed review!
Guenter
next prev parent reply other threads:[~2024-07-18 17:47 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-18 3:39 [PATCH 0/6] hwmon: (lm9534) Various improvements Guenter Roeck
2024-07-18 3:39 ` [PATCH 1/6] hwmon: (lm95234) Reorder include files to be in alphabetic order Guenter Roeck
2024-07-18 16:39 ` Tzung-Bi Shih
2024-07-18 3:39 ` [PATCH 2/6] hwmon: (lm95234) Use find_closest to find matching update interval Guenter Roeck
2024-07-18 16:39 ` Tzung-Bi Shih
2024-07-18 17:48 ` Guenter Roeck
2024-07-18 17:53 ` Guenter Roeck
2024-07-19 0:52 ` Tzung-Bi Shih
2024-07-18 3:39 ` [PATCH 3/6] hwmon: (lm95234) Convert to use regmap Guenter Roeck
2024-07-18 16:40 ` Tzung-Bi Shih
2024-07-18 3:39 ` [PATCH 4/6] hwmon: (lm95234) Convert to with_info hwmon API Guenter Roeck
2024-07-18 16:40 ` Tzung-Bi Shih
2024-07-18 17:47 ` Guenter Roeck [this message]
2024-07-19 0:52 ` Tzung-Bi Shih
2024-07-19 1:55 ` Guenter Roeck
2024-07-18 3:39 ` [PATCH 5/6] hwmon: (lm95234) Add support for tempX_enable attribute Guenter Roeck
2024-07-18 16:40 ` Tzung-Bi Shih
2024-07-18 3:39 ` [PATCH 6/6] hwmon: (lm95234) Use multi-byte regmap operations Guenter Roeck
2024-07-18 16:40 ` Tzung-Bi Shih
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=89c18e08-3a98-4c33-bca4-ea5acba9f6f2@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-hwmon@vger.kernel.org \
--cc=tzungbi@kernel.org \
/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