[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMRc=McqdnBBSe1QhyNEFCs3E+Qb_K-z1dT+B8+n2KvWajj5hA@mail.gmail.com>
Date: Tue, 15 Aug 2023 21:09:55 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Linus Walleij <linus.walleij@...aro.org>,
Kent Gibson <warthog618@...il.com>, linux-gpio@...r.kernel.org,
linux-kernel@...r.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: Re: [PATCH v3] gpio: sim: simplify code with cleanup helpers
On Tue, Aug 15, 2023 at 12:31 PM Andy Shevchenko
<andriy.shevchenko@...ux.intel.com> wrote:
>
> On Sat, Aug 12, 2023 at 08:36:35PM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> >
> > Use macros defined in linux/cleanup.h to automate resource lifetime
> > control in gpio-sim.
>
> ...
>
> > static void gpio_sim_set(struct gpio_chip *gc, unsigned int offset, int value)
> > {
> > struct gpio_sim_chip *chip = gpiochip_get_data(gc);
> >
> > - mutex_lock(&chip->lock);
> > - __assign_bit(offset, chip->value_map, value);
> > - mutex_unlock(&chip->lock);
> > + scoped_guard(mutex, &chip->lock)
> > + __assign_bit(offset, chip->value_map, value);
>
> But this can also be guarded.
>
> guard(mutex)(&chip->lock);
>
> __assign_bit(offset, chip->value_map, value);
>
Come on, this is total bikeshedding! I could produce ten arguments in
favor of the scoped variant.
Linus acked even the previous version and Peter says it looks right. I
will queue it unless some *real* issues come up.
> > }
>
> ...
>
> > {
> > struct gpio_sim_chip *chip = gpiochip_get_data(gc);
> >
> > - mutex_lock(&chip->lock);
> > - bitmap_replace(chip->value_map, chip->value_map, bits, mask, gc->ngpio);
> > - mutex_unlock(&chip->lock);
> > + scoped_guard(mutex, &chip->lock)
> > + bitmap_replace(chip->value_map, chip->value_map, bits, mask,
> > + gc->ngpio);
>
> Ditto.
>
> guard(mutex)(&chip->lock);
>
> bitmap_replace(chip->value_map, chip->value_map, bits, mask, gc->ngpio);
>
> (exactly 80 for the sectants of 80 characters :).
>
> > }
>
> ...
>
> > {
> > struct gpio_sim_chip *chip = gpiochip_get_data(gc);
> >
> > - mutex_lock(&chip->lock);
> > - __assign_bit(offset, chip->value_map, !!test_bit(offset, chip->pull_map));
> > - mutex_unlock(&chip->lock);
> > + scoped_guard(mutex, &chip->lock)
> > + __assign_bit(offset, chip->value_map,
> > + !!test_bit(offset, chip->pull_map));
>
> Ditto.
>
> guard(mutex)(&chip->lock);
>
> __assign_bit(offset, chip->value_map, test_bit(offset, chip->pull_map));
>
> (in this form fanatics of 80 can sleep well :-)
>
> Note that !! is redundant as test_bit() family of functions were fixed to
> return boolean.
Ha! TIL... I'll change it in a separate patch.
Bart
>
> > }
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
Powered by blists - more mailing lists