Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH v2] hwmon: (ads7828) Don't ignore errors from devm_regulator_get_optional()
@ 2026-08-05  3:00 Qingshuang Fu
  2026-08-05  3:10 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Qingshuang Fu @ 2026-08-05  3:00 UTC (permalink / raw)
  To: Guenter Roeck, Liam Girdwood, Mark Brown, Sam Povilus
  Cc: linux-hwmon, linux-kernel, Qingshuang Fu, Qingshuang Fu

From: Qingshuang Fu <fuqingshuang@kylinos.cn>

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 <fuqingshuang@kylinos.cn>
---
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


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

* Re: [PATCH v2] hwmon: (ads7828) Don't ignore errors from devm_regulator_get_optional()
  2026-08-05  3:00 [PATCH v2] hwmon: (ads7828) Don't ignore errors from devm_regulator_get_optional() Qingshuang Fu
@ 2026-08-05  3:10 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-08-05  3:10 UTC (permalink / raw)
  To: Qingshuang Fu; +Cc: linux-hwmon

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The driver acquires the external 'vref' regulator and reads its voltage but never enables it.
--

--- Patch [1]: [PATCH v2] hwmon: (ads7828) Don't ignore errors from devm_regulator_get_optional() ---
commit 49f8d154ff184810c29b27c75b5602ac3ecd4f65
Author: Qingshuang Fu <fuqingshuang@kylinos.cn>
Subject: hwmon: (ads7828) Don't ignore errors from devm_regulator_get_optional()

The driver currently ignores all errors from devm_regulator_get_optional()
and falls back to using the internal VREF. This commit changes the driver
to propagate genuine errors other than -ENODEV to the caller instead of
silently ignoring them.

> diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
> index 149cfcec78dcc..1c3a8ce8afb5b 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);
>  		}

[Severity: High]
This is a pre-existing issue, but looking at ads7828_probe(), the driver
acquires the external vref regulator and reads its voltage but never actually
enables it:

	reg = devm_regulator_get_optional(dev, "vref");
	if (!IS_ERR(reg)) {
		vref_uv = regulator_get_voltage(reg);
		vref_mv = DIV_ROUND_CLOSEST(vref_uv, 1000);
		...

If the external vref regulator is not marked as regulator-always-on in the
device tree, won't the regulator subsystem disable it during the late initcall
unused-regulator cleanup?

Could this cut the reference voltage to the ADC and cause it to return zeroed
or completely incorrect sensor readings?

Should the driver call regulator_enable() or perhaps use
devm_regulator_get_enable_read_voltage() instead?

>  	}
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260805030056.1082745-1-fffsqian@163.com?part=1

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

end of thread, other threads:[~2026-08-05  3:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05  3:00 [PATCH v2] hwmon: (ads7828) Don't ignore errors from devm_regulator_get_optional() Qingshuang Fu
2026-08-05  3:10 ` sashiko-bot

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