mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] iio: potentiostat: lmp91000: Handle configuration write errors
@ 2026-11-13  8:25 Zhu Jun
  2026-11-13  8:41 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-13  8:25 UTC (permalink / raw)
  To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, zhujun2

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.

Fixes: 67e17300dc1d ("iio: potentiostat: add LMP91000 support")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
Changes in v3:
- Declare the loop counter separately from the return code (Andy Shevchenko).
- Explain how probe handles configuration and relock failures.

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 | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c
index 00cb3fea97ca..1e07917ff76a 100644
--- a/drivers/iio/potentiostat/lmp91000.c
+++ b/drivers/iio/potentiostat/lmp91000.c
@@ -205,7 +205,8 @@ static int lmp91000_read_config(struct lmp91000_data *data)
 {
 	struct device *dev = data->dev;
 	unsigned int reg, val;
-	int i, ret;
+	int ret;
+	int i;
 
 	ret = device_property_read_u32(dev, "ti,tia-gain-ohm", &val);
 	if (ret) {
@@ -250,13 +251,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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-14  1:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13  8:25 [PATCH v3] iio: potentiostat: lmp91000: Handle configuration write errors Zhu Jun
2026-11-13  8:41 ` Andy Shevchenko
2026-11-13  8:47   ` Andy Shevchenko
2026-11-14  1:41     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®