diff mbox series

[v2] wilc1000: Fix memleak in wilc_bus_probe

Message ID 20200820055256.24333-1-dinghao.liu@zju.edu.cn (mailing list archive)
State Accepted
Commit 9a19a939abfa7d949f584a7ad872e683473fdc14
Delegated to: Kalle Valo
Headers show
Series [v2] wilc1000: Fix memleak in wilc_bus_probe | expand

Commit Message

Dinghao Liu Aug. 20, 2020, 5:52 a.m. UTC
When devm_clk_get() returns -EPROBE_DEFER, spi_priv
should be freed just like when wilc_cfg80211_init()
fails.

Fixes: 854d66df74aed ("staging: wilc1000: look for rtc_clk clock in spi mode")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---

Changelog:

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

Comments

Ajay Singh Aug. 20, 2020, 5:58 a.m. UTC | #1
On 20/08/20 11:22 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, spi_priv
> should be freed just like when wilc_cfg80211_init()
> fails.
> 
> Fixes: 854d66df74aed ("staging: wilc1000: look for rtc_clk clock in spi mode")
> 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/spi.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c
> index 3f19e3f38a39..a18dac0aa6b6 100644
> --- a/drivers/net/wireless/microchip/wilc1000/spi.c
> +++ b/drivers/net/wireless/microchip/wilc1000/spi.c
> @@ -112,9 +112,10 @@ static int wilc_bus_probe(struct spi_device *spi)
>         wilc->dev_irq_num = spi->irq;
> 
>         wilc->rtc_clk = devm_clk_get(&spi->dev, "rtc_clk");
> -       if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER)
> +       if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) {
> +               kfree(spi_priv);
>                 return -EPROBE_DEFER;
> -       else if (!IS_ERR(wilc->rtc_clk))
> +       } else if (!IS_ERR(wilc->rtc_clk))
>                 clk_prepare_enable(wilc->rtc_clk);
> 
>         return 0;
> --
> 2.17.1
>
Claudiu Beznea Aug. 25, 2020, 8:12 a.m. UTC | #2
Hi Dinghao,

On 20.08.2020 08:52, 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, spi_priv
> should be freed just like when wilc_cfg80211_init()
> fails.
> 
> Fixes: 854d66df74aed ("staging: wilc1000: look for rtc_clk clock in spi mode")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
> 
> Changelog:
> 
> v2: - Remove 'staging' prefix in subject.
> ---
>  drivers/net/wireless/microchip/wilc1000/spi.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c
> index 3f19e3f38a39..a18dac0aa6b6 100644
> --- a/drivers/net/wireless/microchip/wilc1000/spi.c
> +++ b/drivers/net/wireless/microchip/wilc1000/spi.c
> @@ -112,9 +112,10 @@ static int wilc_bus_probe(struct spi_device *spi)
>         wilc->dev_irq_num = spi->irq;
> 
>         wilc->rtc_clk = devm_clk_get(&spi->dev, "rtc_clk");
> -       if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER)
> +       if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) {
> +               kfree(spi_priv);

Same here as in the reply to patch "wilc1000: Fix memleak in wilc_sdio_probe".

>                 return -EPROBE_DEFER;
> -       else if (!IS_ERR(wilc->rtc_clk))
> +       } else if (!IS_ERR(wilc->rtc_clk))
>                 clk_prepare_enable(wilc->rtc_clk);
> 
>         return 0;
> --
> 2.17.1
>
Kalle Valo Aug. 27, 2020, 10:03 a.m. UTC | #3
Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:

> When devm_clk_get() returns -EPROBE_DEFER, spi_priv
> should be freed just like when wilc_cfg80211_init()
> fails.
> 
> Fixes: 854d66df74aed ("staging: wilc1000: look for rtc_clk clock in spi mode")
> 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.

9a19a939abfa wilc1000: Fix memleak in wilc_bus_probe
diff mbox series

Patch

diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c
index 3f19e3f38a39..a18dac0aa6b6 100644
--- a/drivers/net/wireless/microchip/wilc1000/spi.c
+++ b/drivers/net/wireless/microchip/wilc1000/spi.c
@@ -112,9 +112,10 @@  static int wilc_bus_probe(struct spi_device *spi)
 	wilc->dev_irq_num = spi->irq;
 
 	wilc->rtc_clk = devm_clk_get(&spi->dev, "rtc_clk");
-	if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER)
+	if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) {
+		kfree(spi_priv);
 		return -EPROBE_DEFER;
-	else if (!IS_ERR(wilc->rtc_clk))
+	} else if (!IS_ERR(wilc->rtc_clk))
 		clk_prepare_enable(wilc->rtc_clk);
 
 	return 0;