mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: phy: drop kfree of devm_kzalloc's data
@ 2014-08-10 19:59 Himangi Saraogi
  2014-08-11  2:15 ` Jingoo Han
  0 siblings, 1 reply; 2+ messages in thread
From: Himangi Saraogi @ 2014-08-10 19:59 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman, linux-usb, linux-kernel; +Cc: Julia Lawall

Using kfree to free data allocated with devm_kzalloc causes double frees.

The Coccinelle semantic patch that fixes this problem is as follows:

// <smpl>
@@
expression x;
@@

x = devm_kzalloc(...)
...
?-kfree(x);
// </smpl>

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
 drivers/usb/phy/phy-gpio-vbus-usb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/phy/phy-gpio-vbus-usb.c b/drivers/usb/phy/phy-gpio-vbus-usb.c
index ea9e705..f4b14bd 100644
--- a/drivers/usb/phy/phy-gpio-vbus-usb.c
+++ b/drivers/usb/phy/phy-gpio-vbus-usb.c
@@ -260,10 +260,8 @@ static int gpio_vbus_probe(struct platform_device *pdev)
 
 	gpio_vbus->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg),
 					  GFP_KERNEL);
-	if (!gpio_vbus->phy.otg) {
-		kfree(gpio_vbus);
+	if (!gpio_vbus->phy.otg)
 		return -ENOMEM;
-	}
 
 	platform_set_drvdata(pdev, gpio_vbus);
 	gpio_vbus->dev = &pdev->dev;
-- 
1.9.1


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

* Re: [PATCH] usb: phy: drop kfree of devm_kzalloc's data
  2014-08-10 19:59 [PATCH] usb: phy: drop kfree of devm_kzalloc's data Himangi Saraogi
@ 2014-08-11  2:15 ` Jingoo Han
  0 siblings, 0 replies; 2+ messages in thread
From: Jingoo Han @ 2014-08-11  2:15 UTC (permalink / raw)
  To: 'Himangi Saraogi', 'Felipe Balbi'
  Cc: 'Greg Kroah-Hartman',
	linux-usb, linux-kernel, 'Julia Lawall',
	'Jingoo Han'

On Monday, August 11, 2014 5:00 AM, Himangi Saraogi wrote:
> 
> Using kfree to free data allocated with devm_kzalloc causes double frees.
> 
> The Coccinelle semantic patch that fixes this problem is as follows:
> 
> // <smpl>
> @@
> expression x;
> @@
> 
> x = devm_kzalloc(...)
> ...
> ?-kfree(x);
> // </smpl>
> 
> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
> Acked-by: Julia Lawall <julia.lawall@lip6.fr>

Reviewed-by: Jingoo Han <jg1.han@samsung.com>

Best regards,
Jingoo Han

> ---
>  drivers/usb/phy/phy-gpio-vbus-usb.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/phy/phy-gpio-vbus-usb.c b/drivers/usb/phy/phy-gpio-vbus-usb.c
> index ea9e705..f4b14bd 100644
> --- a/drivers/usb/phy/phy-gpio-vbus-usb.c
> +++ b/drivers/usb/phy/phy-gpio-vbus-usb.c
> @@ -260,10 +260,8 @@ static int gpio_vbus_probe(struct platform_device *pdev)
> 
>  	gpio_vbus->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg),
>  					  GFP_KERNEL);
> -	if (!gpio_vbus->phy.otg) {
> -		kfree(gpio_vbus);
> +	if (!gpio_vbus->phy.otg)
>  		return -ENOMEM;
> -	}
> 
>  	platform_set_drvdata(pdev, gpio_vbus);
>  	gpio_vbus->dev = &pdev->dev;
> --
> 1.9.1


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

end of thread, other threads:[~2014-08-11  2:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-10 19:59 [PATCH] usb: phy: drop kfree of devm_kzalloc's data Himangi Saraogi
2014-08-11  2:15 ` Jingoo Han

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®