[PATCH v5 01/13] iio: dac: ds4424: reject -128 RAW value

Oleksij Rempel posted 13 patches 5 days, 6 hours ago
[PATCH v5 01/13] iio: dac: ds4424: reject -128 RAW value
Posted by Oleksij Rempel 5 days, 6 hours ago
The DS442x DAC uses sign-magnitude encoding, so -128 cannot be represented
in hardware (7-bit magnitude).

Previously, passing -128 resulted in a truncated value that programmed
0mA (magnitude 0) instead of the expected maximum negative current,
effectively failing silently.

Reject -128 to avoid producing the wrong current.

Fixes: d632a2bd8ffc ("iio: dac: ds4422/ds4424 dac driver")
Cc: <stable@vger.kernel.org>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
changes v5:
- no changes
changes v4:
- Restore v1 implementation: Keep this patch as a minimal fix suitable
  for stable backports
- Move the refactoring (bitwise operations and GENMASK usage) to a
  separate follow-up patch.
changes v3:
- (Merged into refactoring patch in v3, now split again)
---
 drivers/iio/dac/ds4424.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c
index a8198ba4f98a..059acca45f64 100644
--- a/drivers/iio/dac/ds4424.c
+++ b/drivers/iio/dac/ds4424.c
@@ -141,7 +141,7 @@ static int ds4424_write_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (val < S8_MIN || val > S8_MAX)
+		if (val <= S8_MIN || val > S8_MAX)
 			return -EINVAL;
 
 		if (val > 0) {
-- 
2.47.3
Re: [PATCH v5 01/13] iio: dac: ds4424: reject -128 RAW value
Posted by Andy Shevchenko 5 days, 6 hours ago
On Wed, Feb 04, 2026 at 03:00:33PM +0100, Oleksij Rempel wrote:
> The DS442x DAC uses sign-magnitude encoding, so -128 cannot be represented
> in hardware (7-bit magnitude).
> 
> Previously, passing -128 resulted in a truncated value that programmed
> 0mA (magnitude 0) instead of the expected maximum negative current,
> effectively failing silently.
> 
> Reject -128 to avoid producing the wrong current.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

(as agreed to use S8_* limits for now)

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v5 01/13] iio: dac: ds4424: reject -128 RAW value
Posted by Jonathan Cameron 4 days ago
On Wed, 4 Feb 2026 16:13:59 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Wed, Feb 04, 2026 at 03:00:33PM +0100, Oleksij Rempel wrote:
> > The DS442x DAC uses sign-magnitude encoding, so -128 cannot be represented
> > in hardware (7-bit magnitude).
> > 
> > Previously, passing -128 resulted in a truncated value that programmed
> > 0mA (magnitude 0) instead of the expected maximum negative current,
> > effectively failing silently.
> > 
> > Reject -128 to avoid producing the wrong current.  
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
> (as agreed to use S8_* limits for now)
> 
Applied to the fixes-togreg branch of iio.git.

Note that has a weird base at the moment. I'll probably rebase
and do a pull request very early in next cycle.  

We might have to wait a little while to pick up the rest of the
series as a result.

Thanks,

Jonathan