Re: [PATCH v4 2/3] iio: dac: mcp4821: move state initialization outside switch

David Lechner
2026-04-13T14:33:47Z

On 4/13/26 4:44 AM, Nikhil Gautam wrote:
> Move the iio_priv() call outside the switch statement in
> mcp4821_read_raw() to avoid repeating it in multiple cases.
>
> This is a cleanup change with no functional impact.

It isn't a cleanup, it is preparing for the next patch.

>
> Signed-off-by: Nikhil Gautam <nikhilgtr@gmail.com>
> ---
> drivers/iio/dac/mcp4821.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/dac/mcp4821.c b/drivers/iio/dac/mcp4821.c
> index 29187f2a9d3c..6b732db1cf49 100644
> --- a/drivers/iio/dac/mcp4821.c
> +++ b/drivers/iio/dac/mcp4821.c
> @@ -116,10 +116,10 @@ static int mcp4821_read_raw(struct iio_dev *indio_dev,
> int *val2, long mask)
> {
> struct mcp4821_state *state;
> + state = iio_priv(indio_dev);

This should just be one line.

struct mcp4821_state *state = iio_priv(indio_dev);

>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - state = iio_priv(indio_dev);
> *val = state->dac_value[chan->channel];
> return IIO_VAL_INT;