Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: b7da8c5c725c ("leds: Add ktd2692 flash LED driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Pavel Machek <pavel@ucw.cz>

authored by

Christophe JAILLET and committed by
Pavel Machek
ee78b936 96a30960

+18 -9
+18 -9
drivers/leds/leds-ktd2692.c
··· 256 256 | KTD2692_REG_FLASH_CURRENT_BASE); 257 257 } 258 258 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 + 259 270 static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev, 260 271 struct ktd2692_led_config_data *cfg) 261 272 { ··· 297 286 298 287 if (led->regulator) { 299 288 ret = regulator_enable(led->regulator); 300 - if (ret) 289 + if (ret) { 301 290 dev_err(dev, "Failed to enable supply: %d\n", ret); 291 + } else { 292 + ret = devm_add_action_or_reset(dev, 293 + regulator_disable_action, dev); 294 + if (ret) 295 + return ret; 296 + } 302 297 } 303 298 304 299 child_node = of_get_next_available_child(np, NULL); ··· 394 377 static int ktd2692_remove(struct platform_device *pdev) 395 378 { 396 379 struct ktd2692_context *led = platform_get_drvdata(pdev); 397 - int ret; 398 380 399 381 led_classdev_flash_unregister(&led->fled_cdev); 400 - 401 - if (led->regulator) { 402 - ret = regulator_disable(led->regulator); 403 - if (ret) 404 - dev_err(&pdev->dev, 405 - "Failed to disable supply: %d\n", ret); 406 - } 407 382 408 383 mutex_destroy(&led->lock); 409 384