* [PATCH] gnss: ubx: Use devm_regulator_get_enable_optional()
@ 2023-06-17 10:01 Christophe JAILLET
2023-06-20 8:59 ` Johan Hovold
0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2023-06-17 10:01 UTC (permalink / raw)
To: Johan Hovold, Liam Girdwood, Mark Brown
Cc: linux-kernel, kernel-janitors, Christophe JAILLET
Use devm_regulator_get_enable_optional() instead of hand writing it. It
saves some line of code.
Signed-off-by: Christophe JAILLET <christophe.jaillet@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/ubx.c | 26 ++++----------------------
1 file changed, 4 insertions(+), 22 deletions(-)
diff --git a/drivers/gnss/ubx.c b/drivers/gnss/ubx.c
index c951be202ca2..0ad2a10fc9a2 100644
--- a/drivers/gnss/ubx.c
+++ b/drivers/gnss/ubx.c
@@ -17,7 +17,6 @@
#include "serial.h"
struct ubx_data {
- struct regulator *v_bckp;
struct regulator *vcc;
};
@@ -87,30 +86,16 @@ static int ubx_probe(struct serdev_device *serdev)
goto err_free_gserial;
}
- data->v_bckp = devm_regulator_get_optional(&serdev->dev, "v-bckp");
- if (IS_ERR(data->v_bckp)) {
- ret = PTR_ERR(data->v_bckp);
- if (ret == -ENODEV)
- data->v_bckp = NULL;
- else
- goto err_free_gserial;
- }
-
- if (data->v_bckp) {
- ret = regulator_enable(data->v_bckp);
- if (ret)
- goto err_free_gserial;
- }
+ ret = devm_regulator_get_enable_optional(&serdev->dev, "v-bckp");
+ if (ret)
+ goto err_free_gserial;
ret = gnss_serial_register(gserial);
if (ret)
- goto err_disable_v_bckp;
+ goto err_free_gserial;
return 0;
-err_disable_v_bckp:
- if (data->v_bckp)
- regulator_disable(data->v_bckp);
err_free_gserial:
gnss_serial_free(gserial);
@@ -120,11 +105,8 @@ static int ubx_probe(struct serdev_device *serdev)
static void ubx_remove(struct serdev_device *serdev)
{
struct gnss_serial *gserial = serdev_device_get_drvdata(serdev);
- struct ubx_data *data = gnss_serial_get_drvdata(gserial);
gnss_serial_deregister(gserial);
- if (data->v_bckp)
- regulator_disable(data->v_bckp);
gnss_serial_free(gserial);
}
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gnss: ubx: Use devm_regulator_get_enable_optional()
2023-06-17 10:01 [PATCH] gnss: ubx: Use devm_regulator_get_enable_optional() Christophe JAILLET
@ 2023-06-20 8:59 ` Johan Hovold
0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2023-06-20 8:59 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Liam Girdwood, Mark Brown, linux-kernel, kernel-janitors
On Sat, Jun 17, 2023 at 12:01:22PM +0200, Christophe JAILLET wrote:
> Use devm_regulator_get_enable_optional() instead of hand writing it. It
> saves some line of code.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> - data->v_bckp = devm_regulator_get_optional(&serdev->dev, "v-bckp");
> - if (IS_ERR(data->v_bckp)) {
> - ret = PTR_ERR(data->v_bckp);
> - if (ret == -ENODEV)
> - data->v_bckp = NULL;
> - else
> - goto err_free_gserial;
> - }
> -
> - if (data->v_bckp) {
> - ret = regulator_enable(data->v_bckp);
> - if (ret)
> - goto err_free_gserial;
> - }
> + ret = devm_regulator_get_enable_optional(&serdev->dev, "v-bckp");
> + if (ret)
> + goto err_free_gserial;
Same here, this breaks the driver as -ENODEV is returned when the
optional resource is not present.
Johan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-20 8:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-17 10:01 [PATCH] gnss: ubx: Use devm_regulator_get_enable_optional() Christophe JAILLET
2023-06-20 8:59 ` Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®