Re: [PATCH v1 4/8] iio: dac: ds4424: reject -128 RAW value

From: Andy Shevchenko

Date: Mon Jan 19 2026 - 14:03:52 EST


On Mon, Jan 19, 2026 at 07:24:20PM +0100, Oleksij Rempel wrote:
> The DS442x DAC uses sign-magnitude encoding, so -128 cannot be
> represented in hardware.
>
> With the previous check, userspace could pass -128, which gets converted
> to a magnitude of 128 and then truncated by the 7-bit DAC field. This
> ends up programming a zero magnitude with the sign bit set, i.e. an
> unintended output (effectively 0 mA instead of -128 steps).
>
> Reject -128 to avoid silently producing the wrong current.

...

> - if (val < S8_MIN || val > S8_MAX)
> + if (val <= S8_MIN || val > S8_MAX)
> return -EINVAL;

Hmm... So the range is [ -127 .. 0 .. 127 ] ?

I think in such case the plain numbers would be more specific than
the type related limits.

--
With Best Regards,
Andy Shevchenko