[PATCH] gnss: Use devm_regulator_get_enable_optional()
Christophe JAILLET
christophe.jaillet at wanadoo.fr
Sat Jun 17 02:57:09 PDT 2023
Use devm_regulator_get_enable_optional() instead of hand writing it. It
saves some line of code.
Signed-off-by: Christophe JAILLET <christophe.jaillet at wanadoo.fr>
---
Note that regulator_disable() is now called after gnss_serial_free() in
the error handling path of the probe and in the remove function, but it
looks harmless to me.
---
drivers/gnss/mtk.c | 26 ++++----------------------
1 file changed, 4 insertions(+), 22 deletions(-)
diff --git a/drivers/gnss/mtk.c b/drivers/gnss/mtk.c
index c62b1211f4fe..d3d31295d4e0 100644
--- a/drivers/gnss/mtk.c
+++ b/drivers/gnss/mtk.c
@@ -17,7 +17,6 @@
#include "serial.h"
struct mtk_data {
- struct regulator *vbackup;
struct regulator *vcc;
};
@@ -87,30 +86,16 @@ static int mtk_probe(struct serdev_device *serdev)
goto err_free_gserial;
}
- data->vbackup = devm_regulator_get_optional(&serdev->dev, "vbackup");
- if (IS_ERR(data->vbackup)) {
- ret = PTR_ERR(data->vbackup);
- if (ret == -ENODEV)
- data->vbackup = NULL;
- else
- goto err_free_gserial;
- }
-
- if (data->vbackup) {
- ret = regulator_enable(data->vbackup);
- if (ret)
- goto err_free_gserial;
- }
+ ret = devm_regulator_get_enable_optional(&serdev->dev, "vbackup");
+ if (ret)
+ goto err_free_gserial;
ret = gnss_serial_register(gserial);
if (ret)
- goto err_disable_vbackup;
+ goto err_free_gserial;
return 0;
-err_disable_vbackup:
- if (data->vbackup)
- regulator_disable(data->vbackup);
err_free_gserial:
gnss_serial_free(gserial);
@@ -120,11 +105,8 @@ static int mtk_probe(struct serdev_device *serdev)
static void mtk_remove(struct serdev_device *serdev)
{
struct gnss_serial *gserial = serdev_device_get_drvdata(serdev);
- struct mtk_data *data = gnss_serial_get_drvdata(gserial);
gnss_serial_deregister(gserial);
- if (data->vbackup)
- regulator_disable(data->vbackup);
gnss_serial_free(gserial);
}
--
2.34.1
More information about the linux-arm-kernel
mailing list