]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpio: devres: Use devres parent if undefined
authorLinus Walleij <linus.walleij@linaro.org>
Mon, 27 Apr 2026 08:47:57 +0000 (10:47 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Mon, 4 May 2026 07:32:54 +0000 (09:32 +0200)
If the user did not pass a parent in the struct gpio_chip
then use the device used for devres as parent.

This is quite intuitive and can help avoiding having to
assign parent explicitly in every driver using devres
to add the gpiochip.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://patch.msgid.link/20260427-gpio-mmio-more-v3-1-fe1882351424@kernel.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpiolib-devres.c

index 72422c5db3641e5609759e82ac2ab532fab81783..2ec825ffab7da1fb877822e46bddff19c35bbad4 100644 (file)
@@ -353,6 +353,13 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, vo
 {
        int ret;
 
+       /*
+        * We are passing the devres device here so if the user did not pass
+        * another parent, it's this one.
+        */
+       if (!gc->parent)
+               gc->parent = dev;
+
        ret = gpiochip_add_data_with_key(gc, data, lock_key, request_key);
        if (ret < 0)
                return ret;