Commit 3f0be178 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski
Browse files

gpiolib: reuse macro code in GPIO descriptor printk helpers



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.

Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
parent d4f335b4
Loading
Loading
Loading
Loading
+6 −18
Original line number Diff line number Diff line
@@ -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), \
		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 */