[v2,60/61] mmc: sdhci_am654: Properly handle failures in .remove()

Message ID 20230726040041.26267-60-frank.li@vivo.com
State New
Headers
Series [v2,01/61] mmc: sunxi: Convert to platform remove callback returning void |

Commit Message

李扬韬 July 26, 2023, 4 a.m. UTC
  Returning an error code in a platform driver's remove function is wrong
most of the time and there is an effort to make the callback return
void. To prepare this rework the function not to exit early.

Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 drivers/mmc/host/sdhci_am654.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Uwe Kleine-König July 26, 2023, 7:02 a.m. UTC | #1
On Wed, Jul 26, 2023 at 12:00:40PM +0800, Yangtao Li wrote:
> Returning an error code in a platform driver's remove function is wrong
> most of the time and there is an effort to make the callback return
> void. To prepare this rework the function not to exit early.
> 
> Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>  drivers/mmc/host/sdhci_am654.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c
> index 7cdf0f54e3a5..abe83736d396 100644
> --- a/drivers/mmc/host/sdhci_am654.c
> +++ b/drivers/mmc/host/sdhci_am654.c
> @@ -873,8 +873,7 @@ static int sdhci_am654_remove(struct platform_device *pdev)
>  	int ret;
>  
>  	ret = pm_runtime_resume_and_get(&pdev->dev);
> -	if (ret < 0)
> -		return ret;
> +	WARN_ON(ret < 0);

You must use pm_runtime_get_sync() instead of
pm_runtime_resume_and_get() here because in the error case
pm_runtime_resume_and_get() already calls pm_runtime_put_noidle() which
is repeated here in this driver.

Also WARN_ON is a pretty big hammer, I'd go with a dev_err() instead.

Best regards
Uwe
  

Patch

diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c
index 7cdf0f54e3a5..abe83736d396 100644
--- a/drivers/mmc/host/sdhci_am654.c
+++ b/drivers/mmc/host/sdhci_am654.c
@@ -873,8 +873,7 @@  static int sdhci_am654_remove(struct platform_device *pdev)
 	int ret;
 
 	ret = pm_runtime_resume_and_get(&pdev->dev);
-	if (ret < 0)
-		return ret;
+	WARN_ON(ret < 0);
 
 	sdhci_remove_host(host, true);
 	clk_disable_unprepare(pltfm_host->clk);