Re: [PATCH v6 2/2] iio: dac: ad5706r: Add support for AD5706R DAC
From: Andy Shevchenko
Date: Fri Apr 10 2026 - 00:41:43 EST
On Fri, Apr 10, 2026 at 09:33:56AM +0800, Alexis Czezar Torreno wrote:
> Add support for the Analog Devices AD5706R, a 4-channel 16-bit
> current output digital-to-analog converter with SPI interface.
>
> Features:
> - 4 independent DAC channels
> - Hardware and software LDAC trigger
> - Configurable output range
> - PWM-based LDAC control
> - Dither and toggle modes
> - Dynamically configurable SPI speed
Still the same issue...
After addressing it in full feel free to add
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
...
> +static int ad5706r_regmap_write(void *context, const void *data, size_t count)
> +{
> + struct ad5706r_state *st = context;
> + unsigned int num_bytes, val;
> + u16 reg;
> + reg = get_unaligned_be16(data);
But this has the similar issue... Validation has to be done before the access.
(also theoretically possible to have count 0, so even for byte access we have
to validate the input, strictly speaking)
> + num_bytes = ad5706r_reg_len(reg);
> +
> + struct spi_transfer xfer = {
> + .tx_buf = st->tx_buf,
> + .len = num_bytes + 2,
> + };
> +
> + if (count != 4)
> + return -EINVAL;
> +
> + val = get_unaligned_be32(data);
> + put_unaligned_be32(val, &st->tx_buf[0]);
> +
> + /* For single byte, copy the data to the correct position */
> + if (num_bytes == AD5706R_SINGLE_BYTE_LEN)
> + st->tx_buf[2] = st->tx_buf[3];
> +
> + return spi_sync_transfer(st->spi, &xfer, 1);
> +}
--
With Best Regards,
Andy Shevchenko