[PATCH v2] iio: potentiostat: lmp91000: Handle configuration write errors
From: Zhu Jun
Date: Fri Nov 13 2026 - 04:40:12 EST
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.
Fixes: 67e17300dc1d ("iio: potentiostat: add LMP91000 support")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
Changes in v2:
- Use an explicit error path to restore write protection and return the
original configuration error, as suggested by Jonathan Cameron.
- Return the final lock write result directly on the successful path.
drivers/iio/potentiostat/lmp91000.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c
index 00cb3fea97ca..b9a852646cbc 100644
--- a/drivers/iio/potentiostat/lmp91000.c
+++ b/drivers/iio/potentiostat/lmp91000.c
@@ -250,13 +250,25 @@ static int lmp91000_read_config(struct lmp91000_data *data)
return ret;
}
- 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);
- return 0;
+ return ret;
}
static int lmp91000_buffer_cb(const void *val, void *private)
--
2.51.0