lkml.org 
[lkml]   [2014]   [May]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] Input: tps6507x-ts: Introduce the use of the managed version of kzalloc
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, the unnecessary label err_free_mem is removed.

The following Coccinelle semantic patch was used for making the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
I would like to know if it is desirable to add a
devm_input_allocate_polled_device like devm_input_allocate_device. If
this is done, it seems that no change is required in
input_unregister_polled_device as there is a separate call to this
function, and then to input_free_polled_device (which would go away).
Please let me know if this reasoning is correct.

drivers/input/touchscreen/tps6507x-ts.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/input/touchscreen/tps6507x-ts.c b/drivers/input/touchscreen/tps6507x-ts.c
index 94cde2c..bd57be1 100644
--- a/drivers/input/touchscreen/tps6507x-ts.c
+++ b/drivers/input/touchscreen/tps6507x-ts.c
@@ -233,7 +233,7 @@ static int tps6507x_ts_probe(struct platform_device *pdev)
*/
init_data = tps_board->tps6507x_ts_init_data;

- tsc = kzalloc(sizeof(struct tps6507x_ts), GFP_KERNEL);
+ tsc = devm_kzalloc(&pdev->dev, sizeof(struct tps6507x_ts), GFP_KERNEL);
if (!tsc) {
dev_err(tps6507x_dev->dev, "failed to allocate driver data\n");
return -ENOMEM;
@@ -250,8 +250,7 @@ static int tps6507x_ts_probe(struct platform_device *pdev)
poll_dev = input_allocate_polled_device();
if (!poll_dev) {
dev_err(tsc->dev, "Failed to allocate polled input device.\n");
- error = -ENOMEM;
- goto err_free_mem;
+ return -ENOMEM;
}

tsc->poll_dev = poll_dev;
@@ -293,8 +292,6 @@ static int tps6507x_ts_probe(struct platform_device *pdev)

err_free_polled_dev:
input_free_polled_device(poll_dev);
-err_free_mem:
- kfree(tsc);
return error;
}

@@ -306,8 +303,6 @@ static int tps6507x_ts_remove(struct platform_device *pdev)
input_unregister_polled_device(poll_dev);
input_free_polled_device(poll_dev);

- kfree(tsc);
-
return 0;
}

--
1.9.1


\
 
 \ /
  Last update: 2014-05-19 23:41    [W:0.361 / U:2.960 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site