gpio: rework debug macros
cover gpio: rework debug macros
Rename the chip_$level() macros to gpiochip_$level() and reuse some code in macro definitions.
No functional change.
---
Bartosz Golaszewski (4):
gpiolib: remove unnecessary 'out of memory' messages
gpiolib: rename GPIO chip printk macros
gpiolib: reuse macro code in GPIO descriptor printk helpers
gpiolib: reuse macro code in GPIO chip printk helpers
drivers/gpio/gpiolib-cdev.c | 2 +- drivers/gpio/gpiolib-sysfs.c | 2 +- drivers/gpio/gpiolib.c | 88 +++++++++++++++++++++----------------------- drivers/gpio/gpiolib.h | 41 ++++++++------------- 4 files changed, 58 insertions(+), 75 deletions(-)
---
base-commit: 846bd2225ec3cfa8be046655e02b9457ed41973e
change-id: 20250922-gpio-debug-macros-d37201504cdf
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
PATCH 1/4 gpiolib: remove unnecessary 'out of memory' messages
From: Bartosz Golaszewski <[email protected]>
We don't need to add additional logs when returning -ENOMEM so remove unnecessary error messages.
--- drivers/gpio/gpiolib.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib.c +2 -6
@@ -2316,10 +2316,8 @@ int gpiochip_add_pingroup_range(struct gpio_chip *gc,int ret; pin_range =kzalloc (sizeof (*pin_range),GFP_KERNEL ); -if (!pin_range) { -chip_err (gc,"failed to allocate pin ranges\n" ); +if (!pin_range)return -ENOMEM ; - }/* Use local offset as range ID */ pin_range->range.id = gpio_offset;
@@ -2379,10 +2377,8 @@ int gpiochip_add_pin_range_with_pins(struct gpio_chip *gc,int ret; pin_range =kzalloc (sizeof (*pin_range),GFP_KERNEL ); -if (!pin_range) { -chip_err (gc,"failed to allocate pin ranges\n" ); +if (!pin_range)return -ENOMEM ; - }/* Use local offset as range ID */ pin_range->range.id = gpio_offset;
Signature · 1 line
2.48.1
PATCH 2/4 gpiolib: rename GPIO chip printk macros
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
The chip_$level() macros take struct gpio_chip as argument so make it follow the convention of using the 'gpiochip_' prefix.
--- drivers/gpio/gpiolib-cdev.c | 2 +- drivers/gpio/gpiolib-sysfs.c | 2 +- drivers/gpio/gpiolib.c | 80 +++++++++++++++++++++----------------------- drivers/gpio/gpiolib.h | 8 ++--- 4 files changed, 45 insertions(+), 47 deletions(-)
drivers/gpio/gpiolib-cdev.c +1 -1
@@ -2823,7 +2823,7 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)if (!gc)return -ENODEV ; -chip_dbg (gc,"added GPIO chardev (%d:%d)\n" ,MAJOR (devt), gdev->id); +gpiochip_dbg (gc,"added GPIO chardev (%d:%d)\n" ,MAJOR (devt), gdev->id);return 0 ; }
drivers/gpio/gpiolib-sysfs.c +1 -1
@@ -1091,7 +1091,7 @@ static int gpiofind_sysfs_register(struct gpio_chip *gc, const void *data) ret =gpiochip_sysfs_register (gdev);if (ret) -chip_err (gc,"failed to register the sysfs entry: %d\n" , ret); +gpiochip_err (gc,"failed to register the sysfs entry: %d\n" , ret);return 0 ; }
drivers/gpio/gpiolib.c +39 -41
209 lines not on this page · raw message
drivers/gpio/gpiolib.h +4 -4
@@ -309,13 +309,13 @@ do { \/* With chip prefix */ -#define chip_err (gc, fmt, ...) \ +#define gpiochip_err (gc, fmt, ...) \ dev_err(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) -#define chip_warn (gc, fmt, ...) \ +#define gpiochip_warn (gc, fmt, ...) \ dev_warn(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) -#define chip_info (gc, fmt, ...) \ +#define gpiochip_info (gc, fmt, ...) \ dev_info(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) -#define chip_dbg (gc, fmt, ...) \ +#define gpiochip_dbg (gc, fmt, ...) \ dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)#endif /* GPIOLIB_H */
Signature · 1 line
2.48.1
PATCH 3/4 gpiolib: reuse macro code in GPIO descriptor printk helpers
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
A lot of code in gpiod_$level() macros is duplicated across all definitions. Create an intermediate macro which allows us to reuse the low-level code.
--- drivers/gpio/gpiolib.h | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)
drivers/gpio/gpiolib.h +6 -18
@@ -283,29 +283,17 @@ static inline int gpio_chip_hwgpio(const struct gpio_desc *desc)/* With descriptor prefix */ -#define gpiod_err (desc, fmt, ...) \ +#define __gpiod_pr (level, desc, fmt, ...) \ do { \ scoped_guard(srcu, &desc->gdev->desc_srcu) { \ - pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ - gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \ + pr_##level("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ + gpiod_get_label(desc) ?: "?", ##__VA_ARGS__); \ } \ } while (0) -#define gpiod_warn (desc, fmt, ...) \ -do { \ - scoped_guard(srcu, &desc->gdev->desc_srcu) { \ - pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ - gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \ - } \ -} while (0) - -#define gpiod_dbg (desc, fmt, ...) \ -do { \ - scoped_guard(srcu, &desc->gdev->desc_srcu) { \ - pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ - gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \ - } \ -} while (0) +#define gpiod_err (desc, fmt, ...) __gpiod_pr(err, desc, fmt, ##__VA_ARGS__) +#define gpiod_warn (desc, fmt, ...) __gpiod_pr(warn, desc, fmt, ##__VA_ARGS__) +#define gpiod_dbg (desc, fmt, ...) __gpiod_pr(debug, desc, fmt, ##__VA_ARGS__)/* With chip prefix */
Signature · 1 line
2.48.1
PATCH 4/4 gpiolib: reuse macro code in GPIO chip printk helpers
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
The arguments passed to dev_$level() macros are duplicated across the gpiochip_$level() macros so put them under an intermediate wrapper. While at it: wrap it in a do-while guard.
--- drivers/gpio/gpiolib.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpio/gpiolib.h +9 -8
@@ -297,13 +297,14 @@ do { \/* With chip prefix */ -#define gpiochip_err (gc, fmt, ...) \ - dev_err(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) -#define gpiochip_warn (gc, fmt, ...) \ - dev_warn(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) -#define gpiochip_info (gc, fmt, ...) \ - dev_info(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) -#define gpiochip_dbg (gc, fmt, ...) \ - dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) +#define __gpiochip_pr (level, gc, fmt, ...) \ +do { \ + dev_##level(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__); \ +} while (0) + +#define gpiochip_err (gc, fmt, ...) __gpiochip_pr(err, gc, fmt, ##__VA_ARGS__) +#define gpiochip_warn (gc, fmt, ...) __gpiochip_pr(warn, gc, fmt, ##__VA_ARGS__) +#define gpiochip_info (gc, fmt, ...) __gpiochip_pr(info, gc, fmt, ##__VA_ARGS__) +#define gpiochip_dbg (gc, fmt, ...) __gpiochip_pr(dbg, gc, fmt, ##__VA_ARGS__)#endif /* GPIOLIB_H */
Signature · 1 line
2.48.1
Quoted 6 lines · Bartosz Golaszewski
Rename the chip_$level() macros to gpiochip_$level() and reuse some code in macro definitions.
No functional change.
Signed-off-by Bartosz Golaszewski <[email protected]>
This LGTM!
Yours,
Linus Walleij
Bartosz Golaszewski
AppliedFrom: Bartosz Golaszewski <[email protected]>
Quoted 6 lines · Bartosz Golaszewski
Rename the chip_$level() macros to gpiochip_$level() and reuse some code in macro definitions.
No functional change.
Applied, thanks!
[1/4] gpiolib: remove unnecessary 'out of memory' messages
https://git.kernel.org/brgl/linux/c/0ba6f1ed3808b1f095fbdb490006f0ecd00f52bd [2/4] gpiolib: rename GPIO chip printk macros https://git.kernel.org/brgl/linux/c/d4f335b410ddbe3e99f48f8b5ea78a25041274f1 [3/4] gpiolib: reuse macro code in GPIO descriptor printk helpers https://git.kernel.org/brgl/linux/c/3f0be1783a8ff57f77e6f9a12621903b5a496d40 [4/4] gpiolib: reuse macro code in GPIO chip printk helpers https://git.kernel.org/brgl/linux/c/1540b799d271b545bf04726906184bdf29ab272b
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>