[PATCH v2] hwmon: (ads7828) Don't ignore errors from devm_regulator_get_optional()

Qingshuang Fu <[email protected]> Wed, 5 Aug 2026 11:00:56 +0800
Newsgroups org.kernel.vger.linux-hwmon,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
From: Qingshuang Fu <[email protected]>

The driver currently ignores all errors from devm_regulator_get_optional()
and falls back to using the internal VREF. This is incorrect for errors
other than -ENODEV:

- -EPROBE_DEFER: the external regulator will be available later; retrying
  probe avoids a voltage conflict between internal and external VREF.
- -ENOMEM, -EINVAL, etc.: genuine failures that should be propagated, not
  silently ignored.

Only -ENODEV (no regulator specified in device tree) should trigger the
fallback to internal VREF. Propagate all other errors to the caller.

Fixes: a8ddfea09566 ("hwmon: (ads7828) Accept optional parameters from device tree")
Signed-off-by: Qingshuang Fu <[email protected]>
---
Changes in v2:
- Broaden the error check to handle all errors except -ENODEV, instead of
  only checking for -EPROBE_DEFER. This addresses the Sashiko AI review
  concern about masking genuine errors like -ENOMEM and -EINVAL.

 drivers/hwmon/ads7828.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index 149cfcec78dc..1c3a8ce8afb5 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -133,6 +133,8 @@ static int ads7828_probe(struct i2c_client *client)
 			    vref_mv > ADS7828_EXT_VREF_MV_MAX)
 				return -EINVAL;
 			ext_vref = true;
+		} else if (PTR_ERR(reg) != -ENODEV) {
+			return PTR_ERR(reg);
 		}
 	}
 

base-commit: c21bb4193868a8de71fc4693fa741e195fdf5d86
-- 
2.25.1