Skip to content

Commit ee78b93

Browse files
tititiou36pavelmachek
authored andcommitted
leds: ktd2692: Fix an error handling path
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: b7da8c5 ("leds: Add ktd2692 flash LED driver") Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Signed-off-by: Pavel Machek <pavel@ucw.cz>
1 parent 96a3096 commit ee78b93

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎drivers/leds/leds-ktd2692.c‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ static void ktd2692_setup(struct ktd2692_context *led)
256256
| KTD2692_REG_FLASH_CURRENT_BASE);
257257
}
258258

259+
static void regulator_disable_action(void *_data)
260+
{
261+
struct device *dev = _data;
262+
struct ktd2692_context *led = dev_get_drvdata(dev);
263+
int ret;
264+
265+
ret = regulator_disable(led->regulator);
266+
if (ret)
267+
dev_err(dev, "Failed to disable supply: %d\n", ret);
268+
}
269+
259270
static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
260271
struct ktd2692_led_config_data *cfg)
261272
{
@@ -286,8 +297,14 @@ static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
286297

287298
if (led->regulator) {
288299
ret = regulator_enable(led->regulator);
289-
if (ret)
300+
if (ret) {
290301
dev_err(dev, "Failed to enable supply: %d\n", ret);
302+
} else {
303+
ret = devm_add_action_or_reset(dev,
304+
regulator_disable_action, dev);
305+
if (ret)
306+
return ret;
307+
}
291308
}
292309

293310
child_node = of_get_next_available_child(np, NULL);
@@ -377,17 +394,9 @@ static int ktd2692_probe(struct platform_device *pdev)
377394
static int ktd2692_remove(struct platform_device *pdev)
378395
{
379396
struct ktd2692_context *led = platform_get_drvdata(pdev);
380-
int ret;
381397

382398
led_classdev_flash_unregister(&led->fled_cdev);
383399

384-
if (led->regulator) {
385-
ret = regulator_disable(led->regulator);
386-
if (ret)
387-
dev_err(&pdev->dev,
388-
"Failed to disable supply: %d\n", ret);
389-
}
390-
391400
mutex_destroy(&led->lock);
392401

393402
return 0;

0 commit comments

Comments
 (0)