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

From: Andy Shevchenko

Date: Tue Apr 14 2026 - 12:24:00 EST


On Tue, Apr 14, 2026 at 08:21:00AM -0500, David Lechner wrote:
> On 4/14/26 7:48 AM, Andy Shevchenko wrote:
> > On Tue, Apr 14, 2026 at 03:33:38PM +0300, Ariana Lazar wrote:
> >> Initialize vref1_uV variable to 0 before calling
> >> mcp47feb02_init_ch_scales() in mcp47feb02_probe() to avoid passing an
> >> uninitialized value when have_ext_vref1 is false.

...

> >> + vref1_uV = 0;
> >> if (chip_features->have_ext_vref1) {
> >
> > I'm wondering what will happen if we do the below unconditionally?
> >
> >> ret = devm_regulator_get_enable_read_voltage(dev, "vref1");
> >
> > If we have no regulator, we get a dummy one, right? What is the voltage will
> > be? 0?
>
> It will fail with -EINVAL because dummy regulator doesn't have a
> voltage specified anywhere.

Okay, and we have exactly a branch to assign 0 to the value with even useful
debug message which will answer to two questions at once: Do we have it? Yes,
since we see the debug message. Have we got it? No, as it's written in the
debug message.

That said, I think the better fix is just to drop the outer conditional.

> >> 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