* [PATCH v4] hwmon: (ads7828) Fix external VREF regulator handling
@ 2026-08-05 6:16 Qingshuang Fu
2026-08-05 6:23 ` sashiko-bot
2026-08-05 14:52 ` Guenter Roeck
0 siblings, 2 replies; 3+ messages in thread
From: Qingshuang Fu @ 2026-08-05 6:16 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 has two issues with the external VREF regulator
handling in ads7828_probe():
1. All errors from devm_regulator_get_optional() are ignored, causing the
driver to incorrectly fall back to internal VREF even for transient
errors like -EPROBE_DEFER or genuine failures like -ENOMEM.
2. The external regulator is never enabled. The driver calls
regulator_get_voltage() without first calling regulator_enable(),
so the VREF pin may remain unpowered if the regulator is not
configured as always-on.
Fix both issues by switching to devm_regulator_get_enable_read_voltage(),
which handles regulator get, enable, and voltage read in one call.
Only -ENODEV (no regulator specified in device tree) should trigger the
fallback to internal VREF. All other errors are propagated to the caller.
Fixes: a8ddfea09566 ("hwmon: (ads7828) Accept optional parameters from device tree")
Signed-off-by: Qingshuang Fu <fuqingshuang@kylinos.cn>
---
Changes in v4:
- Invert the control flow to check errors first (if (vref_uv < 0) { ... }
else { ... }), as requested by Guenter Roeck.
Changes in v3:
- Switch to devm_regulator_get_enable_read_voltage() to also enable the
external regulator, as suggested by Guenter Roeck.
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 | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index 149cfcec78dc..f8f2f621dfea 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -106,12 +106,11 @@ static int ads7828_probe(struct i2c_client *client)
struct ads7828_data *data;
struct device *hwmon_dev;
unsigned int vref_mv = ADS7828_INT_VREF_MV;
- unsigned int vref_uv;
+ int vref_uv;
bool diff_input = false;
bool ext_vref = false;
unsigned int regval;
enum ads7828_chips chip;
- struct regulator *reg;
data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
if (!data)
@@ -125,9 +124,11 @@ static int ads7828_probe(struct i2c_client *client)
} else if (dev->of_node) {
diff_input = of_property_read_bool(dev->of_node,
"ti,differential-input");
- reg = devm_regulator_get_optional(dev, "vref");
- if (!IS_ERR(reg)) {
- vref_uv = regulator_get_voltage(reg);
+ vref_uv = devm_regulator_get_enable_read_voltage(dev, "vref");
+ if (vref_uv < 0) {
+ if (vref_uv != -ENODEV)
+ return vref_uv;
+ } else {
vref_mv = DIV_ROUND_CLOSEST(vref_uv, 1000);
if (vref_mv < ADS7828_EXT_VREF_MV_MIN ||
vref_mv > ADS7828_EXT_VREF_MV_MAX)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4] hwmon: (ads7828) Fix external VREF regulator handling
2026-08-05 6:16 [PATCH v4] hwmon: (ads7828) Fix external VREF regulator handling Qingshuang Fu
@ 2026-08-05 6:23 ` sashiko-bot
2026-08-05 14:52 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-08-05 6:23 UTC (permalink / raw)
To: Qingshuang Fu; +Cc: linux-hwmon
> From: Qingshuang Fu <fuqingshuang@kylinos.cn>
>
> The driver currently has two issues with the external VREF regulator
> handling in ads7828_probe():
>
> 1. All errors from devm_regulator_get_optional() are ignored, causing the
> driver to incorrectly fall back to internal VREF even for transient
> errors like -EPROBE_DEFER or genuine failures like -ENOMEM.
>
> 2. The external regulator is never enabled. The driver calls
> regulator_get_voltage() without first calling regulator_enable(),
> so the VREF pin may remain unpowered if the regulator is not
> configured as always-on.
>
> Fix both issues by switching to devm_regulator_get_enable_read_voltage(),
> which handles regulator get, enable, and voltage read in one call.
> Only -ENODEV (no regulator specified in device tree) should trigger the
> fallback to internal VREF. All other errors are propagated to the caller.
>
> Fixes: a8ddfea09566 ("hwmon: (ads7828) Accept optional parameters from device tree")
> Signed-off-by: Qingshuang Fu <fuqingshuang@kylinos.cn>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805061645.1331652-1-fffsqian@163.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4] hwmon: (ads7828) Fix external VREF regulator handling
2026-08-05 6:16 [PATCH v4] hwmon: (ads7828) Fix external VREF regulator handling Qingshuang Fu
2026-08-05 6:23 ` sashiko-bot
@ 2026-08-05 14:52 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-08-05 14:52 UTC (permalink / raw)
To: Qingshuang Fu
Cc: Liam Girdwood, Mark Brown, Sam Povilus, linux-hwmon, linux-kernel,
Qingshuang Fu
On Wed, Aug 05, 2026 at 02:16:45PM +0800, Qingshuang Fu wrote:
> From: Qingshuang Fu <fuqingshuang@kylinos.cn>
>
> The driver currently has two issues with the external VREF regulator
> handling in ads7828_probe():
>
> 1. All errors from devm_regulator_get_optional() are ignored, causing the
> driver to incorrectly fall back to internal VREF even for transient
> errors like -EPROBE_DEFER or genuine failures like -ENOMEM.
>
> 2. The external regulator is never enabled. The driver calls
> regulator_get_voltage() without first calling regulator_enable(),
> so the VREF pin may remain unpowered if the regulator is not
> configured as always-on.
>
> Fix both issues by switching to devm_regulator_get_enable_read_voltage(),
> which handles regulator get, enable, and voltage read in one call.
> Only -ENODEV (no regulator specified in device tree) should trigger the
> fallback to internal VREF. All other errors are propagated to the caller.
>
> Fixes: a8ddfea09566 ("hwmon: (ads7828) Accept optional parameters from device tree")
> Signed-off-by: Qingshuang Fu <fuqingshuang@kylinos.cn>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-05 14:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 6:16 [PATCH v4] hwmon: (ads7828) Fix external VREF regulator handling Qingshuang Fu
2026-08-05 6:23 ` sashiko-bot
2026-08-05 14:52 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox