Re: [PATCH] iio: adc: max1363: sign-extend bipolar differential channel reads

Nguyễn Công <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Message-ID <CAJpJ=GvyZLEwbAS_iZ1sU8tR_cu=uSRZPwsWqXSKFhHauy4nmw@mail.gmail.com>
On Mon, Aug 10, 2026 at 1:45 PM Andy Shevchenko
<[email protected]> wrote:
>
> On Mon, Aug 10, 2026 at 9:42 AM Cong Nguyen <[email protected]> wrote:
> >
> > The MAX1363 differential channels are bipolar (scan_type.sign = 's') and
> > the device returns those samples in two's complement. However
> > max1363_read_single_chan() masks the raw value to the ADC resolution and
> > stores it as-is, without sign extension. A negative differential reading
> > is therefore reported to userspace as a large positive value (for a 12-bit
> > part, -1 reads back as 4095).
>
> Try to make it more compact (remove unneeded or duplicative details,
> do not blindly rely on AI).

Done in v2 - trimmed both paragraphs down to the bug, one example, and
the fix.

>
> > These channels expose only IIO_CHAN_INFO_RAW (no offset), so the raw sysfs
> > value is expected to be the signed result. Sign-extend the masked value
> > from the resolution bit for differential channels before returning it.
> > Single-ended channels are unipolar (sign = 'u') and are left unchanged.
>
> Same here.
>
> > Fixes: 168c9d95a940 ("iio:adc:max1363 move from staging.")
>
> This is a wrong reference in case the driver existed before (and that
> is suggested by the commit description).
>
> --
> With Best Regards,
> Andy Shevchenko

Right, the bug predates the move. The driver was added in 2010 by
d1325cf45077 ("Staging: IIO: max1363 ADC driver"), which already reads
differential channels with an unsigned mask, so v2 uses that as the
Fixes: tag.
Thanks for the review.
Cong
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.