[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251206181758.2bfefde1@jic23-huawei>
Date: Sat, 6 Dec 2025 18:17:58 +0000
From: Jonathan Cameron <jic23@...nel.org>
To: "Kurt Borja" <kuurtb@...il.com>
Cc: "David Lechner" <dlechner@...libre.com>, "Andy Shevchenko"
<andriy.shevchenko@...el.com>, "Lars-Peter Clausen" <lars@...afoo.de>,
"Michael Hennerich" <Michael.Hennerich@...log.com>, "Benson Leung"
<bleung@...omium.org>, "Antoniu Miclaus" <antoniu.miclaus@...log.com>,
"Gwendal Grignou" <gwendal@...omium.org>, "Shrikant Raskar"
<raskar.shree97@...il.com>, "Per-Daniel Olsson"
<perdaniel.olsson@...s.com>, Nuno Sá <nuno.sa@...log.com>,
"Andy Shevchenko" <andy@...nel.org>, "Guenter Roeck" <groeck@...omium.org>,
"Jonathan Cameron" <Jonathan.Cameron@...wei.com>,
<linux-iio@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<chrome-platform@...ts.linux.dev>
Subject: Re: [PATCH RFC 5/6] iio: health: max30102: Use cleanup.h for IIO
locks
On Thu, 04 Dec 2025 12:47:08 -0500
"Kurt Borja" <kuurtb@...il.com> wrote:
> On Thu Dec 4, 2025 at 12:35 PM -05, David Lechner wrote:
> > On 12/4/25 11:07 AM, Kurt Borja wrote:
> >> On Wed Dec 3, 2025 at 4:52 PM -05, David Lechner wrote:
> >>> On 12/3/25 1:18 PM, Kurt Borja wrote:
> >
> > ...
> >
> >>> I would write the whole function like this:
> >>>
> >>> static int max30102_read_raw(struct iio_dev *indio_dev,
> >>> struct iio_chan_spec const *chan,
> >>> int *val, int *val2, long mask)
> >>> {
> >>> struct max30102_data *data = iio_priv(indio_dev);
> >>> int ret;
> >>>
> >>> switch (mask) {
> >>> case IIO_CHAN_INFO_RAW: {
> >>> /*
> >>> * Temperature reading can only be acquired when not in
> >>> * shutdown; leave shutdown briefly when buffer not running
> >>> */
> >>> guard(iio_device_claim)(indio_dev);
> >>
> >> AFAIK you can't guard() inside switch-case blocks. I don't know the
> >> exact reason, but it has to be scoped_guard().
> >
> > You can. You just need the braces like I showed in my suggestion.
> >
> > The reason is that guard() is declaring local variables and some
> > compilers like LLVM don't like declaring local variables in a
> > switch case. By adding the { } scope, the variables are limited
> > to that scope and the issue goes away.
>
> Ah - You're right. I dind't see the braces.
>
> Now it is overly complicated. In this case I see why guard() isn't
> really an improvement.
This bit of guard() usage is fairly well known and I think people are
getting familiar with it.
So I'd prefer the form David suggested. It is nice to get rid
of the mode claiming dance in here.
Jonathan
>
>
Powered by blists - more mailing lists