From: Nicolae-Daniel Deaconescu <Nicolae-daniel.Deaconescu@analog.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Uwe Kleine-König" <ukleinek@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Michael Hennerich" <michael.hennerich@analog.com>,
"Trevor Gamblin" <tgamblin@baylibre.com>,
"Joshua Crofts" <crofts@kernel.org>,
"Sergiu Cuciurean" <sergiu.cuciurean@analog.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-pwm@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 5/7] iio: adc: ad7625: move initial mode setup
Date: Mon, 9 Nov 2026 16:07:34 +0200 [thread overview]
Message-ID: <20261109140734.36901-1-Nicolae-daniel.Deaconescu@analog.com> (raw)
In-Reply-To: <20261107015901.0167e32d@jic23-hlaptop>
Hi Jonathan,
On Sat, 7 Nov 2026 01:59:01 +0000, Jonathan Cameron wrote:
>
> > + * If neither sampling mode is available, then report an error,
> > + * since the other modes are not useful defaults.
> > + */
> > + if (st->can_wide_bandwidth) {
> > + ret = ad7960_set_mode(st, AD7960_MODE_WIDE_BANDWIDTH,
> > + st->have_refin, st->vref_mV);
> > + } else if (st->can_narrow_bandwidth) {
> > + ret = ad7960_set_mode(st, AD7960_MODE_NARROW_BANDWIDTH,
> > + st->have_refin, st->vref_mV);
> > + } else {
> > + return dev_err_probe(dev, -EINVAL,
> > + "couldn't set device to wide or narrow bandwidth modes\n");
> > + }
> > +
> > + if (ret)
> > + return dev_err_probe(dev, -EINVAL, "failed to set EN pins\n");
>
> That's ugly given we are some distance from where ret was set and it
> is eating the value. I'd just duplicate it in the if / else if and
> perhaps give a more focused error message in each of those (I haven't
> thought about what it would be so maybe it doesn't!)
>
> I know this came from original code, but seems worth tidying up whilst
> you are here.
Agreed it is ugly, but I'll not duplicate the check per branch, because the
error can't happen
A mode is only chosen when its flag is set here:
if (st->can_wide_bandwidth)
ret = ad7960_set_mode(st, AD7960_MODE_WIDE_BANDWIDTH, ...);
else if (st->can_narrow_bandwidth)
ret = ad7960_set_mode(st, AD7960_MODE_NARROW_BANDWIDTH, ...);
ad7960_set_mode() fails for such a mode only if that same flag is false:
case AD7960_MODE_WIDE_BANDWIDTH:
if (!st->can_wide_bandwidth)
return -EINVAL;
...
return 0;
(AD7960_MODE_NARROW_BANDWIDTH is the same with can_narrow_bandwidth.)
Both flags are set before this point and not changed afterwards.
In v4 I'll pick the mode first and call ad7960_set_mode() once,
returning its error instead of -EINVAL:
if (st->can_wide_bandwidth)
mode = AD7960_MODE_WIDE_BANDWIDTH;
else if (st->can_narrow_bandwidth)
mode = AD7960_MODE_NARROW_BANDWIDTH;
else
return dev_err_probe(dev, -EINVAL,
"couldn't set device to wide or narrow bandwidth modes\n");
ret = ad7960_set_mode(st, mode, st->have_refin, st->vref_mv);
if (ret)
return dev_err_probe(dev, ret, "failed to set EN pins\n");
Thanks,
Daniel
next prev parent reply other threads:[~2026-11-09 14:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 16:05 [PATCH v3 0/7] iio: adc: ad7625: add LTC2387 and ADAQ2387x support Nicolae-Daniel Deaconescu
2026-11-06 16:05 ` [PATCH v3 1/7] pwm: core: add pwm_get_waveform_step_might_sleep() Nicolae-Daniel Deaconescu
2026-11-06 16:05 ` [PATCH v3 2/7] pwm: axi-pwmgen: report the waveform step Nicolae-Daniel Deaconescu
2026-11-07 1:47 ` Jonathan Cameron
2026-11-09 14:06 ` Nicolae-Daniel Deaconescu
2026-11-14 22:36 ` Jonathan Cameron
2026-11-06 16:05 ` [PATCH v3 3/7] iio: adc: ad7625: fix sampling frequency handling Nicolae-Daniel Deaconescu
2026-11-07 1:50 ` Jonathan Cameron
2026-11-09 14:06 ` Nicolae-Daniel Deaconescu
2026-11-06 16:05 ` [PATCH v3 4/7] iio: adc: ad7625: use standard unit names Nicolae-Daniel Deaconescu
2026-11-07 1:55 ` Jonathan Cameron
2026-11-09 14:07 ` Nicolae-Daniel Deaconescu
2026-11-06 16:05 ` [PATCH v3 5/7] iio: adc: ad7625: move initial mode setup Nicolae-Daniel Deaconescu
2026-11-07 1:59 ` Jonathan Cameron
2026-11-09 14:07 ` Nicolae-Daniel Deaconescu [this message]
2026-11-06 16:05 ` [PATCH v3 6/7] dt-bindings: iio: adc: add adi,ltc2387 Nicolae-Daniel Deaconescu
2026-11-06 17:04 ` Conor Dooley
2026-11-06 16:05 ` [PATCH v3 7/7] iio: adc: ad7625: add LTC2387 and ADAQ2387x support Nicolae-Daniel Deaconescu
2026-11-07 2:20 ` Jonathan Cameron
2026-11-09 14:07 ` Nicolae-Daniel Deaconescu
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=20261109140734.36901-1-Nicolae-daniel.Deaconescu@analog.com \
--to=nicolae-daniel.deaconescu@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=crofts@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=michael.hennerich@analog.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=sergiu.cuciurean@analog.com \
--cc=tgamblin@baylibre.com \
--cc=ukleinek@kernel.org \
/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
all inboxes | Powered by JetHome®