Re: [PATCH RFC 5/6] iio: health: max30102: Use cleanup.h for IIO locks
From: David Lechner
Date: Thu Dec 04 2025 - 12:35:14 EST
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.