[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZNtT37d3eR6FcQyR@smile.fi.intel.com>
Date: Tue, 15 Aug 2023 13:30:55 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Bartosz Golaszewski <brgl@...ev.pl>
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 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);
> }
...
> {
> 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.
> }
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists