iio: amplifier: hmc425a: simplify using devm_regulator_get_enable()
authorMatti Vaittinen <mazziesaccount@gmail.com>
Fri, 19 Aug 2022 19:21:02 +0000 (22:21 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 23 Nov 2022 19:44:01 +0000 (19:44 +0000)
Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(),
add_action_or_reset(regulator_disable)' and use the
devm_regulator_get_enable() and drop the pointer to the regulator.
This simplifies code and makes it less tempting to add manual control
for the regulator which is also controlled by devm.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Acked-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/8b1193fdefb231a6d721e2bded52c48e56039c20.1660934107.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/amplifiers/hmc425a.c

index ce80e0c916f4a0db8c8704733bf58188c66857e7..108f0f1685ef1661f9ac6edbadb715d20f8bbc8e 100644 (file)
@@ -34,7 +34,6 @@ struct hmc425a_chip_info {
 };
 
 struct hmc425a_state {
-       struct  regulator *reg;
        struct  mutex lock; /* protect sensor state */
        struct  hmc425a_chip_info *chip_info;
        struct  gpio_descs *gpios;
@@ -162,13 +161,6 @@ static const struct of_device_id hmc425a_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, hmc425a_of_match);
 
-static void hmc425a_reg_disable(void *data)
-{
-       struct hmc425a_state *st = data;
-
-       regulator_disable(st->reg);
-}
-
 static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = {
        [ID_HMC425A] = {
                .name = "hmc425a",
@@ -211,14 +203,7 @@ static int hmc425a_probe(struct platform_device *pdev)
                return -ENODEV;
        }
 
-       st->reg = devm_regulator_get(&pdev->dev, "vcc-supply");
-       if (IS_ERR(st->reg))
-               return PTR_ERR(st->reg);
-
-       ret = regulator_enable(st->reg);
-       if (ret)
-               return ret;
-       ret = devm_add_action_or_reset(&pdev->dev, hmc425a_reg_disable, st);
+       ret = devm_regulator_get_enable(&pdev->dev, "vcc-supply");
        if (ret)
                return ret;