Re: [PATCH v3] iio: dac: mcp47feb02: Fix Vref validation [1-999] case
From: Andy Shevchenko
Date: Tue Mar 10 2026 - 09:51:34 EST
On Tue, Mar 10, 2026 at 01:56:44PM +0200, Ariana Lazar wrote:
> Store reference voltages in uV instead of mV to avoid invalid error code
> in dev_err_probe() call. Vref variables store the actual value returned by
> devm_regulator_get_enable_read_voltage() function instead of the results of
> dividing it by MILLI. The corner case [1-999] divided by MILLI of the
> voltage reference variable value would become 0 is covered too.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
...
> struct device *dev = &client->dev;
> struct mcp47feb02_data *data;
> struct iio_dev *indio_dev;
> - int vref1_mV = 0;
> - int vref_mV = 0;
> - int vdd_mV;
> - int ret;
> + int vref1_uV, vref_uV, vdd_uV, ret;
Hmm... Semantically ret != vrefXX_uV and putting on one line is questionable.
But I leave it to Jonathan and others.
...
> if (ret > 0) {
> - vref_mV = ret / MILLI;
> + vref_uV = ret;
> data->use_vref = true;
> } else {
> + vref_uV = 0;
> dev_dbg(dev, "using internal band gap as voltage reference.\n");
> dev_dbg(dev, "Vref is unavailable.\n");
> }
Now a question here, why do we need use_vrefXX if we may deduct it
from vrefXX_uV? Perhaps it deserves a separate change.
--
With Best Regards,
Andy Shevchenko