Re: [PATCH v2 2/4] iio: adc: Add support for the Renesas RZ/N1 ADC

From: Andy Shevchenko
Date: Mon Nov 03 2025 - 04:41:53 EST


On Mon, Nov 03, 2025 at 09:40:45AM +0100, Herve Codina wrote:
> On Thu, 30 Oct 2025 11:00:12 +0200
> Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:

...

> > > + ret = devm_regulator_get_enable_optional(dev, avdd_name);
> > > + if (ret < 0) {
> > > + if (ret != -ENODEV)
> > > + return dev_err_probe(dev, ret,
> > > + "Failed to get '%s' regulator\n",
> > > + avdd_name);
> > > + return 0;
> > > + }
> >
> > if (ret == -ENODEV)
> > return dev_err_probe(); // takes less LoCs
> > if (ret < 0) // do we need ' < 0' part?
> > return 0;
>
> Well, I need to abort on error returned by devm_regulator_get_enable_optional()
> but I need also to filter out the ENODEV error.
>
> ENODEV, returned by devm_regulator_get_enable_optional(), means that the
> regulator is not present. This should not be seen as an error by the caller.
> Indeed, the regulator is not present and so, the related ADC core will not
> be used. This is not an error from the caller perspective.
>
> The code you proposed is not correct regarding this point.

Yeah, sorry for that, but I think you got the idea...

The (working) solution should be like this:

if (ret == -ENODEV)
return 0;
if (ret < 0) // do we need ' < 0' part?
return dev_err_probe(); // takes less LoCs

> Instead of my original code, I can propose the following:
> if (ret < 0) {
> if (ret == -ENODEV)
> return 0;
>
> return dev_err_probe(dev, ret,
> "Failed to get '%s' regulator\n",
> avdd_name);
> }
>
> What do you think about it?

--
With Best Regards,
Andy Shevchenko