Linux-Hwmon Archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Lars Petter Mostad <larspm@gmail.com>
Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org,
	Lars Petter Mostad <lars.petter.mostad@appear.net>
Subject: Re: [PATCH] hwmon: (emc1403) Decode fractional temperatures.
Date: Tue, 30 Apr 2024 08:37:20 -0700	[thread overview]
Message-ID: <372d0822-2aff-4663-998a-31cd1db4ab4b@roeck-us.net> (raw)
In-Reply-To: <CAC-Dm243rwTcRS2_p989yUoFUjDoR4p9NGE-8WwwmaA6=Ko+4w@mail.gmail.com>

On 4/30/24 04:11, Lars Petter Mostad wrote:
> On Sun, Apr 28, 2024 at 8:07 PM Guenter Roeck <linux@roeck-us.net> wrote:
>>
>> On Sun, Apr 28, 2024 at 11:00:47AM -0700, Guenter Roeck wrote:
>>> On Fri, Apr 26, 2024 at 04:13:22PM +0200, Lars Petter Mostad wrote:
>>>> Decode all diode data low byte registers.
>>>>
>>> All ?
> 
>>> What about the following ?
>>>
>>> 2c -> 2e
>>> 2d -> 2f
>>
>> Also all other limit registers, and for those the write part is missing.
> 
> Yes, my intention was only to decode the (already non-zero) data registers,
> not the limit registers.
> 

We should really do all or nothing.

>>>> -   unsigned int val;
>>>> +   unsigned int val, val_lowbyte;
>>>
>>> FWIW, this is wrong. The upper bit of the high byte is a sign bit
>>> on emc1438.
> 
> Yes, I missed the sign bit in the datasheets. See my comment on patch for
> emc1438. If I withdraw the EMC1438 patch, this will work for the current
> chips with unsigned registers.
> 

Adding support for the new chip is desirable. Please don't drop it.

>>>        retval = regmap_read(data->regmap, sda->index, &val);
>>>        if (retval < 0)
>>>                return retval;
>>> -     return sprintf(buf, "%d000\n", val);
>>> +
>>> +     if (idx_lowbyte) {
>>> +             retval = regmap_read(data->regmap, idx_lowbyte, &val_lowbyte);
>>> +             if (retval < 0)
>>> +                     val_lowbyte = 0;
>>
>> This is an error and should be handled, not ignored.
> 
> My idea here was that if for some reason it manages to read the high byte but
> not the low byte, I don't break anything. The output will be the same as before
> the patch.
> 

No, you should handle the error.

>>> +     return sprintf(buf, "%d\n",
>>> +                    (((val << 8) | val_lowbyte) * (u32)1000) >> 8);
>>
>> The u32 typecast is unnecessary and would interfer with negative temperatures.
> 
> I put the u32 typecast there on the off chance that somebody will compile
> this with a compiler with 16-bit ints (uClinux?), as C only guarantees 16 bits
> for unsigned int. It would of course have to change if negative values are
> to be supported.

I don't even know if such a system exists, but if it does it won't build a Linux
kernel. It doesn't make sense to even try to support a system with 16-bit integers.

> 
> Is it acceptable to handle the low byte for data registers only?
> 
No, as mentioned above.

> Should it be kept unsigned only (if dropping emc1438 patch)?
> 

You should not drop the emc1438 patch. What I would suggest, though,
is to consider converting the driver to use the _with_info registration
API. That would simplify the code a lot and make it much easier to add
support for new chips and to add conditional support for signed temperatures.

Thanks,
Guenter


      reply	other threads:[~2024-04-30 15:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26 14:13 [PATCH] hwmon: (emc1403) Decode fractional temperatures Lars Petter Mostad
2024-04-28 18:00 ` Guenter Roeck
2024-04-28 18:07   ` Guenter Roeck
2024-04-30 11:11     ` Lars Petter Mostad
2024-04-30 15:37       ` Guenter Roeck [this message]

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=372d0822-2aff-4663-998a-31cd1db4ab4b@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=jdelvare@suse.com \
    --cc=lars.petter.mostad@appear.net \
    --cc=larspm@gmail.com \
    --cc=linux-hwmon@vger.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).