Thread (24 messages) 24 messages, 5 authors, 2026-01-26

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

From: Andy Shevchenko <hidden>
Date: 2026-01-19 19:03:52
Also in: linux-iio, lkml, stable

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

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help