]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
reset: make the provider of reset-gpios the parent of the reset device
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 20 Nov 2025 13:24:02 +0000 (14:24 +0100)
committerPhilipp Zabel <p.zabel@pengutronix.de>
Thu, 20 Nov 2025 15:51:48 +0000 (16:51 +0100)
Auxiliary devices really do need a parent so ahead of converting the
reset-gpios driver to registering on the auxiliary bus, make the GPIO
device that provides the reset GPIO the parent of the reset-gpio device.
To that end move the lookup of the GPIO device by fwnode to the
beginning of __reset_add_reset_gpio_device() which has the added benefit
of bailing out earlier, before allocating resources for the virtual
device, if the chip is not up yet.

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
drivers/reset/core.c

index 5a696e2dbcc224a633e2b321da53b7bc699cb5f3..13236ab69f10ec80e19b982be2bee5e4b0f99388 100644 (file)
@@ -849,11 +849,11 @@ static void __reset_control_put_internal(struct reset_control *rstc)
        kref_put(&rstc->refcnt, __reset_control_release);
 }
 
-static int __reset_add_reset_gpio_lookup(int id, struct device_node *np,
+static int __reset_add_reset_gpio_lookup(struct gpio_device *gdev, int id,
+                                        struct device_node *np,
                                         unsigned int gpio,
                                         unsigned int of_flags)
 {
-       const struct fwnode_handle *fwnode = of_fwnode_handle(np);
        unsigned int lookup_flags;
        const char *label_tmp;
 
@@ -868,10 +868,6 @@ static int __reset_add_reset_gpio_lookup(int id, struct device_node *np,
                return -EINVAL;
        }
 
-       struct gpio_device *gdev __free(gpio_device_put) = gpio_device_find_by_fwnode(fwnode);
-       if (!gdev)
-               return -EPROBE_DEFER;
-
        label_tmp = gpio_device_get_label(gdev);
        if (!label_tmp)
                return -EINVAL;
@@ -926,6 +922,11 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
         */
        lockdep_assert_not_held(&reset_list_mutex);
 
+       struct gpio_device *gdev __free(gpio_device_put) =
+               gpio_device_find_by_fwnode(of_fwnode_handle(args->np));
+       if (!gdev)
+               return -EPROBE_DEFER;
+
        guard(mutex)(&reset_gpio_lookup_mutex);
 
        list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) {
@@ -946,7 +947,7 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
                goto err_ida_free;
        }
 
-       ret = __reset_add_reset_gpio_lookup(id, args->np, args->args[0],
+       ret = __reset_add_reset_gpio_lookup(gdev, id, args->np, args->args[0],
                                            args->args[1]);
        if (ret < 0)
                goto err_kfree;
@@ -958,7 +959,8 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
         * Hold reference as long as rgpio_dev memory is valid.
         */
        of_node_get(rgpio_dev->of_args.np);
-       pdev = platform_device_register_data(NULL, "reset-gpio", id,
+       pdev = platform_device_register_data(gpio_device_to_device(gdev),
+                                            "reset-gpio", id,
                                             &rgpio_dev->of_args,
                                             sizeof(rgpio_dev->of_args));
        ret = PTR_ERR_OR_ZERO(pdev);