Re: [PATCH 1/5] gpio: sysfs: use cleanup guards for gpiod_data::mutex
From: Bartosz Golaszewski
Date: Fri Oct 25 2024 - 03:34:17 EST
On Fri, Oct 25, 2024 at 4:54 AM Kent Gibson <warthog618@xxxxxxxxx> wrote:
>
> > @@ -140,7 +133,7 @@ static ssize_t value_store(struct device *dev,
> >
> > status = kstrtol(buf, 0, &value);
> >
> > - mutex_lock(&data->mutex);
> > + guard(mutex)(&data->mutex);
> >
> > if (!test_bit(FLAG_IS_OUT, &desc->flags)) {
> > status = -EPERM;
> > @@ -149,8 +142,6 @@ static ssize_t value_store(struct device *dev,
> > status = size;
> > }
> >
> > - mutex_unlock(&data->mutex);
> > -
> > return status;
> > }
>
>
> With the guard, this can be further simplified by returning immediately
> and collapsing the if-else chain:
>
Ah, right, it's the whole goal of this change after all.
Bart