Re: [PATCH v3] iio: potentiostat: lmp91000: Handle configuration write errors

From: Andy Shevchenko

Date: Fri Nov 13 2026 - 04:01:44 EST


On Fri, Nov 13, 2026 at 10:25 AM Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> lmp91000_read_config() ignores errors when unlocking and programming
> the TIA and reference registers. Probe can then succeed even though
> the hardware configuration does not match the parameters used to
> interpret measurements.
>
> Check the configuration writes and return the first error. After a
> successful unlock, attempt to restore write protection even if a
> configuration write fails. Return a relock error when both configuration
> writes succeeded.
>
> lmp91000_probe() returns either error before registering the IIO device,
> so the caller does not need to distinguish their source. Preserve the
> configuration error if restoring write protection also fails.

...

> Changes in v3:
> - Declare the loop counter separately from the return code (Andy Shevchenko).

Now this makes no sense as you haven't added any new variable.

> - Explain how probe handles configuration and relock failures.

> - regmap_write(data->regmap, LMP91000_REG_LOCK, 0);
> - regmap_write(data->regmap, LMP91000_REG_TIACN, reg);
> - regmap_write(data->regmap, LMP91000_REG_REFCN,
> - LMP91000_REG_REFCN_EXT_REF | LMP91000_REG_REFCN_50_ZERO);
> + ret = regmap_write(data->regmap, LMP91000_REG_LOCK, 0);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(data->regmap, LMP91000_REG_TIACN, reg);
> + if (ret)
> + goto relock;
> +
> + ret = regmap_write(data->regmap, LMP91000_REG_REFCN,
> + LMP91000_REG_REFCN_EXT_REF | LMP91000_REG_REFCN_50_ZERO);
> + if (ret)
> + goto relock;
> +
> + return regmap_write(data->regmap, LMP91000_REG_LOCK, 1);
> +
> +relock:
> regmap_write(data->regmap, LMP91000_REG_LOCK, 1);

What's the point of duplicating this?
Before label you can easily do

ret = 0;

relock:
...

>
> - return 0;
> + return ret;
> }

--
With Best Regards,
Andy Shevchenko