Re: [PATCH RFC 5/6] iio: health: max30102: Use cleanup.h for IIO locks
From: Kurt Borja
Date: Sun Dec 07 2025 - 10:59:40 EST
On Sat Dec 6, 2025 at 1:17 PM -05, Jonathan Cameron wrote:
> On Thu, 04 Dec 2025 12:47:08 -0500
> "Kurt Borja" <kuurtb@xxxxxxxxx> 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.
Ok, that's good to hear. I'll take David's suggestions for the next
version.
>
> Jonathan
--
~ Kurt