linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function
@ 2020-12-17 20:42 Christophe JAILLET
  2020-12-17 22:55 ` Orson Zhai
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christophe JAILLET @ 2020-12-17 20:42 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson, orsonzhai, baolin.wang7, zhang.lyra
  Cc: linux-mmc, linux-kernel, kernel-janitors, Christophe JAILLET

'sdhci_remove_host()' and 'sdhci_pltfm_free()' should be used in place of
'mmc_remove_host()' and 'mmc_free_host()'.

This avoids some resource leaks, is more in line with the error handling
path of the probe function, and is more consistent with other drivers.

Fixes: fb8bd90f83c4 ("mmc: sdhci-sprd: Add Spreadtrum's initial host controller")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Other adjustment may be needed.
I'm not sure at all of the 0 passed to 'sdhci_remove_host()'. Some drivers
pass 0, some have some more complicated computation.
---
 drivers/mmc/host/sdhci-sprd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
index f85171edabeb..5dc36efff47f 100644
--- a/drivers/mmc/host/sdhci-sprd.c
+++ b/drivers/mmc/host/sdhci-sprd.c
@@ -708,14 +708,14 @@ static int sdhci_sprd_remove(struct platform_device *pdev)
 {
 	struct sdhci_host *host = platform_get_drvdata(pdev);
 	struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
-	struct mmc_host *mmc = host->mmc;
 
-	mmc_remove_host(mmc);
+	sdhci_remove_host(host, 0);
+
 	clk_disable_unprepare(sprd_host->clk_sdio);
 	clk_disable_unprepare(sprd_host->clk_enable);
 	clk_disable_unprepare(sprd_host->clk_2x_enable);
 
-	mmc_free_host(mmc);
+	sdhci_pltfm_free(pdev);
 
 	return 0;
 }
-- 
2.27.0


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

* Re: [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function
  2020-12-17 20:42 [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function Christophe JAILLET
@ 2020-12-17 22:55 ` Orson Zhai
  2020-12-18 13:46   ` Christophe JAILLET
  2021-01-05 12:39 ` Adrian Hunter
  2021-01-11 18:05 ` Ulf Hansson
  2 siblings, 1 reply; 6+ messages in thread
From: Orson Zhai @ 2020-12-17 22:55 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: adrian.hunter, Ulf Hansson, Baolin Wang, Lyra Zhang, linux-mmc,
	Linux Kernel Mailing List, kernel-janitors, billows.wu,
	Wu Hongtao

+ cc: Billows

Hi Christophe,
On Fri, Dec 18, 2020 at 4:50 AM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> 'sdhci_remove_host()' and 'sdhci_pltfm_free()' should be used in place of
> 'mmc_remove_host()' and 'mmc_free_host()'.
>
> This avoids some resource leaks, is more in line with the error handling
> path of the probe function, and is more consistent with other drivers.
>
> Fixes: fb8bd90f83c4 ("mmc: sdhci-sprd: Add Spreadtrum's initial host controller")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Other adjustment may be needed.
> I'm not sure at all of the 0 passed to 'sdhci_remove_host()'. Some drivers
> pass 0, some have some more complicated computation.
> ---
>  drivers/mmc/host/sdhci-sprd.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
> index f85171edabeb..5dc36efff47f 100644
> --- a/drivers/mmc/host/sdhci-sprd.c
> +++ b/drivers/mmc/host/sdhci-sprd.c
> @@ -708,14 +708,14 @@ static int sdhci_sprd_remove(struct platform_device *pdev)
>  {
>         struct sdhci_host *host = platform_get_drvdata(pdev);
>         struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
> -       struct mmc_host *mmc = host->mmc;
>
> -       mmc_remove_host(mmc);
> +       sdhci_remove_host(host, 0);
> +
>         clk_disable_unprepare(sprd_host->clk_sdio);
>         clk_disable_unprepare(sprd_host->clk_enable);
>         clk_disable_unprepare(sprd_host->clk_2x_enable);
>
> -       mmc_free_host(mmc);
> +       sdhci_pltfm_free(pdev);

I saw a lot of drivers also use mmc_free_host().
Do you have patches elsewhere to clean them?

Thanks,
-Orson

>
>         return 0;
>  }
> --
> 2.27.0
>

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

* Re: [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function
  2020-12-17 22:55 ` Orson Zhai
@ 2020-12-18 13:46   ` Christophe JAILLET
  2020-12-20  2:05     ` Orson Zhai
  0 siblings, 1 reply; 6+ messages in thread
From: Christophe JAILLET @ 2020-12-18 13:46 UTC (permalink / raw)
  To: Orson Zhai
  Cc: adrian.hunter, Ulf Hansson, Baolin Wang, Lyra Zhang, linux-mmc,
	Linux Kernel Mailing List, kernel-janitors, billows.wu,
	Wu Hongtao

Le 17/12/2020 à 23:55, Orson Zhai a écrit :
> + cc: Billows
> 
> Hi Christophe,
> On Fri, Dec 18, 2020 at 4:50 AM Christophe JAILLET
> <christophe.jaillet@wanadoo.fr> wrote:
>>
>> 'sdhci_remove_host()' and 'sdhci_pltfm_free()' should be used in place of
>> 'mmc_remove_host()' and 'mmc_free_host()'.
>>
>> This avoids some resource leaks, is more in line with the error handling
>> path of the probe function, and is more consistent with other drivers.
>>
>> Fixes: fb8bd90f83c4 ("mmc: sdhci-sprd: Add Spreadtrum's initial host controller")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> Other adjustment may be needed.
>> I'm not sure at all of the 0 passed to 'sdhci_remove_host()'. Some drivers
>> pass 0, some have some more complicated computation.
>> ---
>>   drivers/mmc/host/sdhci-sprd.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
>> index f85171edabeb..5dc36efff47f 100644
>> --- a/drivers/mmc/host/sdhci-sprd.c
>> +++ b/drivers/mmc/host/sdhci-sprd.c
>> @@ -708,14 +708,14 @@ static int sdhci_sprd_remove(struct platform_device *pdev)
>>   {
>>          struct sdhci_host *host = platform_get_drvdata(pdev);
>>          struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
>> -       struct mmc_host *mmc = host->mmc;
>>
>> -       mmc_remove_host(mmc);
>> +       sdhci_remove_host(host, 0);
>> +
>>          clk_disable_unprepare(sprd_host->clk_sdio);
>>          clk_disable_unprepare(sprd_host->clk_enable);
>>          clk_disable_unprepare(sprd_host->clk_2x_enable);
>>
>> -       mmc_free_host(mmc);
>> +       sdhci_pltfm_free(pdev);
> 
> I saw a lot of drivers also use mmc_free_host().
> Do you have patches elsewhere to clean them?
> 

As far as I can see, all drivers that use 'mmc_free_host' also use 
'mmc_alloc_host'. (based on 5.10.1 and unless error)

The only exception is 'sdhci-sprd.c'.

So no, I don't plan any other clean-up.



To spot it, I run one of my own cocci script which compare functions 
called in the remove function and in the error handling path of the probe.

So I caught this one because 'mmc_free_host' is used in the porbe and 
'sdhci_pltfm_free' in the remove function.


CJ

> Thanks,
> -Orson
> 
>>
>>          return 0;
>>   }
>> --
>> 2.27.0
>>
> 


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

* Re: [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function
  2020-12-18 13:46   ` Christophe JAILLET
@ 2020-12-20  2:05     ` Orson Zhai
  0 siblings, 0 replies; 6+ messages in thread
From: Orson Zhai @ 2020-12-20  2:05 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: adrian.hunter, Ulf Hansson, Baolin Wang, Lyra Zhang, linux-mmc,
	Linux Kernel Mailing List, kernel-janitors, billows.wu,
	Wu Hongtao

On Fri, Dec 18, 2020 at 9:46 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> Le 17/12/2020 à 23:55, Orson Zhai a écrit :
> > + cc: Billows
> >
> > Hi Christophe,
> > On Fri, Dec 18, 2020 at 4:50 AM Christophe JAILLET
> > <christophe.jaillet@wanadoo.fr> wrote:
> >>
> >> 'sdhci_remove_host()' and 'sdhci_pltfm_free()' should be used in place of
> >> 'mmc_remove_host()' and 'mmc_free_host()'.
> >>
> >> This avoids some resource leaks, is more in line with the error handling
> >> path of the probe function, and is more consistent with other drivers.
> >>
> >> Fixes: fb8bd90f83c4 ("mmc: sdhci-sprd: Add Spreadtrum's initial host controller")
> >> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> >> ---
> >> Other adjustment may be needed.
> >> I'm not sure at all of the 0 passed to 'sdhci_remove_host()'. Some drivers
> >> pass 0, some have some more complicated computation.
> >> ---
> >>   drivers/mmc/host/sdhci-sprd.c | 6 +++---
> >>   1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
> >> index f85171edabeb..5dc36efff47f 100644
> >> --- a/drivers/mmc/host/sdhci-sprd.c
> >> +++ b/drivers/mmc/host/sdhci-sprd.c
> >> @@ -708,14 +708,14 @@ static int sdhci_sprd_remove(struct platform_device *pdev)
> >>   {
> >>          struct sdhci_host *host = platform_get_drvdata(pdev);
> >>          struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
> >> -       struct mmc_host *mmc = host->mmc;
> >>
> >> -       mmc_remove_host(mmc);
> >> +       sdhci_remove_host(host, 0);
> >> +
> >>          clk_disable_unprepare(sprd_host->clk_sdio);
> >>          clk_disable_unprepare(sprd_host->clk_enable);
> >>          clk_disable_unprepare(sprd_host->clk_2x_enable);
> >>
> >> -       mmc_free_host(mmc);
> >> +       sdhci_pltfm_free(pdev);
> >
> > I saw a lot of drivers also use mmc_free_host().
> > Do you have patches elsewhere to clean them?
> >
>
> As far as I can see, all drivers that use 'mmc_free_host' also use
> 'mmc_alloc_host'. (based on 5.10.1 and unless error)
>
> The only exception is 'sdhci-sprd.c'.
>
> So no, I don't plan any other clean-up.
>
>
>
> To spot it, I run one of my own cocci script which compare functions
> called in the remove function and in the error handling path of the probe.
>
> So I caught this one because 'mmc_free_host' is used in the porbe and
> 'sdhci_pltfm_free' in the remove function.

Thanks for the clarification.

Acked-by: Orson Zhai <orson.zhai@gmail.com>

>
>
> CJ
>
> > Thanks,
> > -Orson
> >
> >>
> >>          return 0;
> >>   }
> >> --
> >> 2.27.0
> >>
> >
>

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

* Re: [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function
  2020-12-17 20:42 [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function Christophe JAILLET
  2020-12-17 22:55 ` Orson Zhai
@ 2021-01-05 12:39 ` Adrian Hunter
  2021-01-11 18:05 ` Ulf Hansson
  2 siblings, 0 replies; 6+ messages in thread
From: Adrian Hunter @ 2021-01-05 12:39 UTC (permalink / raw)
  To: Christophe JAILLET, ulf.hansson, orsonzhai, baolin.wang7, zhang.lyra
  Cc: linux-mmc, linux-kernel, kernel-janitors

On 17/12/20 10:42 pm, Christophe JAILLET wrote:
> 'sdhci_remove_host()' and 'sdhci_pltfm_free()' should be used in place of
> 'mmc_remove_host()' and 'mmc_free_host()'.
> 
> This avoids some resource leaks, is more in line with the error handling
> path of the probe function, and is more consistent with other drivers.
> 
> Fixes: fb8bd90f83c4 ("mmc: sdhci-sprd: Add Spreadtrum's initial host controller")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
> Other adjustment may be needed.
> I'm not sure at all of the 0 passed to 'sdhci_remove_host()'. Some drivers
> pass 0, some have some more complicated computation.

'0' means cleanup nicely. '1' (dead) means nothing works anymore, including
interrupts, so give up on requests immediately.

Either should work.  '0' is better unless your host controller really is
dead, which is mostly not possible except for some legacy PCI devices.

> ---
>  drivers/mmc/host/sdhci-sprd.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
> index f85171edabeb..5dc36efff47f 100644
> --- a/drivers/mmc/host/sdhci-sprd.c
> +++ b/drivers/mmc/host/sdhci-sprd.c
> @@ -708,14 +708,14 @@ static int sdhci_sprd_remove(struct platform_device *pdev)
>  {
>  	struct sdhci_host *host = platform_get_drvdata(pdev);
>  	struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
> -	struct mmc_host *mmc = host->mmc;
>  
> -	mmc_remove_host(mmc);
> +	sdhci_remove_host(host, 0);
> +
>  	clk_disable_unprepare(sprd_host->clk_sdio);
>  	clk_disable_unprepare(sprd_host->clk_enable);
>  	clk_disable_unprepare(sprd_host->clk_2x_enable);
>  
> -	mmc_free_host(mmc);
> +	sdhci_pltfm_free(pdev);
>  
>  	return 0;
>  }
> 


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

* Re: [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function
  2020-12-17 20:42 [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function Christophe JAILLET
  2020-12-17 22:55 ` Orson Zhai
  2021-01-05 12:39 ` Adrian Hunter
@ 2021-01-11 18:05 ` Ulf Hansson
  2 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2021-01-11 18:05 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Adrian Hunter, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-mmc,
	Linux Kernel Mailing List, kernel-janitors

On Thu, 17 Dec 2020 at 21:42, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> 'sdhci_remove_host()' and 'sdhci_pltfm_free()' should be used in place of
> 'mmc_remove_host()' and 'mmc_free_host()'.
>
> This avoids some resource leaks, is more in line with the error handling
> path of the probe function, and is more consistent with other drivers.
>
> Fixes: fb8bd90f83c4 ("mmc: sdhci-sprd: Add Spreadtrum's initial host controller")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Applied for next, thanks!

Kind regards
Uffe


> ---
> Other adjustment may be needed.
> I'm not sure at all of the 0 passed to 'sdhci_remove_host()'. Some drivers
> pass 0, some have some more complicated computation.
> ---
>  drivers/mmc/host/sdhci-sprd.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
> index f85171edabeb..5dc36efff47f 100644
> --- a/drivers/mmc/host/sdhci-sprd.c
> +++ b/drivers/mmc/host/sdhci-sprd.c
> @@ -708,14 +708,14 @@ static int sdhci_sprd_remove(struct platform_device *pdev)
>  {
>         struct sdhci_host *host = platform_get_drvdata(pdev);
>         struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
> -       struct mmc_host *mmc = host->mmc;
>
> -       mmc_remove_host(mmc);
> +       sdhci_remove_host(host, 0);
> +
>         clk_disable_unprepare(sprd_host->clk_sdio);
>         clk_disable_unprepare(sprd_host->clk_enable);
>         clk_disable_unprepare(sprd_host->clk_2x_enable);
>
> -       mmc_free_host(mmc);
> +       sdhci_pltfm_free(pdev);
>
>         return 0;
>  }
> --
> 2.27.0
>

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

end of thread, other threads:[~2021-01-11 18:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 20:42 [PATCH] mmc: sdhci-sprd: Fix some resource leaks in the remove function Christophe JAILLET
2020-12-17 22:55 ` Orson Zhai
2020-12-18 13:46   ` Christophe JAILLET
2020-12-20  2:05     ` Orson Zhai
2021-01-05 12:39 ` Adrian Hunter
2021-01-11 18:05 ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).