[PATCH v2 2/3] gpiolib: Simplify implementation of for_each_hwgpio_in_range()

From: Andy Shevchenko
Date: Fri Feb 07 2025 - 10:12:31 EST


The whole purpose of the custom CLASS() is to have possibility
to initialise the counter variable _i to 0. This can't be done
with simple __free() macro as it will be not allowed by C language.
OTOH, the CLASS() operates with the pointers and explicit usage of
the scoped variable _data is not needed, since the pointers are kept
the same over the iterations. Simplify the implementation of
for_each_hwgpio_in_range().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
include/linux/gpio/driver.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 024112ef5a78..ae93f75170f2 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -559,11 +559,9 @@ DEFINE_CLASS(_gpiochip_for_each_data,
*/
#define for_each_hwgpio_in_range(_chip, _i, _base, _size, _label) \
for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \
- *_data.i < _size; \
- (*_data.i)++, kfree(*(_data.label)), *_data.label = NULL) \
- if (IS_ERR(*_data.label = \
- gpiochip_dup_line_label(_chip, _base + *_data.i))) {} \
- else
+ _i < _size; \
+ _i++, kfree(_label), _label = NULL) \
+ if (IS_ERR(_label = gpiochip_dup_line_label(_chip, _base + _i))) {} else

/**
* for_each_hwgpio - Iterates over all GPIOs for given chip.
--
2.43.0.rc1.1336.g36b5255a03ac