Skip to contentSkip to conversation

Input: wm831x-on - Convert to devm_kzalloc()

PATCH In review Mark Brown 2 participants 3 messages Dec 26, 2011

Subsystems (3)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 Input: wm831x-on - Convert to devm_kzalloc()

Saves a small amount of code and reduces the potential for leaks.

---
 drivers/input/misc/wm831x-on.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/input/misc/wm831x-on.c +2 -3
index 47f18d6..aee53fb 100644
@@ -76,7 +76,8 @@ static int __devinit wm831x_on_probe(struct platform_device *pdev)
 	int irq = platform_get_irq(pdev, 0);
 	int ret;
 
-	wm831x_on = kzalloc(sizeof(struct wm831x_on), GFP_KERNEL);
+	wm831x_on = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_on),
+				 GFP_KERNEL);
 	if (!wm831x_on) {
 		dev_err(&pdev->dev, "Can't allocate data\n");
 		return -ENOMEM;
@@ -120,7 +121,6 @@ err_irq:
 err_input_dev:
 	input_free_device(wm831x_on->dev);
 err:
-	kfree(wm831x_on);
 	return ret;
 }
 
@@ -132,7 +132,6 @@ static int __devexit wm831x_on_remove(struct platform_device *pdev)
 	free_irq(irq, wm831x_on);
 	cancel_delayed_work_sync(&wm831x_on->work);
 	input_unregister_device(wm831x_on->dev);
-	kfree(wm831x_on);
 
 	return 0;
 }
Signature · 1 line
1.7.7.3
#1 lore raw
Quoted 1 line

Saves a small amount of code and reduces the potential for leaks.

Shouldn't you still be kind and free the memory anyway?

M

Quoted 36 lines
---
 drivers/input/misc/wm831x-on.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/input/misc/wm831x-on.c index 47f18d6..aee53fb 100644

drivers/input/misc/wm831x-on.c +2 -3
@@ -76,7 +76,8 @@ static int __devinit wm831x_on_probe(struct
 platform_device *pdev) int irq = platform_get_irq(pdev, 0);
 	int ret;
 
-	wm831x_on = kzalloc(sizeof(struct wm831x_on), GFP_KERNEL);
+	wm831x_on = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_on),
+				 GFP_KERNEL);
 	if (!wm831x_on) {
 		dev_err(&pdev->dev, "Can't allocate data\n");
 		return -ENOMEM;
@@ -120,7 +121,6 @@ err_irq:
 err_input_dev:
 	input_free_device(wm831x_on->dev);
 err:
-	kfree(wm831x_on);
 	return ret;
 }
 
@@ -132,7 +132,6 @@ static int __devexit wm831x_on_remove(struct
 platform_device *pdev) free_irq(irq, wm831x_on);
 	cancel_delayed_work_sync(&wm831x_on->work);
 	input_unregister_device(wm831x_on->dev);
-	kfree(wm831x_on);
 
 	return 0;
 }
author
#2 lore raw
Quoted 3 lines · Marek Vasut
Quoted 1 line

Saves a small amount of code and reduces the potential for leaks.

Shouldn't you still be kind and free the memory anyway?

There doesn't seem to be much point if it's going to be freed immediately anyway and half the point of the helpers is to avoid having to write the cleanup code.