* [PATCH 1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe()
@ 2022-12-10 18:36 Christophe JAILLET
2022-12-10 18:36 ` [PATCH 2/3] mmc: sunlpus: Fix a memory leak in case of error " Christophe JAILLET
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Christophe JAILLET @ 2022-12-10 18:36 UTC (permalink / raw)
To: Tony Huang, Li-hao Kuo, Ulf Hansson, Arnd Bergmann
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-mmc
If an error occurs after successful clk_prepare_enable() call in the probe,
the clk is not clk_disable_unprepare()'ed.
Use devm_clk_get_enabled() instead of devm_clk_get() to fix, and simplify
the probe and the remove function accordingly.
Fixes: 4e268fed8b18 ("mmc: Add mmc driver for Sunplus SP7021")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This changes the order of resource releasing when the driver is removed,
but it looks ok to me.
---
drivers/mmc/host/sunplus-mmc.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/mmc/host/sunplus-mmc.c b/drivers/mmc/host/sunplus-mmc.c
index db5e0dcdfa7f..3e8856a82188 100644
--- a/drivers/mmc/host/sunplus-mmc.c
+++ b/drivers/mmc/host/sunplus-mmc.c
@@ -878,7 +878,7 @@ static int spmmc_drv_probe(struct platform_device *pdev)
if (IS_ERR(host->base))
return PTR_ERR(host->base);
- host->clk = devm_clk_get(&pdev->dev, NULL);
+ host->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(host->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n");
@@ -896,10 +896,6 @@ static int spmmc_drv_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = clk_prepare_enable(host->clk);
- if (ret)
- return dev_err_probe(&pdev->dev, ret, "failed to enable clk\n");
-
ret = mmc_of_parse(mmc);
if (ret)
goto probe_free_host;
@@ -944,7 +940,6 @@ static int spmmc_drv_remove(struct platform_device *dev)
mmc_remove_host(host->mmc);
pm_runtime_get_sync(&dev->dev);
- clk_disable_unprepare(host->clk);
pm_runtime_put_noidle(&dev->dev);
pm_runtime_disable(&dev->dev);
platform_set_drvdata(dev, NULL);
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] mmc: sunlpus: Fix a memory leak in case of error in spmmc_drv_probe()
2022-12-10 18:36 [PATCH 1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe() Christophe JAILLET
@ 2022-12-10 18:36 ` Christophe JAILLET
2022-12-10 18:36 ` [PATCH 3/3] mmc: sunlpus: Slightly simplify the error ahndling path " Christophe JAILLET
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2022-12-10 18:36 UTC (permalink / raw)
To: Tony Huang, Li-hao Kuo, Ulf Hansson, Arnd Bergmann
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-mmc
If an error occurs after a successful mmc_alloc_host() call in the probe,
the error handling path should be executed in order to call
mmc_free_host().
Fixes: 4e268fed8b18 ("mmc: Add mmc driver for Sunplus SP7021")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/mmc/host/sunplus-mmc.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/drivers/mmc/host/sunplus-mmc.c b/drivers/mmc/host/sunplus-mmc.c
index 3e8856a82188..ed789a9bdd23 100644
--- a/drivers/mmc/host/sunplus-mmc.c
+++ b/drivers/mmc/host/sunplus-mmc.c
@@ -875,26 +875,34 @@ static int spmmc_drv_probe(struct platform_device *pdev)
host->dma_int_threshold = 1024;
host->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
- if (IS_ERR(host->base))
- return PTR_ERR(host->base);
+ if (IS_ERR(host->base)) {
+ ret = PTR_ERR(host->base);
+ goto probe_free_host;
+ }
host->clk = devm_clk_get_enabled(&pdev->dev, NULL);
- if (IS_ERR(host->clk))
- return dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n");
+ if (IS_ERR(host->clk)) {
+ ret = dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n");
+ goto probe_free_host;
+ }
host->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
- if (IS_ERR(host->rstc))
- return dev_err_probe(&pdev->dev, PTR_ERR(host->rstc), "rst get fail\n");
+ if (IS_ERR(host->rstc)) {
+ ret = dev_err_probe(&pdev->dev, PTR_ERR(host->rstc), "rst get fail\n");
+ goto probe_free_host;
+ }
host->irq = platform_get_irq(pdev, 0);
- if (host->irq <= 0)
- return host->irq;
+ if (host->irq <= 0) {
+ ret = host->irq;
+ goto probe_free_host;
+ }
ret = devm_request_threaded_irq(&pdev->dev, host->irq,
spmmc_irq, spmmc_func_finish_req, IRQF_SHARED,
NULL, host);
if (ret)
- return ret;
+ goto probe_free_host;
ret = mmc_of_parse(mmc);
if (ret)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] mmc: sunlpus: Slightly simplify the error ahndling path in spmmc_drv_probe()
2022-12-10 18:36 [PATCH 1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe() Christophe JAILLET
2022-12-10 18:36 ` [PATCH 2/3] mmc: sunlpus: Fix a memory leak in case of error " Christophe JAILLET
@ 2022-12-10 18:36 ` Christophe JAILLET
2022-12-10 18:56 ` [PATCH 1/3] mmc: sunlpus: Fix an error handling " Christophe JAILLET
2023-01-02 12:49 ` Ulf Hansson
3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2022-12-10 18:36 UTC (permalink / raw)
To: Tony Huang, Li-hao Kuo, Ulf Hansson
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-mmc
If mmc_alloc_host() fails, we can return directly.
This saves some LoC, a test and some indentation in the error handling
path.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/mmc/host/sunplus-mmc.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/mmc/host/sunplus-mmc.c b/drivers/mmc/host/sunplus-mmc.c
index ed789a9bdd23..d990b120789d 100644
--- a/drivers/mmc/host/sunplus-mmc.c
+++ b/drivers/mmc/host/sunplus-mmc.c
@@ -864,10 +864,8 @@ static int spmmc_drv_probe(struct platform_device *pdev)
int ret = 0;
mmc = mmc_alloc_host(sizeof(*host), &pdev->dev);
- if (!mmc) {
- ret = -ENOMEM;
- goto probe_free_host;
- }
+ if (!mmc)
+ return -ENOMEM;
host = mmc_priv(mmc);
host->mmc = mmc;
@@ -936,8 +934,7 @@ static int spmmc_drv_probe(struct platform_device *pdev)
return ret;
probe_free_host:
- if (mmc)
- mmc_free_host(mmc);
+ mmc_free_host(mmc);
return ret;
}
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe()
2022-12-10 18:36 [PATCH 1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe() Christophe JAILLET
2022-12-10 18:36 ` [PATCH 2/3] mmc: sunlpus: Fix a memory leak in case of error " Christophe JAILLET
2022-12-10 18:36 ` [PATCH 3/3] mmc: sunlpus: Slightly simplify the error ahndling path " Christophe JAILLET
@ 2022-12-10 18:56 ` Christophe JAILLET
2023-01-02 12:49 ` Ulf Hansson
3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2022-12-10 18:56 UTC (permalink / raw)
To: Tony Huang, Li-hao Kuo, Ulf Hansson, Arnd Bergmann
Cc: linux-kernel, kernel-janitors, linux-mmc
Le 10/12/2022 à 19:36, Christophe JAILLET a écrit :
> If an error occurs after successful clk_prepare_enable() call in the probe,
> the clk is not clk_disable_unprepare()'ed.
>
> Use devm_clk_get_enabled() instead of devm_clk_get() to fix, and simplify
> the probe and the remove function accordingly.
>
> Fixes: 4e268fed8b18 ("mmc: Add mmc driver for Sunplus SP7021")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This changes the order of resource releasing when the driver is removed,
> but it looks ok to me.
> ---
> drivers/mmc/host/sunplus-mmc.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
Hi, in the whole serie, the subject was supposed to be sunplus, not sunlpus.
Could also be SP7021, or sunplus-SP7021, or whatever else.
I'll wait for potential comments on the patches themselves before
sending a v2 to fix the subject (and I hope it could be fixed when
applied if there is no comment :))
CJ
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe()
2022-12-10 18:36 [PATCH 1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe() Christophe JAILLET
` (2 preceding siblings ...)
2022-12-10 18:56 ` [PATCH 1/3] mmc: sunlpus: Fix an error handling " Christophe JAILLET
@ 2023-01-02 12:49 ` Ulf Hansson
3 siblings, 0 replies; 5+ messages in thread
From: Ulf Hansson @ 2023-01-02 12:49 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Tony Huang, Li-hao Kuo, Arnd Bergmann, linux-kernel,
kernel-janitors, linux-mmc
On Sat, 10 Dec 2022 at 19:36, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> If an error occurs after successful clk_prepare_enable() call in the probe,
> the clk is not clk_disable_unprepare()'ed.
>
> Use devm_clk_get_enabled() instead of devm_clk_get() to fix, and simplify
> the probe and the remove function accordingly.
>
> Fixes: 4e268fed8b18 ("mmc: Add mmc driver for Sunplus SP7021")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This changes the order of resource releasing when the driver is removed,
> but it looks ok to me.
> ---
> drivers/mmc/host/sunplus-mmc.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/mmc/host/sunplus-mmc.c b/drivers/mmc/host/sunplus-mmc.c
> index db5e0dcdfa7f..3e8856a82188 100644
> --- a/drivers/mmc/host/sunplus-mmc.c
> +++ b/drivers/mmc/host/sunplus-mmc.c
> @@ -878,7 +878,7 @@ static int spmmc_drv_probe(struct platform_device *pdev)
> if (IS_ERR(host->base))
> return PTR_ERR(host->base);
>
> - host->clk = devm_clk_get(&pdev->dev, NULL);
> + host->clk = devm_clk_get_enabled(&pdev->dev, NULL);
> if (IS_ERR(host->clk))
> return dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n");
>
> @@ -896,10 +896,6 @@ static int spmmc_drv_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> - ret = clk_prepare_enable(host->clk);
> - if (ret)
> - return dev_err_probe(&pdev->dev, ret, "failed to enable clk\n");
> -
> ret = mmc_of_parse(mmc);
> if (ret)
> goto probe_free_host;
> @@ -944,7 +940,6 @@ static int spmmc_drv_remove(struct platform_device *dev)
>
> mmc_remove_host(host->mmc);
> pm_runtime_get_sync(&dev->dev);
> - clk_disable_unprepare(host->clk);
I don't think this improves code quality, but rather the opposite.
Removing the call to clk_disable_unprepare() here, makes the untrained
eye, to believe that the calls to pm_runtime_get_sync() and
pm_runtime_put_noidle() are redundant, while they aren't.
Instead, I suggest we add a call to clk_disable_unprepare() in the
error path in ->probe(), rather than using devm_clk_get_enabled().
> pm_runtime_put_noidle(&dev->dev);
> pm_runtime_disable(&dev->dev);
> platform_set_drvdata(dev, NULL);
Kind regards
Uffe
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-01-02 12:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-10 18:36 [PATCH 1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe() Christophe JAILLET
2022-12-10 18:36 ` [PATCH 2/3] mmc: sunlpus: Fix a memory leak in case of error " Christophe JAILLET
2022-12-10 18:36 ` [PATCH 3/3] mmc: sunlpus: Slightly simplify the error ahndling path " Christophe JAILLET
2022-12-10 18:56 ` [PATCH 1/3] mmc: sunlpus: Fix an error handling " Christophe JAILLET
2023-01-02 12:49 ` Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®