* [PATCH] iio: humidity: ens210: remove compiler warning workaround
@ 2026-05-22 1:25 David Lechner
2026-05-22 5:25 ` Maxwell Doose
0 siblings, 1 reply; 5+ messages in thread
From: David Lechner @ 2026-05-22 1:25 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, David Lechner
Rewrite IIO_CHAN_INFO_RAW case to avoid needing to add unreachable code
to work around a compiler warning.
When scoped_guard() was first introduced, compilers could not see when
it returned unconditionally from inside the hidden for loop. This has
since been fixed in the macro definition. So removing the `return
-EINVAL` should be enough. Still, we can improve readability, decrease
indentation and avoid the hidden for loop by rewriting the case without
scoped_guard().
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/humidity/ens210.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/humidity/ens210.c b/drivers/iio/humidity/ens210.c
index 22ad208e6aa6..49543fc389bf 100644
--- a/drivers/iio/humidity/ens210.c
+++ b/drivers/iio/humidity/ens210.c
@@ -149,15 +149,16 @@ static int ens210_read_raw(struct iio_dev *indio_dev,
int ret;
switch (mask) {
- case IIO_CHAN_INFO_RAW:
- scoped_guard(mutex, &data->lock) {
- ret = ens210_get_measurement(
- indio_dev, channel->type == IIO_TEMP, val);
- if (ret)
- return ret;
- return IIO_VAL_INT;
- }
- return -EINVAL; /* compiler warning workaround */
+ case IIO_CHAN_INFO_RAW: {
+ guard(mutex)(&data->lock);
+
+ ret = ens210_get_measurement(indio_dev, channel->type == IIO_TEMP,
+ val);
+ if (ret)
+ return ret;
+
+ return IIO_VAL_INT;
+ }
case IIO_CHAN_INFO_SCALE:
if (channel->type == IIO_TEMP) {
*val = 15;
---
base-commit: e1a29334a9c043defe7a9363fa76d399d3fdfbec
change-id: 20260521-iio-humidity-ens210-remove-hack-7c5a6496547c
Best regards,
--
David Lechner <dlechner@baylibre.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: humidity: ens210: remove compiler warning workaround
2026-05-22 1:25 [PATCH] iio: humidity: ens210: remove compiler warning workaround David Lechner
@ 2026-05-22 5:25 ` Maxwell Doose
2026-05-22 12:37 ` Jonathan Cameron
0 siblings, 1 reply; 5+ messages in thread
From: Maxwell Doose @ 2026-05-22 5:25 UTC (permalink / raw)
To: David Lechner
Cc: Jonathan Cameron, Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel
Hi David,
On Thu, May 21, 2026 at 8:26 PM David Lechner <dlechner@baylibre.com> wrote:
>
> Rewrite IIO_CHAN_INFO_RAW case to avoid needing to add unreachable code
> to work around a compiler warning.
>
> When scoped_guard() was first introduced, compilers could not see when
> it returned unconditionally from inside the hidden for loop. This has
> since been fixed in the macro definition. So removing the `return
> -EINVAL` should be enough. Still, we can improve readability, decrease
> indentation and avoid the hidden for loop by rewriting the case without
> scoped_guard().
>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> drivers/iio/humidity/ens210.c | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/humidity/ens210.c b/drivers/iio/humidity/ens210.c
> index 22ad208e6aa6..49543fc389bf 100644
> --- a/drivers/iio/humidity/ens210.c
> +++ b/drivers/iio/humidity/ens210.c
> @@ -149,15 +149,16 @@ static int ens210_read_raw(struct iio_dev *indio_dev,
> int ret;
>
> switch (mask) {
> - case IIO_CHAN_INFO_RAW:
> - scoped_guard(mutex, &data->lock) {
> - ret = ens210_get_measurement(
> - indio_dev, channel->type == IIO_TEMP, val);
> - if (ret)
> - return ret;
> - return IIO_VAL_INT;
> - }
> - return -EINVAL; /* compiler warning workaround */
> + case IIO_CHAN_INFO_RAW: {
> + guard(mutex)(&data->lock);
> +
> + ret = ens210_get_measurement(indio_dev, channel->type == IIO_TEMP,
> + val);
> + if (ret)
> + return ret;
> +
> + return IIO_VAL_INT;
> + }
> case IIO_CHAN_INFO_SCALE:
> if (channel->type == IIO_TEMP) {
> *val = 15;
>
I'm questioning how that initial commit got merged at all, they
could've just used guard()() with {} (the kind of thing to make me
want to take a look at this file even further!). Visually looks good
to me but will follow-up later with rb if it all checks out.
best regards,
max
> ---
> base-commit: e1a29334a9c043defe7a9363fa76d399d3fdfbec
> change-id: 20260521-iio-humidity-ens210-remove-hack-7c5a6496547c
>
> Best regards,
> --
> David Lechner <dlechner@baylibre.com>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: humidity: ens210: remove compiler warning workaround
2026-05-22 5:25 ` Maxwell Doose
@ 2026-05-22 12:37 ` Jonathan Cameron
2026-05-22 12:43 ` Maxwell Doose
2026-06-02 18:06 ` Andy Shevchenko
0 siblings, 2 replies; 5+ messages in thread
From: Jonathan Cameron @ 2026-05-22 12:37 UTC (permalink / raw)
To: Maxwell Doose
Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel
On Fri, 22 May 2026 00:25:08 -0500
Maxwell Doose <m32285159@gmail.com> wrote:
> Hi David,
>
> On Thu, May 21, 2026 at 8:26 PM David Lechner <dlechner@baylibre.com> wrote:
> >
> > Rewrite IIO_CHAN_INFO_RAW case to avoid needing to add unreachable code
> > to work around a compiler warning.
> >
> > When scoped_guard() was first introduced, compilers could not see when
> > it returned unconditionally from inside the hidden for loop. This has
> > since been fixed in the macro definition. So removing the `return
> > -EINVAL` should be enough. Still, we can improve readability, decrease
> > indentation and avoid the hidden for loop by rewriting the case without
> > scoped_guard().
> >
> > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > ---
> > drivers/iio/humidity/ens210.c | 19 ++++++++++---------
> > 1 file changed, 10 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/iio/humidity/ens210.c b/drivers/iio/humidity/ens210.c
> > index 22ad208e6aa6..49543fc389bf 100644
> > --- a/drivers/iio/humidity/ens210.c
> > +++ b/drivers/iio/humidity/ens210.c
> > @@ -149,15 +149,16 @@ static int ens210_read_raw(struct iio_dev *indio_dev,
> > int ret;
> >
> > switch (mask) {
> > - case IIO_CHAN_INFO_RAW:
> > - scoped_guard(mutex, &data->lock) {
> > - ret = ens210_get_measurement(
> > - indio_dev, channel->type == IIO_TEMP, val);
> > - if (ret)
> > - return ret;
> > - return IIO_VAL_INT;
> > - }
> > - return -EINVAL; /* compiler warning workaround */
> > + case IIO_CHAN_INFO_RAW: {
> > + guard(mutex)(&data->lock);
> > +
> > + ret = ens210_get_measurement(indio_dev, channel->type == IIO_TEMP,
> > + val);
> > + if (ret)
> > + return ret;
> > +
> > + return IIO_VAL_INT;
> > + }
> > case IIO_CHAN_INFO_SCALE:
> > if (channel->type == IIO_TEMP) {
> > *val = 15;
> >
>
> I'm questioning how that initial commit got merged at all, they
> could've just used guard()() with {} (the kind of thing to make me
> want to take a look at this file even further!). Visually looks good
> to me but will follow-up later with rb if it all checks out.
The guard stuff was fairly new at the time so we were still working out what
patterns make sense. Took a little while for consensus to emerge!
Anyhow patch is obviously correct and a cleanup so applied to the testing
branch of iio.git. Happy to add tags etc for next few days
(or drop it if I'm missing something!)
Jonathan
>
> best regards,
> max
>
>
> > ---
> > base-commit: e1a29334a9c043defe7a9363fa76d399d3fdfbec
> > change-id: 20260521-iio-humidity-ens210-remove-hack-7c5a6496547c
> >
> > Best regards,
> > --
> > David Lechner <dlechner@baylibre.com>
> >
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: humidity: ens210: remove compiler warning workaround
2026-05-22 12:37 ` Jonathan Cameron
@ 2026-05-22 12:43 ` Maxwell Doose
2026-06-02 18:06 ` Andy Shevchenko
1 sibling, 0 replies; 5+ messages in thread
From: Maxwell Doose @ 2026-05-22 12:43 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel
On Fri, May 22, 2026 at 7:37 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Fri, 22 May 2026 00:25:08 -0500
> Maxwell Doose <m32285159@gmail.com> wrote:
>
> > Hi David,
> >
> > On Thu, May 21, 2026 at 8:26 PM David Lechner <dlechner@baylibre.com> wrote:
> > >
> > > Rewrite IIO_CHAN_INFO_RAW case to avoid needing to add unreachable code
> > > to work around a compiler warning.
> > >
> > > When scoped_guard() was first introduced, compilers could not see when
> > > it returned unconditionally from inside the hidden for loop. This has
> > > since been fixed in the macro definition. So removing the `return
> > > -EINVAL` should be enough. Still, we can improve readability, decrease
> > > indentation and avoid the hidden for loop by rewriting the case without
> > > scoped_guard().
> > >
> > > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > > ---
> > > drivers/iio/humidity/ens210.c | 19 ++++++++++---------
> > > 1 file changed, 10 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/drivers/iio/humidity/ens210.c b/drivers/iio/humidity/ens210.c
> > > index 22ad208e6aa6..49543fc389bf 100644
> > > --- a/drivers/iio/humidity/ens210.c
> > > +++ b/drivers/iio/humidity/ens210.c
> > > @@ -149,15 +149,16 @@ static int ens210_read_raw(struct iio_dev *indio_dev,
> > > int ret;
> > >
> > > switch (mask) {
> > > - case IIO_CHAN_INFO_RAW:
> > > - scoped_guard(mutex, &data->lock) {
> > > - ret = ens210_get_measurement(
> > > - indio_dev, channel->type == IIO_TEMP, val);
> > > - if (ret)
> > > - return ret;
> > > - return IIO_VAL_INT;
> > > - }
> > > - return -EINVAL; /* compiler warning workaround */
> > > + case IIO_CHAN_INFO_RAW: {
> > > + guard(mutex)(&data->lock);
> > > +
> > > + ret = ens210_get_measurement(indio_dev, channel->type == IIO_TEMP,
> > > + val);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + return IIO_VAL_INT;
> > > + }
> > > case IIO_CHAN_INFO_SCALE:
> > > if (channel->type == IIO_TEMP) {
> > > *val = 15;
> > >
> >
> > I'm questioning how that initial commit got merged at all, they
> > could've just used guard()() with {} (the kind of thing to make me
> > want to take a look at this file even further!). Visually looks good
> > to me but will follow-up later with rb if it all checks out.
>
> The guard stuff was fairly new at the time so we were still working out what
> patterns make sense. Took a little while for consensus to emerge!
>
Thanks for the insight, I wouldn't have been around here for that
early period of guard()() but still pretty interesting.
>
> Anyhow patch is obviously correct and a cleanup so applied to the testing
> branch of iio.git. Happy to add tags etc for next few days
> (or drop it if I'm missing something!)
>
Yeah if you want to add my rb you can but don't feel like you have to!
best regards,
max
> Jonathan
>
> >
> > best regards,
> > max
> >
> >
> > > ---
> > > base-commit: e1a29334a9c043defe7a9363fa76d399d3fdfbec
> > > change-id: 20260521-iio-humidity-ens210-remove-hack-7c5a6496547c
> > >
> > > Best regards,
> > > --
> > > David Lechner <dlechner@baylibre.com>
> > >
> > >
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: humidity: ens210: remove compiler warning workaround
2026-05-22 12:37 ` Jonathan Cameron
2026-05-22 12:43 ` Maxwell Doose
@ 2026-06-02 18:06 ` Andy Shevchenko
1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-06-02 18:06 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Maxwell Doose, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On Fri, May 22, 2026 at 01:37:17PM +0100, Jonathan Cameron wrote:
> On Fri, 22 May 2026 00:25:08 -0500
> Maxwell Doose <m32285159@gmail.com> wrote:
> > On Thu, May 21, 2026 at 8:26 PM David Lechner <dlechner@baylibre.com> wrote:
...
> > > - case IIO_CHAN_INFO_RAW:
> > > - scoped_guard(mutex, &data->lock) {
> > > - ret = ens210_get_measurement(
> > > - indio_dev, channel->type == IIO_TEMP, val);
> > > - if (ret)
> > > - return ret;
> > > - return IIO_VAL_INT;
> > > - }
> > > - return -EINVAL; /* compiler warning workaround */
We may just drop this return statement, but in this case some people may be
confused. In addition the patch fixes the indentation of the function
parameters, which is good on itself.
> > > + case IIO_CHAN_INFO_RAW: {
> > > + guard(mutex)(&data->lock);
> > > +
> > > + ret = ens210_get_measurement(indio_dev, channel->type == IIO_TEMP,
> > > + val);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + return IIO_VAL_INT;
> > > + }
> > I'm questioning how that initial commit got merged at all, they
> > could've just used guard()() with {} (the kind of thing to make me
> > want to take a look at this file even further!). Visually looks good
> > to me but will follow-up later with rb if it all checks out.
>
> The guard stuff was fairly new at the time so we were still working out what
> patterns make sense. Took a little while for consensus to emerge!
>
> Anyhow patch is obviously correct and a cleanup so applied to the testing
> branch of iio.git. Happy to add tags etc for next few days
> (or drop it if I'm missing something!)
Taking the above into consideration,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-02 18:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-22 1:25 [PATCH] iio: humidity: ens210: remove compiler warning workaround David Lechner
2026-05-22 5:25 ` Maxwell Doose
2026-05-22 12:37 ` Jonathan Cameron
2026-05-22 12:43 ` Maxwell Doose
2026-06-02 18:06 ` Andy Shevchenko
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®