Skip to content

Commit 5c887b6

Browse files
andy-shevBartosz Golaszewski
authored andcommitted
gpiolib: Fix debug messaging in gpiod_find_and_request()
When consolidating GPIO lookups in ACPI code, the debug messaging had been reworked that the user may see [ 13.401147] (NULL device *): using ACPI '\_SB.LEDS.led-0' for '(null)' GPIO lookup [ 13.401378] gpio gpiochip0: Persistence not supported for GPIO 40 [ 13.401402] gpio-40 (?): no flags found for (null) instead of [ 14.182962] gpio gpiochip0: Persistence not supported for GPIO 40 [ 14.182994] gpio-40 (?): no flags found for gpios The '(null)' parts are less informative and likely scare the users. Replace them by '(default)' which can point out to the default connection IDs, such as 'gpios'. While at it, amend other places where con_id is used in the messages. Reported-by: Ferry Toth <[email protected]> Fixes: 8eb1f71 ("gpiolib: consolidate GPIO lookups") Suggested-by: Dmitry Torokhov <[email protected]> Tested-by: Ferry Toth <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 52464f5 commit 5c887b6

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

drivers/gpio/gpiolib.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,11 @@ char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset)
23972397
}
23982398
EXPORT_SYMBOL_GPL(gpiochip_dup_line_label);
23992399

2400+
static inline const char *function_name_or_default(const char *con_id)
2401+
{
2402+
return con_id ?: "(default)";
2403+
}
2404+
24002405
/**
24012406
* gpiochip_request_own_desc - Allow GPIO chip to request its own descriptor
24022407
* @gc: GPIO chip
@@ -2425,10 +2430,11 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc,
24252430
enum gpiod_flags dflags)
24262431
{
24272432
struct gpio_desc *desc = gpiochip_get_desc(gc, hwnum);
2433+
const char *name = function_name_or_default(label);
24282434
int ret;
24292435

24302436
if (IS_ERR(desc)) {
2431-
chip_err(gc, "failed to get GPIO descriptor\n");
2437+
chip_err(gc, "failed to get GPIO %s descriptor\n", name);
24322438
return desc;
24332439
}
24342440

@@ -2438,8 +2444,8 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc,
24382444

24392445
ret = gpiod_configure_flags(desc, label, lflags, dflags);
24402446
if (ret) {
2441-
chip_err(gc, "setup of own GPIO %s failed\n", label);
24422447
gpiod_free_commit(desc);
2448+
chip_err(gc, "setup of own GPIO %s failed\n", name);
24432449
return ERR_PTR(ret);
24442450
}
24452451

@@ -4153,19 +4159,17 @@ static struct gpio_desc *gpiod_find_by_fwnode(struct fwnode_handle *fwnode,
41534159
enum gpiod_flags *flags,
41544160
unsigned long *lookupflags)
41554161
{
4162+
const char *name = function_name_or_default(con_id);
41564163
struct gpio_desc *desc = ERR_PTR(-ENOENT);
41574164

41584165
if (is_of_node(fwnode)) {
4159-
dev_dbg(consumer, "using DT '%pfw' for '%s' GPIO lookup\n",
4160-
fwnode, con_id);
4166+
dev_dbg(consumer, "using DT '%pfw' for '%s' GPIO lookup\n", fwnode, name);
41614167
desc = of_find_gpio(to_of_node(fwnode), con_id, idx, lookupflags);
41624168
} else if (is_acpi_node(fwnode)) {
4163-
dev_dbg(consumer, "using ACPI '%pfw' for '%s' GPIO lookup\n",
4164-
fwnode, con_id);
4169+
dev_dbg(consumer, "using ACPI '%pfw' for '%s' GPIO lookup\n", fwnode, name);
41654170
desc = acpi_find_gpio(fwnode, con_id, idx, flags, lookupflags);
41664171
} else if (is_software_node(fwnode)) {
4167-
dev_dbg(consumer, "using swnode '%pfw' for '%s' GPIO lookup\n",
4168-
fwnode, con_id);
4172+
dev_dbg(consumer, "using swnode '%pfw' for '%s' GPIO lookup\n", fwnode, name);
41694173
desc = swnode_find_gpio(fwnode, con_id, idx, lookupflags);
41704174
}
41714175

@@ -4181,6 +4185,7 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer,
41814185
bool platform_lookup_allowed)
41824186
{
41834187
unsigned long lookupflags = GPIO_LOOKUP_FLAGS_DEFAULT;
4188+
const char *name = function_name_or_default(con_id);
41844189
/*
41854190
* scoped_guard() is implemented as a for loop, meaning static
41864191
* analyzers will complain about these two not being initialized.
@@ -4203,8 +4208,7 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer,
42034208
}
42044209

42054210
if (IS_ERR(desc)) {
4206-
dev_dbg(consumer, "No GPIO consumer %s found\n",
4207-
con_id);
4211+
dev_dbg(consumer, "No GPIO consumer %s found\n", name);
42084212
return desc;
42094213
}
42104214

@@ -4226,15 +4230,14 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer,
42264230
*
42274231
* FIXME: Make this more sane and safe.
42284232
*/
4229-
dev_info(consumer,
4230-
"nonexclusive access to GPIO for %s\n", con_id);
4233+
dev_info(consumer, "nonexclusive access to GPIO for %s\n", name);
42314234
return desc;
42324235
}
42334236

42344237
ret = gpiod_configure_flags(desc, con_id, lookupflags, flags);
42354238
if (ret < 0) {
4236-
dev_dbg(consumer, "setup of GPIO %s failed\n", con_id);
42374239
gpiod_put(desc);
4240+
dev_dbg(consumer, "setup of GPIO %s failed\n", name);
42384241
return ERR_PTR(ret);
42394242
}
42404243

@@ -4350,6 +4353,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_optional);
43504353
int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
43514354
unsigned long lflags, enum gpiod_flags dflags)
43524355
{
4356+
const char *name = function_name_or_default(con_id);
43534357
int ret;
43544358

43554359
if (lflags & GPIO_ACTIVE_LOW)
@@ -4393,7 +4397,7 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
43934397

43944398
/* No particular flag request, return here... */
43954399
if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) {
4396-
gpiod_dbg(desc, "no flags found for %s\n", con_id);
4400+
gpiod_dbg(desc, "no flags found for GPIO %s\n", name);
43974401
return 0;
43984402
}
43994403

0 commit comments

Comments
 (0)