regulator: gpio: Convert to devm_regulator_register
authorAxel Lin <axel.lin@ingics.com>
Fri, 8 Mar 2019 06:15:28 +0000 (14:15 +0800)
committerMark Brown <broonie@kernel.org>
Wed, 13 Mar 2019 15:09:29 +0000 (15:09 +0000)
Use devm_regulator_register to simplify the code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/gpio-regulator.c

index 6157001df0a49f5d2753677b0a90ba57e3b759a0..967338bf1dc14f72f53337fbc88b4d44f0da8aa1 100644 (file)
@@ -36,7 +36,6 @@
 
 struct gpio_regulator_data {
        struct regulator_desc desc;
-       struct regulator_dev *dev;
 
        struct gpio_desc **gpiods;
        int nr_gpios;
@@ -233,6 +232,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
        struct device_node *np = dev->of_node;
        struct gpio_regulator_data *drvdata;
        struct regulator_config cfg = { };
+       struct regulator_dev *rdev;
        enum gpiod_flags gflags;
        int ptr, ret, state, i;
 
@@ -326,9 +326,9 @@ static int gpio_regulator_probe(struct platform_device *pdev)
        if (IS_ERR(cfg.ena_gpiod))
                return PTR_ERR(cfg.ena_gpiod);
 
-       drvdata->dev = regulator_register(&drvdata->desc, &cfg);
-       if (IS_ERR(drvdata->dev)) {
-               ret = PTR_ERR(drvdata->dev);
+       rdev = devm_regulator_register(dev, &drvdata->desc, &cfg);
+       if (IS_ERR(rdev)) {
+               ret = PTR_ERR(rdev);
                dev_err(dev, "Failed to register regulator: %d\n", ret);
                return ret;
        }
@@ -338,15 +338,6 @@ static int gpio_regulator_probe(struct platform_device *pdev)
        return 0;
 }
 
-static int gpio_regulator_remove(struct platform_device *pdev)
-{
-       struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev);
-
-       regulator_unregister(drvdata->dev);
-
-       return 0;
-}
-
 #if defined(CONFIG_OF)
 static const struct of_device_id regulator_gpio_of_match[] = {
        { .compatible = "regulator-gpio", },
@@ -357,7 +348,6 @@ MODULE_DEVICE_TABLE(of, regulator_gpio_of_match);
 
 static struct platform_driver gpio_regulator_driver = {
        .probe          = gpio_regulator_probe,
-       .remove         = gpio_regulator_remove,
        .driver         = {
                .name           = "gpio-regulator",
                .of_match_table = of_match_ptr(regulator_gpio_of_match),