mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Packham <Chris.Packham@alliedtelesis.co.nz>
To: Guenter Roeck <linux@roeck-us.net>,
	"jdelvare@suse.com" <jdelvare@suse.com>,
	"robh@kernel.org" <robh@kernel.org>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"corbet@lwn.net" <corbet@lwn.net>,
	"wenliang202407@163.com" <wenliang202407@163.com>,
	"jre@pengutronix.de" <jre@pengutronix.de>
Cc: "linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Subject: Re: [PATCH v3 2/4] hwmon: (ina238) Correctly clamp temperature
Date: Sun, 31 Aug 2025 21:12:14 +0000	[thread overview]
Message-ID: <d5bace8a-003f-4fb5-b9b6-93f0aa7cda41@alliedtelesis.co.nz> (raw)
In-Reply-To: <ba2f563e-4eb3-42be-af05-c01bcef1d5e3@roeck-us.net>


On 29/08/25 21:55, Guenter Roeck wrote:
> On 8/28/25 20:05, Chris Packham wrote:
>> ina238_write_temp() was attempting to clamp the user input but was
>> throwing away the result. Ensure that we clamp the value to the
>> appropriate range before it is converted into a register value.
>>
>> Fixes: 0d9f596b1fe3 ("hwmon: (ina238) Modify the calculation formula 
>> to adapt to different chips")
>> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>> ---
>>
>> Notes:
>>      Changes in v3:
>>      - New. Split off bugfix from main patch
>>
>>   drivers/hwmon/ina238.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c
>> index 5a394eeff676..4d3dc018ead9 100644
>> --- a/drivers/hwmon/ina238.c
>> +++ b/drivers/hwmon/ina238.c
>> @@ -572,7 +572,7 @@ static int ina238_write_temp(struct device *dev, 
>> u32 attr, long val)
>>           return -EOPNOTSUPP;
>>         /* Signed */
>> -    regval = clamp_val(val, -40000, 125000);
>> +    val = clamp_val(val, -40000, 125000);
>
> That needs another correction: As it turns out, the default register 
> value
> is 0x7ff0, or 255875. That means we need to accept that range. The 
> same is
> probably true for negative temperatures, but I'll need to see the real 
> chip
> to be sure.
>
> Yes, the chips only support a limited temperature range, but that is the
> limit register, not the supported range. Other chips have a similar 
> problem.
> It is ok to limit the input range if the chip has a reasonable default 
> set,
> but if the actual chip default is 0x7ff0 or 255.875 degrees C we need to
> support writing that value.
I'm guessing that might change my introduction of temp_max in the next 
patch. I'll re-order my series to put the bugfix first with the changes 
mentioned.
>
> Guenter
>

  reply	other threads:[~2025-08-31 21:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29  3:05 [PATCH v3 0/4] hwmon: Add support for INA780 Chris Packham
2025-08-29  3:05 ` [PATCH v3 1/4] dt-bindings: hwmon: ti,ina2xx: Add INA780 device Chris Packham
2025-08-31 22:35   ` Guenter Roeck
2025-08-29  3:05 ` [PATCH v3 2/4] hwmon: (ina238) Correctly clamp temperature Chris Packham
2025-08-29  9:55   ` Guenter Roeck
2025-08-31 21:12     ` Chris Packham [this message]
2025-08-31 22:09       ` Guenter Roeck
2025-08-31 22:34   ` Guenter Roeck
2025-08-29  3:05 ` [PATCH v3 3/4] hwmon: (ina238) Add ina238_config fields Chris Packham
2025-08-29 15:56   ` Guenter Roeck
2025-08-29  3:05 ` [PATCH v3 4/4] hwmon: (ina238) Add support for INA780 Chris Packham

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=d5bace8a-003f-4fb5-b9b6-93f0aa7cda41@alliedtelesis.co.nz \
    --to=chris.packham@alliedtelesis.co.nz \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=jre@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=robh@kernel.org \
    --cc=wenliang202407@163.com \
    /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

all inboxes | Powered by JetHome®