Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH] hwmon: (ads7828) Check return value of regmap_read() in probe
@ 2026-08-04  9:17 Qingshuang Fu
  2026-08-04  9:24 ` sashiko-bot
  2026-08-04 13:58 ` Guenter Roeck
  0 siblings, 2 replies; 5+ messages in thread
From: Qingshuang Fu @ 2026-08-04  9:17 UTC (permalink / raw)
  To: Guenter Roeck, Akshay Bhat
  Cc: linux-hwmon, linux-kernel, Qingshuang Fu, Qingshuang Fu

From: Qingshuang Fu <fuqingshuang@kylinos.cn>

ads7828_probe() issues a dummy regmap_read() to enable the internal
reference voltage when ext_vref is false. The original code ignores the
return value of regmap_read().

If the I2C read fails, the internal reference voltage will not be enabled,
and subsequent ADC readings return incorrect values without any error
indication.

Check the return value of regmap_read(), log an error message, and abort
probe on failure. This prevents registering a non-functional hwmon device.

Fixes: 7a18afe80977 ("hwmon: (ads7828) Enable internal reference")
Signed-off-by: Qingshuang Fu <fuqingshuang@kylinos.cn>
---
 drivers/hwmon/ads7828.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index 149cfcec78dc..91ef0c4a08c4 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -112,6 +112,7 @@ static int ads7828_probe(struct i2c_client *client)
 	unsigned int regval;
 	enum ads7828_chips chip;
 	struct regulator *reg;
+	int ret;
 
 	data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
 	if (!data)
@@ -166,8 +167,13 @@ static int ads7828_probe(struct i2c_client *client)
 	 * voltage needs to settle before getting valid ADC data. So perform a
 	 * dummy read to enable the internal reference voltage.
 	 */
-	if (!ext_vref)
-		regmap_read(data->regmap, data->cmd_byte, &regval);
+	if (!ext_vref) {
+		ret = regmap_read(data->regmap, data->cmd_byte, &regval);
+		if (ret) {
+			dev_err(dev, "dummy read failed to enable internal VREF: %d\n", ret);
+			return ret;
+		}
+	}
 
 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
 							   data,

base-commit: 848acc8ffe1b7cd5f1bf427b93069becfebc2c9d
-- 
2.25.1


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

end of thread, other threads:[~2026-08-04 13:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-04  9:17 [PATCH] hwmon: (ads7828) Check return value of regmap_read() in probe Qingshuang Fu
2026-08-04  9:24 ` sashiko-bot
2026-08-04 10:14   ` Qingshuang Fu
2026-08-04 13:59     ` Guenter Roeck
2026-08-04 13:58 ` Guenter Roeck

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