diff options
author | Christophe Jaillet <christophe.jaillet@wanadoo.fr> | 2018-03-13 16:33:11 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2018-03-14 12:37:41 -0400 |
commit | ed8cffda27dea6fd3dafb3ee881c5a786edac9ca (patch) | |
tree | 46cb7abf33d55e210a6a8ea5046fb11021a05e15 | |
parent | 11da04af0d3b4c24ab057dd17f54dbc854d735de (diff) |
regulator: gpio: Fix some error handling paths in 'gpio_regulator_probe()'
Re-order error handling code and gotos to avoid leaks in error handling
paths.
Fixes: 9f946099fe19 ("regulator: gpio: fix parsing of gpio list")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/regulator/gpio-regulator.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 0fce06acfaec..a2eb50719c7b 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c | |||
@@ -271,8 +271,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) | |||
271 | drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); | 271 | drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); |
272 | if (drvdata->desc.name == NULL) { | 272 | if (drvdata->desc.name == NULL) { |
273 | dev_err(&pdev->dev, "Failed to allocate supply name\n"); | 273 | dev_err(&pdev->dev, "Failed to allocate supply name\n"); |
274 | ret = -ENOMEM; | 274 | return -ENOMEM; |
275 | goto err; | ||
276 | } | 275 | } |
277 | 276 | ||
278 | if (config->nr_gpios != 0) { | 277 | if (config->nr_gpios != 0) { |
@@ -292,7 +291,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) | |||
292 | dev_err(&pdev->dev, | 291 | dev_err(&pdev->dev, |
293 | "Could not obtain regulator setting GPIOs: %d\n", | 292 | "Could not obtain regulator setting GPIOs: %d\n", |
294 | ret); | 293 | ret); |
295 | goto err_memstate; | 294 | goto err_memgpio; |
296 | } | 295 | } |
297 | } | 296 | } |
298 | 297 | ||
@@ -303,7 +302,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) | |||
303 | if (drvdata->states == NULL) { | 302 | if (drvdata->states == NULL) { |
304 | dev_err(&pdev->dev, "Failed to allocate state data\n"); | 303 | dev_err(&pdev->dev, "Failed to allocate state data\n"); |
305 | ret = -ENOMEM; | 304 | ret = -ENOMEM; |
306 | goto err_memgpio; | 305 | goto err_stategpio; |
307 | } | 306 | } |
308 | drvdata->nr_states = config->nr_states; | 307 | drvdata->nr_states = config->nr_states; |
309 | 308 | ||
@@ -324,7 +323,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) | |||
324 | default: | 323 | default: |
325 | dev_err(&pdev->dev, "No regulator type set\n"); | 324 | dev_err(&pdev->dev, "No regulator type set\n"); |
326 | ret = -EINVAL; | 325 | ret = -EINVAL; |
327 | goto err_memgpio; | 326 | goto err_memstate; |
328 | } | 327 | } |
329 | 328 | ||
330 | /* build initial state from gpio init data. */ | 329 | /* build initial state from gpio init data. */ |
@@ -361,22 +360,21 @@ static int gpio_regulator_probe(struct platform_device *pdev) | |||
361 | if (IS_ERR(drvdata->dev)) { | 360 | if (IS_ERR(drvdata->dev)) { |
362 | ret = PTR_ERR(drvdata->dev); | 361 | ret = PTR_ERR(drvdata->dev); |
363 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); | 362 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); |
364 | goto err_stategpio; | 363 | goto err_memstate; |
365 | } | 364 | } |
366 | 365 | ||
367 | platform_set_drvdata(pdev, drvdata); | 366 | platform_set_drvdata(pdev, drvdata); |
368 | 367 | ||
369 | return 0; | 368 | return 0; |
370 | 369 | ||
371 | err_stategpio: | ||
372 | gpio_free_array(drvdata->gpios, drvdata->nr_gpios); | ||
373 | err_memstate: | 370 | err_memstate: |
374 | kfree(drvdata->states); | 371 | kfree(drvdata->states); |
372 | err_stategpio: | ||
373 | gpio_free_array(drvdata->gpios, drvdata->nr_gpios); | ||
375 | err_memgpio: | 374 | err_memgpio: |
376 | kfree(drvdata->gpios); | 375 | kfree(drvdata->gpios); |
377 | err_name: | 376 | err_name: |
378 | kfree(drvdata->desc.name); | 377 | kfree(drvdata->desc.name); |
379 | err: | ||
380 | return ret; | 378 | return ret; |
381 | } | 379 | } |
382 | 380 | ||