linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator: cros-ec-regulator: Fix double free of desc->name.
@ 2020-07-28  9:19 Pi-Hsun Shih
  2020-07-28  9:34 ` Enric Balletbo i Serra
  2020-07-28 16:31 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Pi-Hsun Shih @ 2020-07-28  9:19 UTC (permalink / raw)
  Cc: Pi-Hsun Shih, Liam Girdwood, Mark Brown, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck, Prashant Malani,
	open list:VOLTAGE AND CURRENT REGULATOR FRAMEWORK

The desc->name field is allocated with devm_kstrdup, but is also kfreed
on the error path, causing it to be double freed. Remove the kfree on
the error path.

Fixes: 8d9f8d57e023 ("regulator: Add driver for cros-ec-regulator")
Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
---
 drivers/regulator/cros-ec-regulator.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/regulator/cros-ec-regulator.c b/drivers/regulator/cros-ec-regulator.c
index 35f97246bc48..cee259eb0213 100644
--- a/drivers/regulator/cros-ec-regulator.c
+++ b/drivers/regulator/cros-ec-regulator.c
@@ -222,18 +222,13 @@ static int cros_ec_regulator_probe(struct platform_device *pdev)
 
 	drvdata->dev = devm_regulator_register(dev, &drvdata->desc, &cfg);
 	if (IS_ERR(drvdata->dev)) {
-		ret = PTR_ERR(drvdata->dev);
 		dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
-		goto free_name;
+		return PTR_ERR(drvdata->dev);
 	}
 
 	platform_set_drvdata(pdev, drvdata);
 
 	return 0;
-
-free_name:
-	kfree(desc->name);
-	return ret;
 }
 
 static const struct of_device_id regulator_cros_ec_of_match[] = {

base-commit: 8d9f8d57e023893bfa708d83e3a787e77766a378
-- 
2.28.0.rc0.142.g3c755180ce-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] regulator: cros-ec-regulator: Fix double free of desc->name.
  2020-07-28  9:19 [PATCH] regulator: cros-ec-regulator: Fix double free of desc->name Pi-Hsun Shih
@ 2020-07-28  9:34 ` Enric Balletbo i Serra
  2020-07-28 16:31 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Enric Balletbo i Serra @ 2020-07-28  9:34 UTC (permalink / raw)
  To: Pi-Hsun Shih
  Cc: Liam Girdwood, Mark Brown, Benson Leung, Guenter Roeck,
	Prashant Malani,
	open list:VOLTAGE AND CURRENT REGULATOR FRAMEWORK

Hi Pi-Hsun,

Thank you for your patch and to send upstream.

On 28/7/20 11:19, Pi-Hsun Shih wrote:
> The desc->name field is allocated with devm_kstrdup, but is also kfreed
> on the error path, causing it to be double freed. Remove the kfree on
> the error path.
> 
> Fixes: 8d9f8d57e023 ("regulator: Add driver for cros-ec-regulator")
> Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>

Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

> ---
>  drivers/regulator/cros-ec-regulator.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/regulator/cros-ec-regulator.c b/drivers/regulator/cros-ec-regulator.c
> index 35f97246bc48..cee259eb0213 100644
> --- a/drivers/regulator/cros-ec-regulator.c
> +++ b/drivers/regulator/cros-ec-regulator.c
> @@ -222,18 +222,13 @@ static int cros_ec_regulator_probe(struct platform_device *pdev)
>  
>  	drvdata->dev = devm_regulator_register(dev, &drvdata->desc, &cfg);
>  	if (IS_ERR(drvdata->dev)) {
> -		ret = PTR_ERR(drvdata->dev);
>  		dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
> -		goto free_name;
> +		return PTR_ERR(drvdata->dev);
>  	}
>  
>  	platform_set_drvdata(pdev, drvdata);
>  
>  	return 0;
> -
> -free_name:
> -	kfree(desc->name);
> -	return ret;
>  }
>  
>  static const struct of_device_id regulator_cros_ec_of_match[] = {
> 
> base-commit: 8d9f8d57e023893bfa708d83e3a787e77766a378
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] regulator: cros-ec-regulator: Fix double free of desc->name.
  2020-07-28  9:19 [PATCH] regulator: cros-ec-regulator: Fix double free of desc->name Pi-Hsun Shih
  2020-07-28  9:34 ` Enric Balletbo i Serra
@ 2020-07-28 16:31 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2020-07-28 16:31 UTC (permalink / raw)
  To: Pi-Hsun Shih
  Cc: Guenter Roeck, open list:VOLTAGE AND CURRENT REGULATOR FRAMEWORK,
	Liam Girdwood, Enric Balletbo i Serra, Benson Leung,
	Prashant Malani

On Tue, 28 Jul 2020 17:19:09 +0800, Pi-Hsun Shih wrote:
> The desc->name field is allocated with devm_kstrdup, but is also kfreed
> on the error path, causing it to be double freed. Remove the kfree on
> the error path.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/1] regulator: cros-ec-regulator: Fix double free of desc->name.
      commit: 176cf704425f3d22603d379ffa4a1033a24a779d

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-28 16:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28  9:19 [PATCH] regulator: cros-ec-regulator: Fix double free of desc->name Pi-Hsun Shih
2020-07-28  9:34 ` Enric Balletbo i Serra
2020-07-28 16:31 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).