Re: [PATCH] iio: dac: mcp47feb02: reject out-of-range raw values

From: Joshua Crofts

Date: Sun Oct 25 2026 - 06:17:33 EST


On Sat, 24 Oct 2026 22:44:23 +0100
David Carlier <devnexen@xxxxxxxxx> wrote:

> mcp47feb02_write_raw() writes the user supplied raw value to the DAC
> register without checking it against the chip resolution. The parts
> are 8, 10 or 12 bit, and the bits above the resolution are not
> implemented, so writing 300 to out_voltage0_raw on an 8-bit part sets
> the output to code 44 instead of failing, and -1 is written as 0xffff.
>
> The out-of-range value is also cached in dac_data, so it is written
> back on resume and stored to EEPROM by store_eeprom.
>
> Return -EINVAL for values outside [0, 2^resolution - 1].
>
> Found by code inspection. Build tested with W=1 (=m and =y) only;
> no hardware was available for runtime testing.

This should go under the ---.

> Fixes: bf394cc80369 ("iio: dac: adding support for Microchip MCP47FEB02")
> Cc: stable@xxxxxxxxxxxxxxx
> Assisted-by: LLM

This tag has been deprecated.

Otherwise LGTM.

Reviewed-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>

--
Kind regards,
Joshua Crofts