From: Linus Walleij Date: Mon, 27 Apr 2026 08:47:57 +0000 (+0200) Subject: gpio: devres: Use devres parent if undefined X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=575d985581e9ef7a175b61d63c824e5dd1d47987;p=thirdparty%2Fkernel%2Flinux.git gpio: devres: Use devres parent if undefined 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 Link: https://patch.msgid.link/20260427-gpio-mmio-more-v3-1-fe1882351424@kernel.org Signed-off-by: Bartosz Golaszewski --- diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c index 72422c5db3641..2ec825ffab7da 100644 --- a/drivers/gpio/gpiolib-devres.c +++ b/drivers/gpio/gpiolib-devres.c @@ -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;