From: "Nuno Sá" <noname.nuno@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Alisa-Dariana Roman <alisadariana@gmail.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Alisa-Dariana Roman" <alisa.roman@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Subject: Re: [PATCH v1 1/1] iio: adc: ad7191: Don't check for specific errors when parsing properties
Date: Fri, 20 Feb 2026 10:04:52 +0000 [thread overview]
Message-ID: <c59c19d923d369eac2a0a46405e13e41836591c2.camel@gmail.com> (raw)
In-Reply-To: <20260219143936.2276366-1-andriy.shevchenko@linux.intel.com>
On Thu, 2026-02-19 at 15:39 +0100, Andy Shevchenko wrote:
> Instead of checking for the specific error codes (that can be considered
> a layering violation to some extent) check for the property existence first
> and then either parse it, or apply a default value.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
Not really sure how I feel about this one. Checking for specific errors is a very common
pattern and this change just makes it we check for the property presence twice. That said,
this makes it more "future proof" (though I find it very unlikely for ret value o change).
Anyways, even if we choose to go down this route, I don't see much benefit in starting
converting the drivers with the pattern below (which should be a considerable number).
- Nuno Sá
> drivers/iio/adc/ad7191.c | 63 +++++++++++++++++++++-------------------
> 1 file changed, 33 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7191.c b/drivers/iio/adc/ad7191.c
> index d9cd903ffdd2..51ec199fb06f 100644
> --- a/drivers/iio/adc/ad7191.c
> +++ b/drivers/iio/adc/ad7191.c
> @@ -154,27 +154,18 @@ static int ad7191_config_setup(struct iio_dev *indio_dev)
> const u32 gain[4] = { 1, 8, 64, 128 };
> static u32 scale_buffer[4][2];
> int odr_value, odr_index = 0, pga_value, pga_index = 0, i, ret;
> + const char *propname;
> u64 scale_uv;
>
> st->samp_freq_index = 0;
> st->scale_index = 0;
>
> - ret = device_property_read_u32(dev, "adi,odr-value", &odr_value);
> - if (ret && ret != -EINVAL)
> - return dev_err_probe(dev, ret, "Failed to get odr value.\n");
> + propname = "adi,odr-value";
> + if (device_property_present(dev, propname)) {
> + ret = device_property_read_u32(dev, propname, &odr_value);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to get %s.\n", propname);
>
> - if (ret == -EINVAL) {
> - st->odr_gpios = devm_gpiod_get_array(dev, "odr", GPIOD_OUT_LOW);
> - if (IS_ERR(st->odr_gpios))
> - return dev_err_probe(dev, PTR_ERR(st->odr_gpios),
> - "Failed to get odr gpios.\n");
> -
> - if (st->odr_gpios->ndescs != 2)
> - return dev_err_probe(dev, -EINVAL, "Expected 2 odr gpio pins.\n");
> -
> - st->samp_freq_avail = samp_freq;
> - st->samp_freq_avail_size = ARRAY_SIZE(samp_freq);
> - } else {
> for (i = 0; i < ARRAY_SIZE(samp_freq); i++) {
> if (odr_value != samp_freq[i])
> continue;
> @@ -186,6 +177,17 @@ static int ad7191_config_setup(struct iio_dev *indio_dev)
> st->samp_freq_avail_size = 1;
>
> st->odr_gpios = NULL;
> + } else {
> + st->odr_gpios = devm_gpiod_get_array(dev, "odr", GPIOD_OUT_LOW);
> + if (IS_ERR(st->odr_gpios))
> + return dev_err_probe(dev, PTR_ERR(st->odr_gpios),
> + "Failed to get odr gpios.\n");
> +
> + if (st->odr_gpios->ndescs != 2)
> + return dev_err_probe(dev, -EINVAL, "Expected 2 odr gpio pins.\n");
> +
> + st->samp_freq_avail = samp_freq;
> + st->samp_freq_avail_size = ARRAY_SIZE(samp_freq);
> }
>
> mutex_lock(&st->lock);
> @@ -200,22 +202,12 @@ static int ad7191_config_setup(struct iio_dev *indio_dev)
>
> mutex_unlock(&st->lock);
>
> - ret = device_property_read_u32(dev, "adi,pga-value", &pga_value);
> - if (ret && ret != -EINVAL)
> - return dev_err_probe(dev, ret, "Failed to get pga value.\n");
> + propname = "adi,pga-value";
> + if (device_property_present(dev, propname)) {
> + ret = device_property_read_u32(dev, propname, &pga_value);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to get %s.\n", propname);
>
> - if (ret == -EINVAL) {
> - st->pga_gpios = devm_gpiod_get_array(dev, "pga", GPIOD_OUT_LOW);
> - if (IS_ERR(st->pga_gpios))
> - return dev_err_probe(dev, PTR_ERR(st->pga_gpios),
> - "Failed to get pga gpios.\n");
> -
> - if (st->pga_gpios->ndescs != 2)
> - return dev_err_probe(dev, -EINVAL, "Expected 2 pga gpio pins.\n");
> -
> - st->scale_avail = scale_buffer;
> - st->scale_avail_size = ARRAY_SIZE(scale_buffer);
> - } else {
> for (i = 0; i < ARRAY_SIZE(gain); i++) {
> if (pga_value != gain[i])
> continue;
> @@ -227,6 +219,17 @@ static int ad7191_config_setup(struct iio_dev *indio_dev)
> st->scale_avail_size = 1;
>
> st->pga_gpios = NULL;
> + } else {
> + st->pga_gpios = devm_gpiod_get_array(dev, "pga", GPIOD_OUT_LOW);
> + if (IS_ERR(st->pga_gpios))
> + return dev_err_probe(dev, PTR_ERR(st->pga_gpios),
> + "Failed to get pga gpios.\n");
> +
> + if (st->pga_gpios->ndescs != 2)
> + return dev_err_probe(dev, -EINVAL, "Expected 2 pga gpio pins.\n");
> +
> + st->scale_avail = scale_buffer;
> + st->scale_avail_size = ARRAY_SIZE(scale_buffer);
> }
>
> st->temp_gpio = devm_gpiod_get(dev, "temp", GPIOD_OUT_LOW);
next prev parent reply other threads:[~2026-02-20 10:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 14:39 [PATCH v1 1/1] iio: adc: ad7191: Don't check for specific errors when parsing properties Andy Shevchenko
2026-02-20 10:04 ` Nuno Sá [this message]
2026-02-20 10:33 ` Andy Shevchenko
2026-03-17 10:42 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c59c19d923d369eac2a0a46405e13e41836591c2.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=alisa.roman@analog.com \
--cc=alisadariana@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox