Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

video: msm: 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, linux/device.h is added to make sure the devm_*()
routine declarations are unambiguously available. The function
mddi_dummy_remove is removed as it is no longer required after
removing the kfree. The variable ret is also done away with.

The following Coccinelle semantic patch was used for making a part of
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>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>

authored by

Himangi Saraogi and committed by
Tomi Valkeinen
6a902305 8c70f533

+3 -16
+3 -16
drivers/video/fbdev/msm/mddi_client_dummy.c
··· 15 15 * GNU General Public License for more details. 16 16 */ 17 17 18 + #include <linux/device.h> 18 19 #include <linux/slab.h> 19 20 #include <linux/module.h> 20 21 #include <linux/kernel.h> ··· 52 51 { 53 52 struct msm_mddi_client_data *client_data = pdev->dev.platform_data; 54 53 struct panel_info *panel = 55 - kzalloc(sizeof(struct panel_info), GFP_KERNEL); 56 - int ret; 54 + devm_kzalloc(&pdev->dev, sizeof(struct panel_info), GFP_KERNEL); 57 55 if (!panel) 58 56 return -ENOMEM; 59 57 platform_set_drvdata(pdev, panel); ··· 67 67 client_data->fb_resource, 1); 68 68 panel->panel_data.fb_data = client_data->private_client_data; 69 69 panel->pdev.dev.platform_data = &panel->panel_data; 70 - ret = platform_device_register(&panel->pdev); 71 - if (ret) { 72 - kfree(panel); 73 - return ret; 74 - } 75 - return 0; 76 - } 77 - 78 - static int mddi_dummy_remove(struct platform_device *pdev) 79 - { 80 - struct panel_info *panel = platform_get_drvdata(pdev); 81 - kfree(panel); 82 - return 0; 70 + return platform_device_register(&panel->pdev); 83 71 } 84 72 85 73 static struct platform_driver mddi_client_dummy = { 86 74 .probe = mddi_dummy_probe, 87 - .remove = mddi_dummy_remove, 88 75 .driver = { .name = "mddi_c_dummy" }, 89 76 }; 90 77