Re: [PATCH 4/4] iio: adc: ti-ads112c14: add measurement channel support

From: Andy Shevchenko

Date: Wed Jun 17 2026 - 06:28:27 EST


On Tue, Jun 16, 2026 at 10:55:34AM -0500, David Lechner wrote:
> On 6/16/26 3:36 AM, Andy Shevchenko wrote:
> > On Mon, Jun 15, 2026 at 05:00:02PM -0500, David Lechner (TI) wrote:

...

> >> + if (fwnode_property_present(child, "single-channel")) {
> >> + ret = fwnode_property_read_u32(child, "single-channel", &spec->channel);
> >> + if (ret)
> >> + return dev_err_probe(dev, ret,
> >> + "failed to read single-channel property\n");
> >> +
> >> + if (spec->channel >= 8)
> >> + return dev_err_probe(dev, -EINVAL,
> >> + "single-channel value must be between 0 and 7\n");
> >> + } else if (fwnode_property_present(child, "diff-channels")) {
> >> + ret = fwnode_property_read_u32_array(child, "diff-channels", pair, ARRAY_SIZE(pair));
> >> + if (ret)
> >> + return dev_err_probe(dev, ret,
> >> + "failed to read diff-channels property\n");
> >> +
> >> + if (pair[0] >= 8 || pair[1] >= 8)
> >> + return dev_err_probe(dev, -EINVAL,
> >> + "diff-channels values must be between 0 and 7\n");
> >> +
> >> + spec->channel = pair[0];
> >> + spec->channel2 = pair[1];
> >> + spec->differential = 1;
> >> + } else {
> >> + return dev_err_probe(dev, -EINVAL,
> >> + "channel node missing channel type property\n");
> >> + }
> >
> > Looking how it's going to spread (I mean the above pattern), perhaps it's a time to introduce bunch of
> >
> > fwnode_property_read_*_optional()
> >
> > and the respective device_property_read_*_optional()?
> >
> > Let's start from u32 case only, as it will be most used anyway.
>
> I don't think that would be really any different from device_property_read_*
> and checking for -EINVAL or ignoring the error completely. TBH, I really like
> it this way with fwnode_property_present().

Yeah, it's explicit, but with _optional() we may simply have

propname = "single-channel";
ret = fwnode_property_read_u32_optional(child, propname, &spec->channel, 0);
if (ret)
return dev_err_probe(dev, ret, "failed to read %s property\n", propname);
if (spec->channel >= 8)
return dev_err_probe(dev, -EINVAL, "%s value must be between 0 and 7\n", propname);

However I admit that in the above case you also want to distinguish the cases.

--
With Best Regards,
Andy Shevchenko