mbox series

[v2,0/3] gpiolib: refactor for_each_hwgpio()

Message ID 20250207151149.2119765-1-andriy.shevchenko@linux.intel.com
Headers show
Series gpiolib: refactor for_each_hwgpio() | expand

Message

Andy Shevchenko Feb. 7, 2025, 3:07 p.m. UTC
Some of the for_each_*() macros use the very similar piece of code
that may be deduplicated (by introducing a new helper macro in patch 1).
On top of that the implementation of the low-level for_each_hwgpio_in_range()
looks too verbose. Try to simplify it (patches 2 and 3).

Changelog v2:
- added kernel-doc for a new helper (Bart)
- added two more patches

Andy Shevchenko (3):
  gpiolib: Deduplicate some code in for_each_requested_gpio_in_range()
  gpiolib: Simplify implementation of for_each_hwgpio_in_range()
  gpiolib: Switch to use for_each_if() helper

 include/linux/gpio/driver.h | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

Comments

Bartosz Golaszewski Feb. 12, 2025, 1:41 p.m. UTC | #1
On Fri, Feb 7, 2025 at 4:11 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> The for_each_*() APIs that are conditional can be written shorter and
> less error prone with for_each_if() helper in use. Switch them to use
> this helper.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  include/linux/gpio/driver.h | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
> index ae93f75170f2..a7e9c1d3df71 100644
> --- a/include/linux/gpio/driver.h
> +++ b/include/linux/gpio/driver.h
> @@ -532,6 +532,7 @@ struct gpio_chip {
>
>  char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset);
>
> +#define for_each_if(condition) if (!(condition)) {} else

This is already defined in drm/drm_util.h. Please move it out of there
and make it available globally instead of duplicating.

Bart
Bartosz Golaszewski Feb. 12, 2025, 2:21 p.m. UTC | #2
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Fri, 07 Feb 2025 17:07:33 +0200, Andy Shevchenko wrote:
> Some of the for_each_*() macros use the very similar piece of code
> that may be deduplicated (by introducing a new helper macro in patch 1).
> On top of that the implementation of the low-level for_each_hwgpio_in_range()
> looks too verbose. Try to simplify it (patches 2 and 3).
> 
> Changelog v2:
> - added kernel-doc for a new helper (Bart)
> - added two more patches
> 
> [...]

I applied patches 1 and 2. Please revisit 3/3 in order to not duplicate
the for_each_if() macro.

[1/3] gpiolib: Deduplicate some code in for_each_requested_gpio_in_range()
      commit: 8893516000b247f91fa2cef34f2a77b609e661a4
[2/3] gpiolib: Simplify implementation of for_each_hwgpio_in_range()
      commit: 767412f092fc6e04147305acd70f15770ece47ec

Best regards,