Commit 121de4ed authored by Christophe Jaillet's avatar Christophe Jaillet Committed by Greg Kroah-Hartman

regulator: gpio: Fix some error handling paths in 'gpio_regulator_probe()'

[ Upstream commit ed8cffda ]

Re-order error handling code and gotos to avoid leaks in error handling
paths.

Fixes: 9f946099 ("regulator: gpio: fix parsing of gpio list")
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 19434e74
...@@ -268,8 +268,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) ...@@ -268,8 +268,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL);
if (drvdata->desc.name == NULL) { if (drvdata->desc.name == NULL) {
dev_err(&pdev->dev, "Failed to allocate supply name\n"); dev_err(&pdev->dev, "Failed to allocate supply name\n");
ret = -ENOMEM; return -ENOMEM;
goto err;
} }
if (config->nr_gpios != 0) { if (config->nr_gpios != 0) {
...@@ -289,7 +288,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) ...@@ -289,7 +288,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Could not obtain regulator setting GPIOs: %d\n", "Could not obtain regulator setting GPIOs: %d\n",
ret); ret);
goto err_memstate; goto err_memgpio;
} }
} }
...@@ -300,7 +299,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) ...@@ -300,7 +299,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
if (drvdata->states == NULL) { if (drvdata->states == NULL) {
dev_err(&pdev->dev, "Failed to allocate state data\n"); dev_err(&pdev->dev, "Failed to allocate state data\n");
ret = -ENOMEM; ret = -ENOMEM;
goto err_memgpio; goto err_stategpio;
} }
drvdata->nr_states = config->nr_states; drvdata->nr_states = config->nr_states;
...@@ -321,7 +320,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) ...@@ -321,7 +320,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
default: default:
dev_err(&pdev->dev, "No regulator type set\n"); dev_err(&pdev->dev, "No regulator type set\n");
ret = -EINVAL; ret = -EINVAL;
goto err_memgpio; goto err_memstate;
} }
/* build initial state from gpio init data. */ /* build initial state from gpio init data. */
...@@ -358,22 +357,21 @@ static int gpio_regulator_probe(struct platform_device *pdev) ...@@ -358,22 +357,21 @@ static int gpio_regulator_probe(struct platform_device *pdev)
if (IS_ERR(drvdata->dev)) { if (IS_ERR(drvdata->dev)) {
ret = PTR_ERR(drvdata->dev); ret = PTR_ERR(drvdata->dev);
dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
goto err_stategpio; goto err_memstate;
} }
platform_set_drvdata(pdev, drvdata); platform_set_drvdata(pdev, drvdata);
return 0; return 0;
err_stategpio:
gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
err_memstate: err_memstate:
kfree(drvdata->states); kfree(drvdata->states);
err_stategpio:
gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
err_memgpio: err_memgpio:
kfree(drvdata->gpios); kfree(drvdata->gpios);
err_name: err_name:
kfree(drvdata->desc.name); kfree(drvdata->desc.name);
err:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment