From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Kent Gibson <warthog618@gmail.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH v3] gpio: sim: simplify code with cleanup helpers
Date: Tue, 15 Aug 2023 13:30:55 +0300 [thread overview]
Message-ID: <ZNtT37d3eR6FcQyR@smile.fi.intel.com> (raw)
In-Reply-To: <20230812183635.5478-1-brgl@bgdev.pl>
On Sat, Aug 12, 2023 at 08:36:35PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.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
next prev parent reply other threads:[~2023-08-15 10:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-12 18:36 [PATCH v3] gpio: sim: simplify code with cleanup helpers Bartosz Golaszewski
2023-08-15 10:30 ` Andy Shevchenko [this message]
2023-08-15 19:09 ` Bartosz Golaszewski
2023-08-17 9:25 ` Andy Shevchenko
2023-08-17 12:15 ` Bartosz Golaszewski
2023-08-18 7:50 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZNtT37d3eR6FcQyR@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=warthog618@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox