Skip to content

Commit

Permalink
leds: ktd2692: Fix an error handling path
Browse files Browse the repository at this point in the history
[ Upstream commit ee78b93 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
tititiou36 authored and gregkh committed Jul 14, 2021
1 parent 2f0b82e commit 5b2499e
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions drivers/leds/leds-ktd2692.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5b2499e

Please sign in to comment.