[PATCH] gpiolib: Warn if a single GPIO is expected but a list is found

Richard Weinberger posted 1 patch 1 week ago
drivers/gpio/gpiolib.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] gpiolib: Warn if a single GPIO is expected but a list is found
Posted by Richard Weinberger 1 week ago
Device tree properties such as reset-gpios can contain one or more
GPIOs but the vast majority of device drivers query only for a single
GPIO desc.
Add some aid to detect the case when someone defines multiple GPIOs
but a driver expected only one.
This would have saved me an hour today.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/gpio/gpiolib.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index cd8800ba5825f..d57d83cc4074e 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4601,6 +4601,10 @@ static struct gpio_desc *gpiod_find_by_fwnode(struct fwnode_handle *fwnode,
 	const char *name = function_name_or_default(con_id);
 	struct gpio_desc *desc = ERR_PTR(-ENOENT);
 
+	if (gpiod_count(consumer, con_id) > 1)
+		dev_warn(consumer, "gpio property \"%s\" in %pfw has more than one elements, expected only one!\n",
+			 con_id, fwnode);
+
 	if (is_of_node(fwnode)) {
 		dev_dbg(consumer, "using DT '%pfw' for '%s' GPIO lookup\n", fwnode, name);
 		desc = of_find_gpio(to_of_node(fwnode), con_id, idx, lookupflags);
-- 
2.51.0