linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: ktd2692: Fix an error handling path
@ 2021-05-21 11:21 Christophe JAILLET
  2021-06-23 20:26 ` Pavel Machek
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2021-05-21 11:21 UTC (permalink / raw)
  To: pavel, j.anaszewski, sw0312.kim, ingi2.kim, varkabhadram, cooloney
  Cc: linux-leds, linux-kernel, kernel-janitors, Christophe JAILLET

In 'ktd2692_parse_dt()', if an error occurs after a successful
'regulator_enable()' call, we should call 'regulator_enable()'.

This is the same in 'ktd2692_probe()', if an error occurs after a
successful 'ktd2692_parse_dt()' call.

Instead of adding 'regulator_enable()' in several places, implement a
resource managed solution and simplify the remove function accordingly.

Fixes: b7da8c5c725c ("leds: Add ktd2692 flash LED driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only.
The regulator looks optional, so maybe 'devm_add_action()' without a
'return ret;' would be more logical that 'devm_add_action_or_reset()'.
The code could be simpler if we don't car about the message if
'regulator_disable()' fails.
---
 drivers/leds/leds-ktd2692.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/leds/leds-ktd2692.c b/drivers/leds/leds-ktd2692.c
index 632f10db4b3f..f341da1503a4 100644
--- a/drivers/leds/leds-ktd2692.c
+++ b/drivers/leds/leds-ktd2692.c
@@ -256,6 +256,17 @@ static void ktd2692_setup(struct ktd2692_context *led)
 				 | KTD2692_REG_FLASH_CURRENT_BASE);
 }
 
+static void regulator_disable_action(void *_data)
+{
+	struct device *dev = _data;
+	struct ktd2692_context *led = dev_get_drvdata(dev);
+	int ret;
+
+	ret = regulator_disable(led->regulator);
+	if (ret)
+		dev_err(dev, "Failed to disable supply: %d\n", ret);
+}
+
 static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
 			    struct ktd2692_led_config_data *cfg)
 {
@@ -286,8 +297,14 @@ static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
 
 	if (led->regulator) {
 		ret = regulator_enable(led->regulator);
-		if (ret)
+		if (ret) {
 			dev_err(dev, "Failed to enable supply: %d\n", ret);
+		} else {
+			ret = devm_add_action_or_reset(dev,
+						regulator_disable_action, dev);
+			if (ret)
+				return ret;
+		}
 	}
 
 	child_node = of_get_next_available_child(np, NULL);
@@ -377,17 +394,9 @@ static int ktd2692_probe(struct platform_device *pdev)
 static int ktd2692_remove(struct platform_device *pdev)
 {
 	struct ktd2692_context *led = platform_get_drvdata(pdev);
-	int ret;
 
 	led_classdev_flash_unregister(&led->fled_cdev);
 
-	if (led->regulator) {
-		ret = regulator_disable(led->regulator);
-		if (ret)
-			dev_err(&pdev->dev,
-				"Failed to disable supply: %d\n", ret);
-	}
-
 	mutex_destroy(&led->lock);
 
 	return 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] leds: ktd2692: Fix an error handling path
  2021-05-21 11:21 [PATCH] leds: ktd2692: Fix an error handling path Christophe JAILLET
@ 2021-06-23 20:26 ` Pavel Machek
  0 siblings, 0 replies; 2+ messages in thread
From: Pavel Machek @ 2021-06-23 20:26 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: j.anaszewski, sw0312.kim, ingi2.kim, varkabhadram, cooloney,
	linux-leds, linux-kernel, kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 680 bytes --]

On Fri 2021-05-21 13:21:01, Christophe JAILLET wrote:
> In 'ktd2692_parse_dt()', if an error occurs after a successful
> 'regulator_enable()' call, we should call 'regulator_enable()'.
> 
> This is the same in 'ktd2692_probe()', if an error occurs after a
> successful 'ktd2692_parse_dt()' call.
> 
> Instead of adding 'regulator_enable()' in several places, implement a
> resource managed solution and simplify the remove function accordingly.
> 
> Fixes: b7da8c5c725c ("leds: Add ktd2692 flash LED driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Thanks, applied.
								Pavel
								
-- 
http://www.livejournal.com/~pavelmachek

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-23 20:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 11:21 [PATCH] leds: ktd2692: Fix an error handling path Christophe JAILLET
2021-06-23 20:26 ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).