* Re: [PATCH v2] sdio: Fix a memory leaking bug in wl1271_probe() [not found] <20190523144425.GA26766@zhanggen-UX430UQ> @ 2019-05-23 15:00 ` Kalle Valo 2019-05-24 2:43 ` [PATCH v2] wlcore: " Gen Zhang 0 siblings, 1 reply; 3+ messages in thread From: Kalle Valo @ 2019-05-23 15:00 UTC (permalink / raw) To: Gen Zhang; +Cc: eyalreizer, netdev, linux-kernel, linux-wireless + linux-wireless Gen Zhang <blackgod016574@gmail.com> writes: > 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 <blackgod016574@gmail.com> > --- > 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 You need to CC linux-wireless, otherwise patchwork won't see the patch and it will not be applied. Also you should use prefix "wlcore:". https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches#commit_title_is_wrong -- Kalle Valo ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] wlcore: sdio: Fix a memory leaking bug in wl1271_probe() 2019-05-23 15:00 ` [PATCH v2] sdio: Fix a memory leaking bug in wl1271_probe() Kalle Valo @ 2019-05-24 2:43 ` Gen Zhang 2019-05-24 9:28 ` Jon Hunter 0 siblings, 1 reply; 3+ messages in thread From: Gen Zhang @ 2019-05-24 2:43 UTC (permalink / raw) To: Kalle Valo; +Cc: linux-wireless, netdev, linux-kernel 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 <blackgod016574@gmail.com> --- diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c index 4d4b0770..9110891 100644 --- a/drivers/net/wireless/ti/wlcore/sdio.c +++ b/drivers/net/wireless/ti/wlcore/sdio.c @@ -298,8 +298,10 @@ static int wl1271_probe(struct sdio_func *func, pdev_data->if_ops = &sdio_ops; glue = devm_kzalloc(&func->dev, sizeof(*glue), GFP_KERNEL); - if (!glue) - return -ENOMEM; + if (!glue) { + ret = -ENOMEM; + goto out_free1; + } glue->dev = &func->dev; @@ -311,7 +313,7 @@ static int wl1271_probe(struct sdio_func *func, ret = wlcore_probe_of(&func->dev, &irq, &wakeirq, pdev_data); if (ret) - goto out; + goto out_free2; /* if sdio can keep power while host is suspended, enable wow */ mmcflags = sdio_get_host_pm_caps(func); @@ -340,7 +342,7 @@ static int wl1271_probe(struct sdio_func *func, if (!glue->core) { dev_err(glue->dev, "can't allocate platform_device"); ret = -ENOMEM; - goto out; + goto out_free2; } glue->core->dev.parent = &func->dev; @@ -380,12 +382,17 @@ static int wl1271_probe(struct sdio_func *func, dev_err(glue->dev, "can't add platform device\n"); goto out_dev_put; } - return 0; + ret = 0; out_dev_put: platform_device_put(glue->core); -out: +out_free2: + devm_kfree(&func->dev, glue); + +out_free1: + devm_kfree(&func->dev, pdev_data); + return ret; } --- ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] wlcore: sdio: Fix a memory leaking bug in wl1271_probe() 2019-05-24 2:43 ` [PATCH v2] wlcore: " Gen Zhang @ 2019-05-24 9:28 ` Jon Hunter 0 siblings, 0 replies; 3+ messages in thread From: Jon Hunter @ 2019-05-24 9:28 UTC (permalink / raw) To: Gen Zhang, Kalle Valo; +Cc: linux-wireless, netdev, linux-kernel On 24/05/2019 03:43, Gen Zhang wrote: > 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. No, devm_kzalloc() automatically frees memory on failure. > 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. Why? > Signed-off-by: Gen Zhang <blackgod016574@gmail.com> > --- > diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c > index 4d4b0770..9110891 100644 > --- a/drivers/net/wireless/ti/wlcore/sdio.c > +++ b/drivers/net/wireless/ti/wlcore/sdio.c > @@ -298,8 +298,10 @@ static int wl1271_probe(struct sdio_func *func, > pdev_data->if_ops = &sdio_ops; > > glue = devm_kzalloc(&func->dev, sizeof(*glue), GFP_KERNEL); > - if (!glue) > - return -ENOMEM; > + if (!glue) { > + ret = -ENOMEM; > + goto out_free1; > + } > > glue->dev = &func->dev; > > @@ -311,7 +313,7 @@ static int wl1271_probe(struct sdio_func *func, > > ret = wlcore_probe_of(&func->dev, &irq, &wakeirq, pdev_data); > if (ret) > - goto out; > + goto out_free2; > > /* if sdio can keep power while host is suspended, enable wow */ > mmcflags = sdio_get_host_pm_caps(func); > @@ -340,7 +342,7 @@ static int wl1271_probe(struct sdio_func *func, > if (!glue->core) { > dev_err(glue->dev, "can't allocate platform_device"); > ret = -ENOMEM; > - goto out; > + goto out_free2; > } > > glue->core->dev.parent = &func->dev; > @@ -380,12 +382,17 @@ static int wl1271_probe(struct sdio_func *func, > dev_err(glue->dev, "can't add platform device\n"); > goto out_dev_put; > } > - return 0; > + ret = 0; This is completely wrong. > out_dev_put: > platform_device_put(glue->core); > > -out: > +out_free2: > + devm_kfree(&func->dev, glue); > + > +out_free1: > + devm_kfree(&func->dev, pdev_data); > + > return ret; > } > > --- Jon -- nvpublic ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-24 9:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20190523144425.GA26766@zhanggen-UX430UQ>
2019-05-23 15:00 ` [PATCH v2] sdio: Fix a memory leaking bug in wl1271_probe() Kalle Valo
2019-05-24 2:43 ` [PATCH v2] wlcore: " Gen Zhang
2019-05-24 9:28 ` Jon Hunter
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox