linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] wilc1000: Fix memleak in wilc_sdio_probe
@ 2020-08-20  5:48 Dinghao Liu
  2020-08-20  5:56 ` Ajay.Kathat
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dinghao Liu @ 2020-08-20  5:48 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Ajay Singh, Claudiu Beznea, Kalle Valo, David S. Miller,
	Jakub Kicinski, Eugen Hristev, Greg Kroah-Hartman,
	linux-wireless, netdev, linux-kernel

When devm_clk_get() returns -EPROBE_DEFER, sdio_priv
should be freed just like when wilc_cfg80211_init()
fails.

Fixes: 8692b047e86cf ("staging: wilc1000: look for rtc_clk clock")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---

Changelog:

v2: - Remove 'staging' prefix in subject.
---
 drivers/net/wireless/microchip/wilc1000/sdio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/microchip/wilc1000/sdio.c b/drivers/net/wireless/microchip/wilc1000/sdio.c
index 3ece7b0b0392..351ff909ab1c 100644
--- a/drivers/net/wireless/microchip/wilc1000/sdio.c
+++ b/drivers/net/wireless/microchip/wilc1000/sdio.c
@@ -149,9 +149,10 @@ static int wilc_sdio_probe(struct sdio_func *func,
 	wilc->dev = &func->dev;
 
 	wilc->rtc_clk = devm_clk_get(&func->card->dev, "rtc");
-	if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER)
+	if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) {
+		kfree(sdio_priv);
 		return -EPROBE_DEFER;
-	else if (!IS_ERR(wilc->rtc_clk))
+	} else if (!IS_ERR(wilc->rtc_clk))
 		clk_prepare_enable(wilc->rtc_clk);
 
 	dev_info(&func->dev, "Driver Initializing success\n");
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [v2] wilc1000: Fix memleak in wilc_sdio_probe
  2020-08-20  5:48 [PATCH] [v2] wilc1000: Fix memleak in wilc_sdio_probe Dinghao Liu
@ 2020-08-20  5:56 ` Ajay.Kathat
  2020-08-25  8:11 ` Claudiu.Beznea
  2020-08-27 10:01 ` Kalle Valo
  2 siblings, 0 replies; 4+ messages in thread
From: Ajay.Kathat @ 2020-08-20  5:56 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Claudiu.Beznea, kvalo, davem, kuba, Eugen.Hristev, gregkh,
	linux-wireless, netdev, linux-kernel


On 20/08/20 11:18 am, Dinghao Liu wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> When devm_clk_get() returns -EPROBE_DEFER, sdio_priv
> should be freed just like when wilc_cfg80211_init()
> fails.
> 
> Fixes: 8692b047e86cf ("staging: wilc1000: look for rtc_clk clock")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>

Acked-by: Ajay Singh <ajay.kathat@microchip.com>

> ---
> 
> Changelog:
> 
> v2: - Remove 'staging' prefix in subject.
> ---
>  drivers/net/wireless/microchip/wilc1000/sdio.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/microchip/wilc1000/sdio.c b/drivers/net/wireless/microchip/wilc1000/sdio.c
> index 3ece7b0b0392..351ff909ab1c 100644
> --- a/drivers/net/wireless/microchip/wilc1000/sdio.c
> +++ b/drivers/net/wireless/microchip/wilc1000/sdio.c
> @@ -149,9 +149,10 @@ static int wilc_sdio_probe(struct sdio_func *func,
>         wilc->dev = &func->dev;
> 
>         wilc->rtc_clk = devm_clk_get(&func->card->dev, "rtc");
> -       if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER)
> +       if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) {
> +               kfree(sdio_priv);
>                 return -EPROBE_DEFER;
> -       else if (!IS_ERR(wilc->rtc_clk))
> +       } else if (!IS_ERR(wilc->rtc_clk))
>                 clk_prepare_enable(wilc->rtc_clk);
> 
>         dev_info(&func->dev, "Driver Initializing success\n");
> --
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [v2] wilc1000: Fix memleak in wilc_sdio_probe
  2020-08-20  5:48 [PATCH] [v2] wilc1000: Fix memleak in wilc_sdio_probe Dinghao Liu
  2020-08-20  5:56 ` Ajay.Kathat
@ 2020-08-25  8:11 ` Claudiu.Beznea
  2020-08-27 10:01 ` Kalle Valo
  2 siblings, 0 replies; 4+ messages in thread
From: Claudiu.Beznea @ 2020-08-25  8:11 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Ajay.Kathat, kvalo, davem, kuba, Eugen.Hristev, gregkh,
	linux-wireless, netdev, linux-kernel



On 20.08.2020 08:48, Dinghao Liu wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> When devm_clk_get() returns -EPROBE_DEFER, sdio_priv
> should be freed just like when wilc_cfg80211_init()
> fails.
> 
> Fixes: 8692b047e86cf ("staging: wilc1000: look for rtc_clk clock")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
> 
> Changelog:
> 
> v2: - Remove 'staging' prefix in subject.
> ---
>  drivers/net/wireless/microchip/wilc1000/sdio.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/microchip/wilc1000/sdio.c b/drivers/net/wireless/microchip/wilc1000/sdio.c
> index 3ece7b0b0392..351ff909ab1c 100644
> --- a/drivers/net/wireless/microchip/wilc1000/sdio.c
> +++ b/drivers/net/wireless/microchip/wilc1000/sdio.c
> @@ -149,9 +149,10 @@ static int wilc_sdio_probe(struct sdio_func *func,
>         wilc->dev = &func->dev;
> 
>         wilc->rtc_clk = devm_clk_get(&func->card->dev, "rtc");
> -       if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER)
> +       if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) {
> +               kfree(sdio_priv);

The proper way to free resources here would be to call
wilc_netdev_cleanup() which will free all objects allocated by
wilc_cfg80211_init() and will also free sdio_priv. I personally would go
further and remove the kfree(wilc->bus_data) from wilc_netdev_cleanup() and
keep it in the wilc_sdio_probe(), wilc_spi_probe() where it was actually
allocated.

>                 return -EPROBE_DEFER;
> -       else if (!IS_ERR(wilc->rtc_clk))
> +       } else if (!IS_ERR(wilc->rtc_clk))
>                 clk_prepare_enable(wilc->rtc_clk);
> 
>         dev_info(&func->dev, "Driver Initializing success\n");
> --
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [v2] wilc1000: Fix memleak in wilc_sdio_probe
  2020-08-20  5:48 [PATCH] [v2] wilc1000: Fix memleak in wilc_sdio_probe Dinghao Liu
  2020-08-20  5:56 ` Ajay.Kathat
  2020-08-25  8:11 ` Claudiu.Beznea
@ 2020-08-27 10:01 ` Kalle Valo
  2 siblings, 0 replies; 4+ messages in thread
From: Kalle Valo @ 2020-08-27 10:01 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: dinghao.liu, kjlu, Ajay Singh, Claudiu Beznea, David S. Miller,
	Jakub Kicinski, Eugen Hristev, Greg Kroah-Hartman,
	linux-wireless, netdev, linux-kernel

Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:

> When devm_clk_get() returns -EPROBE_DEFER, sdio_priv
> should be freed just like when wilc_cfg80211_init()
> fails.
> 
> Fixes: 8692b047e86cf ("staging: wilc1000: look for rtc_clk clock")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> Acked-by: Ajay Singh <ajay.kathat@microchip.com>

Patch applied to wireless-drivers-next.git, thanks.

8d95ab34b21e wilc1000: Fix memleak in wilc_sdio_probe

-- 
https://patchwork.kernel.org/patch/11725481/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-08-27 10:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-20  5:48 [PATCH] [v2] wilc1000: Fix memleak in wilc_sdio_probe Dinghao Liu
2020-08-20  5:56 ` Ajay.Kathat
2020-08-25  8:11 ` Claudiu.Beznea
2020-08-27 10:01 ` Kalle Valo

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox