Merge tag 'regulator-fix-v6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / drivers / regulator / core.c
index c661be129818c27c27b078df380aa9fe0961ad35..ae69e493913da2ec1782c8acf0f88386e407ed46 100644 (file)
@@ -5168,6 +5168,7 @@ static void regulator_dev_release(struct device *dev)
 {
        struct regulator_dev *rdev = dev_get_drvdata(dev);
 
+       debugfs_remove_recursive(rdev->debugfs);
        kfree(rdev->constraints);
        of_node_put(rdev->dev.of_node);
        kfree(rdev);
@@ -5659,11 +5660,15 @@ wash:
        mutex_lock(&regulator_list_mutex);
        regulator_ena_gpio_free(rdev);
        mutex_unlock(&regulator_list_mutex);
+       put_device(&rdev->dev);
+       rdev = NULL;
 clean:
        if (dangling_of_gpiod)
                gpiod_put(config->ena_gpiod);
+       if (rdev && rdev->dev.of_node)
+               of_node_put(rdev->dev.of_node);
+       kfree(rdev);
        kfree(config);
-       put_device(&rdev->dev);
 rinse:
        if (dangling_cfg_gpiod)
                gpiod_put(cfg->ena_gpiod);
@@ -5692,7 +5697,6 @@ void regulator_unregister(struct regulator_dev *rdev)
 
        mutex_lock(&regulator_list_mutex);
 
-       debugfs_remove_recursive(rdev->debugfs);
        WARN_ON(rdev->open_count);
        regulator_remove_coupling(rdev);
        unset_regulator_supplies(rdev);