Hi Pranav,
On 2026-07-09T14:28:59, Pranav Sanwal <[email protected]> wrote:
> gpio: uclass: warn when a gpio offset is already claimed
>
> dm_gpio_request() returns -EBUSY when the requested offset is
> already claimed, but gives no indication of which label is holding
> it, making an offset collision opaque to debug.
>
> Add a dev_warn() printing the label already holding the offset
> alongside the newly requested label.
>
> Signed-off-by: Pranav Sanwal <[email protected]>
>
> drivers/gpio/gpio-uclass.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
> diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
> @@ -397,8 +397,12 @@ int dm_gpio_request(struct gpio_desc *desc, const char
> *label)
> uc_priv = dev_get_uclass_priv(dev);
> - if (gpio_is_claimed(uc_priv, desc->offset))
> + if (gpio_is_claimed(uc_priv, desc->offset)) {
> + dev_warn(dev, "gpio offset %u already claimed by '%s',
> requested label '%s'\n",
> + desc->offset, uc_priv->name[desc->offset], label);
> return -EBUSY;
> + }
The -EBUSY return from dm_gpio_request() is a normal, expected
condition for some callers, not just an error to be diagnosed. For
example, cmd/gpio.c deliberately tolerates it:
ret = gpio_request(gpio, "cmd_gpio");
if (ret && ret != -EBUSY) {
so with this patch every 'gpio set' or 'gpio toggle' on a pin already
claimed by a driver or hog prints a warning for a legitimate
operation. The sandbox tests also trigger this path on purpose
(dm_test_gpio_phandles and dm_test_gpio_devm expect -EBUSY), so test
runs will emit these warnings too.
We don't really want drivers to print warnings unless something is
actually wrong with the device.
Could this go into the gpio command instead?
Regards,
Simon