Re: [PATCH v2 6/8] iio: dac: ds4424: fix -128 rejection and refactor raw access

From: Andy Shevchenko

Date: Tue Jan 27 2026 - 05:43:22 EST


On Tue, Jan 27, 2026 at 07:09:37AM +0100, Oleksij Rempel wrote:
> The DS442x DAC uses sign-magnitude encoding, so -128 cannot be represented.
> Previously, passing -128 resulted in a truncated value that programmed 0mA.
>
> Fix this by validating the input against the 7-bit magnitude limit.
> Additionally, refactor the raw access logic to use symmetrical bitwise
> operations, replacing the union structure.

> Fixes: d632a2bd8ffc ("iio: dac: ds4422/ds4424 dac driver")

Usually fixes go first in the series...

...

> +#define DS4424_DAC_MASK GENMASK(6, 0)
> +#define DS4424_DAC_SOURCE BIT(7)

+ bits.h ?

...

> case IIO_CHAN_INFO_RAW:
> - if (val < S8_MIN || val > S8_MAX)
> + abs_val = abs(val);

> +

Redundant blank line.

> + if (abs_val > DS4424_DAC_MASK)
> return -EINVAL;

...

> + /*
> + * Currents exiting the IC (Source) are positive.
> + * Canonicalize 0 to sink; datasheet treats sign as don't-care.
> + */
> + if (val > 0)
> + abs_val |= DS4424_DAC_SOURCE;

Hmm... Maybe 0 should be excluded as invalid?

--
With Best Regards,
Andy Shevchenko