Skip to contentSkip to conversation

usb: phy: drop kfree of devm_kzalloc's data

PATCH In review Himangi Saraogi 2 participants 2 messages Aug 10, 2014 – Aug 11, 2014 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: phy: drop kfree of devm_kzalloc's data

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>

---
 drivers/usb/phy/phy-gpio-vbus-usb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/phy/phy-gpio-vbus-usb.c +1 -3
index ea9e705..f4b14bd 100644
@@ -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;
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Himangi Saraogi

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;
@@

Quoted 7 lines

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

Best regards,
Jingoo Han

Quoted 22 lines
---
 drivers/usb/phy/phy-gpio-vbus-usb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/phy/phy-gpio-vbus-usb.c +1 -4
index ea9e705..f4b14bd 100644
@@ -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