Re: [PATCH] iio: dac: Fix passing uninitialized vref1_uV for no Vref1 case

From: Andy Shevchenko

Date: Tue Apr 14 2026 - 12:32:03 EST


On Tue, Apr 14, 2026 at 10:32:11AM -0500, David Lechner wrote:
> On 4/14/26 7:33 AM, Ariana Lazar wrote:

...

> > + vref1_uV = 0;
> > if (chip_features->have_ext_vref1) {
> > ret = devm_regulator_get_enable_read_voltage(dev, "vref1");
>
> I don't think ignoring all errors here is a good idea. For example, what
> if it returned -EPROBE_DEFER? Then we could end up with the wrong reference
> voltage instead of trying again later.
>
> So probably something like this would be better (also fixes uninitialized
> variable):
>
> if (chip_features->have_ext_vref1 &&
> device_property_present(dev, "vref1")) {
> ret = devm_regulator_get_enable_read_voltage(dev, "vref1");
> if (ret < 0)
> return ret;
>
> vref1_uV = ret;
> data->use_vref1 = true;
> } else {
> vref1_uV = 0;
> dev_dbg(dev, "using internal band gap as voltage reference 1.\n");
> }

Thanks for the suggestion, I agree also with this alternative.

> > if (ret > 0) {
> > vref1_uV = ret;
> > data->use_vref1 = true;
> > } else {
> > - vref1_uV = 0;
> > dev_dbg(dev, "using internal band gap as voltage reference 1.\n");
> > dev_dbg(dev, "Vref1 is unavailable.\n");
> > }

--
With Best Regards,
Andy Shevchenko