Re: [PATCH v2] sdio: Fix a memory leaking bug in wl1271_probe()
From: Jiri Slaby <hidden>
Date: 2019-06-05 06:03:46
Also in:
lkml
On 23. 05. 19, 16:44, Gen Zhang wrote:
quoted hunk ↗ jump to hunk
In wl1271_probe(), 'glue->core' is allocated by platform_device_alloc(), when this allocation fails, ENOMEM is returned. However, 'pdev_data' and 'glue' are allocated by devm_kzalloc() before 'glue->core'. When platform_device_alloc() returns NULL, we should also free 'pdev_data' and 'glue' before wl1271_probe() ends to prevent leaking memory. Similarly, we should free 'pdev_data' when 'glue' is NULL. And we should free 'pdev_data' and 'glue' when 'ret' is error. Further, we shoulf free 'glue->dev', 'pdev_data' and 'glue' when this function normally ends to prevent memory leaking. Signed-off-by: Gen Zhang <redacted> ---diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c index 4d4b0770..232ce5f 100644 --- a/drivers/net/wireless/ti/wlcore/sdio.c +++ b/drivers/net/wireless/ti/wlcore/sdio.c
...
quoted hunk ↗ jump to hunk
@@ -380,11 +382,20 @@ static int wl1271_probe(struct sdio_func *func, dev_err(glue->dev, "can't add platform device\n"); goto out_dev_put; } + platform_device_put(glue->core); + devm_kfree(&func->dev, glue); + devm_kfree(&func->dev, pdev_data); return 0; out_dev_put: platform_device_put(glue->core); +out_free2: + devm_kfree(&func->dev, glue); + +out_free1: + devm_kfree(&func->dev, pdev_data);
Are you aware of purpose of devm allocations? thanks, -- js suse labs