[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <o55ujlbvxwezsf3ogqx33pcbg5b2lviy6bv5ufnz6t7yi4v23t@i6uiafh6no6c>
Date: Thu, 16 Oct 2025 10:50:44 +0200
From: Uwe Kleine-König <u.kleine-koenig@...libre.com>
To: Rakuram Eswaran <rakuram.e96@...il.com>
Cc: ulf.hansson@...aro.org, chenhuacai@...nel.org,
david.hunter.linux@...il.com, khalid@...nel.org, skhan@...uxfoundation.org,
zhoubinbin@...ngson.cn, linux-kernel-mentees@...ts.linux.dev,
linux-kernel@...r.kernel.org, linux-mmc@...r.kernel.org, kernel test robot <lkp@...el.com>,
Dan Carpenter <dan.carpenter@...aro.org>
Subject: Re: [PATCH v2] mmc: pxamci: Simplify pxamci_probe() error handling
using devm APIs
On Wed, Oct 15, 2025 at 12:16:57AM +0530, Rakuram Eswaran wrote:
> This patch refactors pxamci_probe() to use devm-managed resource
> allocation (e.g. devm_dma_request_chan()) and dev_err_probe() for
> improved readability and automatic cleanup on probe failure.
>
> This eliminates redundant NULL assignments and manual release logic.
>
> This issue was originally reported by Smatch:
> drivers/mmc/host/pxamci.c:709 pxamci_probe() warn: passing zero to 'PTR_ERR'
>
> The warning occurred because a pointer was set to NULL before using
> PTR_ERR(), leading to PTR_ERR(0) and an incorrect 0 return value.
> This refactor eliminates that condition while improving overall
> error handling robustness.
>
> Reported-by: kernel test robot <lkp@...el.com>
> Reported-by: Dan Carpenter <dan.carpenter@...aro.org>
> Closes: https://lore.kernel.org/r/202510041841.pRlunIfl-lkp@intel.com/
> Fixes: 58c40f3faf742c ("mmc: pxamci: Use devm_mmc_alloc_host() helper")
> Suggested-by: Uwe Kleine-König <u.kleine-koenig@...libre.com>
> Signed-off-by: Rakuram Eswaran <rakuram.e96@...il.com>
> ---
>
> Changes since v1:
> Following Uwe Kleine-König’s suggestion:
> - Replaced dma_request_chan() with devm_dma_request_chan() to make DMA
> channel allocation devm-managed and avoid manual release paths.
> - Used dev_err_probe() for improved error reporting and consistent
> probe failure handling.
> - Removed redundant NULL assignments and obsolete goto-based cleanup logic.
> - Updated commit message to better describe the intent of the change.
>
> Testing note:
> I do not have access to appropriate hardware for runtime testing.
> Any help verifying on actual hardware would be appreciated.
>
> Build and Analysis:
> This patch was compiled against the configuration file reported by
> 0day CI in the above link (config: s390-randconfig-r071-20251004) using
> `s390x-linux-gnu-gcc (Ubuntu 14.2.0-19ubuntu2) 14.2.0`.
>
> Static analysis was performed with Smatch to ensure the reported warning
> no longer reproduces after applying this fix.
>
> Command used for verification:
> ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- \
> ~/project/smatch/smatch_scripts/kchecker ./drivers/mmc/host/pxamci.c
>
> drivers/mmc/host/pxamci.c | 57 +++++++++++++++------------------------
> 1 file changed, 21 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
> index 26d03352af63..d03388f64934 100644
> --- a/drivers/mmc/host/pxamci.c
> +++ b/drivers/mmc/host/pxamci.c
> @@ -652,11 +652,14 @@ static int pxamci_probe(struct platform_device *pdev)
> host->clkrt = CLKRT_OFF;
>
> host->clk = devm_clk_get(dev, NULL);
> - if (IS_ERR(host->clk)) {
> - host->clk = NULL;
> - return PTR_ERR(host->clk);
> - }
> + if (IS_ERR(host->clk))
> + return dev_err_probe(dev, PTR_ERR(host->clk),
> + "Failed to acquire clock\n");
>
> + /*
> + * Note that the return value of clk_get_rate() is only valid
> + * if the clock is enabled.
> + */
The intention of this comment in my WIP suggestion was to point out
another thing to fix as the precondition for calling clk_get_rate()
isn't asserted. If you don't want to address this (which is fine),
drop the comment (or improve my wording to make it more obvious that
there is something to fix).
> host->clkrate = clk_get_rate(host->clk);
>
> /*
> [...]
> @@ -759,16 +752,8 @@ static int pxamci_probe(struct platform_device *pdev)
> if (ret) {
> if (host->pdata && host->pdata->exit)
> host->pdata->exit(dev, mmc);
> - goto out;
> }
>
> - return 0;
> -
> -out:
> - if (host->dma_chan_rx)
> - dma_release_channel(host->dma_chan_rx);
> - if (host->dma_chan_tx)
> - dma_release_channel(host->dma_chan_tx);
I was lazy in my prototype patch and didn't drop the calls to
dma_release_channel() in pxamci_remove(). For a proper patch this is
required though.
To continue the quest: Now that I looked at pxamci_remove(): `mmc` is
always non-NULL, so the respective check can be dropped.
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists