mmc: pxamci: Simplify pxamci_probe() error handling using devm APIs
PATCH v3 1/1 mmc: pxamci: Simplify pxamci_probe() error handling using devm APIs
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.
It also removes redundant NULL assignments and manual resource release logic from pxamci_probe(), and eliminates the corresponding release calls from pxamci_remove().
---
Changes since v2:
- Dropped redundant dma_release_channel() calls from pxamci_remove() as devm_dma_request_chan() automatically handles resource cleanup.
- Added link to v2 for reference:
https://lore.kernel.org/linux-mmc/[email protected]/
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.
- Adopted 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.
- Added link to v1 for reference:
https://lore.kernel.org/linux-mmc/[email protected]/
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 | 56 +++++++++++++-------------------------- 1 file changed, 18 insertions(+), 38 deletions(-)
drivers/mmc/host/pxamci.c +18 -38
@@ -652,10 +652,9 @@ 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" ); host->clkrate =clk_get_rate (host->clk);
@@ -703,46 +702,37 @@ static int pxamci_probe(struct platform_device *pdev)platform_set_drvdata (pdev, mmc); - host->dma_chan_rx =dma_request_chan (dev,"rx" ); -if (IS_ERR (host->dma_chan_rx)) { - host->dma_chan_rx =NULL ; + host->dma_chan_rx =devm_dma_request_chan (dev,"rx" ); +if (IS_ERR (host->dma_chan_rx))return dev_err_probe (dev,PTR_ERR (host->dma_chan_rx),"unable to request rx dma channel\n" ); - } - host->dma_chan_tx =dma_request_chan (dev,"tx" ); -if (IS_ERR (host->dma_chan_tx)) { -dev_err (dev,"unable to request tx dma channel\n" ); - ret =PTR_ERR (host->dma_chan_tx); - host->dma_chan_tx =NULL ; - goto out; - } + + host->dma_chan_tx =devm_dma_request_chan (dev,"tx" ); +if (IS_ERR (host->dma_chan_tx)) +return dev_err_probe (dev,PTR_ERR (host->dma_chan_tx), +"unable to request tx dma channel\n" );if (host->pdata) { host->detect_delay_ms = host->pdata->detect_delay_ms; host->power =devm_gpiod_get_optional (dev,"power" ,GPIOD_OUT_LOW ); -if (IS_ERR (host->power)) { - ret =PTR_ERR (host->power); -dev_err (dev,"Failed requesting gpio_power\n" ); - goto out; - } +if (IS_ERR (host->power)) +return dev_err_probe (dev,PTR_ERR (host->power), +"Failed requesting gpio_power\n" );/* FIXME: should we pass detection delay to debounce? */ ret =mmc_gpiod_request_cd (mmc,"cd" ,0 , false,0 ); -if (ret && ret != -ENOENT ) { -dev_err (dev,"Failed requesting gpio_cd\n" ); - goto out; - } +if (ret && ret != -ENOENT ) +return dev_err_probe (dev, ret,"Failed requesting gpio_cd\n" );if (!host->pdata->gpio_card_ro_invert) mmc->caps2 |=MMC_CAP2_RO_ACTIVE_HIGH ; ret =mmc_gpiod_request_ro (mmc,"wp" ,0 ,0 ); -if (ret && ret != -ENOENT ) { -dev_err (dev,"Failed requesting gpio_ro\n" ); - goto out; - } +if (ret && ret != -ENOENT ) +return dev_err_probe (dev, ret,"Failed requesting gpio_ro\n" ); +if (!ret) host->use_ro_gpio = true;
@@ -759,16 +749,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);return ret; }
@@ -791,8 +773,6 @@ static void pxamci_remove(struct platform_device *pdev)dmaengine_terminate_all (host->dma_chan_rx);dmaengine_terminate_all (host->dma_chan_tx); -dma_release_channel (host->dma_chan_rx); -dma_release_channel (host->dma_chan_tx); } }
Signature · 1 line
2.48.1
Quoted 8 lines · Rakuram Eswaran
This patch refactors
pxamci_probe()to use devm-managed resource allocation (e.g.devm_dma_request_chan) anddev_err_probe()for improved readability and automatic cleanup on probe failure.It also removes redundant NULL assignments and manual resource release logic from
pxamci_probe(), and eliminates the corresponding release calls frompxamci_remove().
Quoted 7 lines
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Fixes 58c40f3faf742c ("mmc: pxamci: Use devm_mmc_alloc_host() helper")Suggested-by Uwe Kleine-König <[email protected]>Signed-off-by Rakuram Eswaran <[email protected]>---
This looks good to me now.
--
Khalid
Quoted 143 lines
Changes since v2:
- Dropped redundantdma_release_channel()calls frompxamci_remove()asdevm_dma_request_chan()automatically handles resource cleanup.
- Added link to v2 for reference:https://lore.kernel.org/linux-mmc/[email protected]/Changes since v1:
Following Uwe Kleine-König’s suggestion:
- Replaceddma_request_chan()withdevm_dma_request_chan()to make DMA channel allocation devm-managed and avoid manual release paths.
- Adopteddev_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.
- Added link to v1 for reference:https://lore.kernel.org/linux-mmc/[email protected]/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) usings390x-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.cdrivers/mmc/host/pxamci.c | 56 +++++++++++++-------------------------- 1 file changed, 18 insertions(+), 38 deletions(-)drivers/mmc/host/pxamci.c +18
-38@@ -652,10 +652,9 @@ 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" ); host->clkrate =clk_get_rate (host->clk);@@ -703,46 +702,37 @@ static int pxamci_probe(struct platform_device *pdev)platform_set_drvdata (pdev, mmc); - host->dma_chan_rx =dma_request_chan (dev,"rx" ); -if (IS_ERR (host->dma_chan_rx)) { - host->dma_chan_rx =NULL ; + host->dma_chan_rx =devm_dma_request_chan (dev,"rx" ); +if (IS_ERR (host->dma_chan_rx))return dev_err_probe (dev,PTR_ERR (host->dma_chan_rx),"unable to request rx dma channel\n" ); - } - host->dma_chan_tx =dma_request_chan (dev,"tx" ); -if (IS_ERR (host->dma_chan_tx)) { -dev_err (dev,"unable to request tx dma channel\n" ); - ret =PTR_ERR (host->dma_chan_tx); - host->dma_chan_tx =NULL ; - goto out; - } + + host->dma_chan_tx =devm_dma_request_chan (dev,"tx" ); +if (IS_ERR (host->dma_chan_tx)) +return dev_err_probe (dev,PTR_ERR (host->dma_chan_tx), +"unable to request tx dma channel\n" );if (host->pdata) { host->detect_delay_ms = host->pdata->detect_delay_ms; host->power =devm_gpiod_get_optional (dev,"power" ,GPIOD_OUT_LOW ); -if (IS_ERR (host->power)) { - ret =PTR_ERR (host->power); -dev_err (dev,"Failed requesting gpio_power\n" ); - goto out; - } +if (IS_ERR (host->power)) +return dev_err_probe (dev,PTR_ERR (host->power), +"Failed requesting gpio_power\n" );/* FIXME: should we pass detection delay to debounce? */ ret =mmc_gpiod_request_cd (mmc,"cd" ,0 , false,0 ); -if (ret && ret != -ENOENT ) { -dev_err (dev,"Failed requesting gpio_cd\n" ); - goto out; - } +if (ret && ret != -ENOENT ) +return dev_err_probe (dev, ret,"Failed requesting gpio_cd\n" );if (!host->pdata->gpio_card_ro_invert) mmc->caps2 |=MMC_CAP2_RO_ACTIVE_HIGH ; ret =mmc_gpiod_request_ro (mmc,"wp" ,0 ,0 ); -if (ret && ret != -ENOENT ) { -dev_err (dev,"Failed requesting gpio_ro\n" ); - goto out; - } +if (ret && ret != -ENOENT ) +return dev_err_probe (dev, ret,"Failed requesting gpio_ro\n" ); +if (!ret) host->use_ro_gpio = true;@@ -759,16 +749,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);return ret; }@@ -791,8 +773,6 @@ static void pxamci_remove(struct platform_device *pdev)dmaengine_terminate_all (host->dma_chan_rx);dmaengine_terminate_all (host->dma_chan_tx); -dma_release_channel (host->dma_chan_rx); -dma_release_channel (host->dma_chan_tx); } }
Hello,
Quoted 8 lines · Rakuram Eswaran
This patch refactors
pxamci_probe()to use devm-managed resource allocation (e.g.devm_dma_request_chan) anddev_err_probe()for improved readability and automatic cleanup on probe failure.It also removes redundant NULL assignments and manual resource release logic from
pxamci_probe(), and eliminates the corresponding release calls frompxamci_remove().
Quoted 6 lines
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Fixes 58c40f3faf742c ("mmc: pxamci: Use devm_mmc_alloc_host() helper")Suggested-by Uwe Kleine-König <[email protected]>Signed-off-by Rakuram Eswaran <[email protected]>
LGTM, thanks
Best regards
Uwe
Quoted 9 lines · Rakuram Eswaran
This patch refactors
pxamci_probe()to use devm-managed resource allocation (e.g.devm_dma_request_chan) anddev_err_probe()for improved readability and automatic cleanup on probe failure.It also removes redundant NULL assignments and manual resource release logic from
pxamci_probe(), and eliminates the corresponding release calls frompxamci_remove().
Quoted 6 lines
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Fixes 58c40f3faf742c ("mmc: pxamci: Use devm_mmc_alloc_host() helper")Suggested-by Uwe Kleine-König <[email protected]>Signed-off-by Rakuram Eswaran <[email protected]>
Applied for fixes, thanks!
Kind regards
Uffe
Quoted 147 lines
---
Changes since v2:
- Dropped redundantdma_release_channel()calls frompxamci_remove()asdevm_dma_request_chan()automatically handles resource cleanup.
- Added link to v2 for reference:
https://lore.kernel.org/linux-mmc/[email protected]/Changes since v1:
Following Uwe Kleine-König’s suggestion:
- Replaceddma_request_chan()withdevm_dma_request_chan()to make DMA channel allocation devm-managed and avoid manual release paths.
- Adopteddev_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.
- Added link to v1 for reference:
https://lore.kernel.org/linux-mmc/[email protected]/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) usings390x-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.cdrivers/mmc/host/pxamci.c | 56 +++++++++++++-------------------------- 1 file changed, 18 insertions(+), 38 deletions(-)drivers/mmc/host/pxamci.c +18
-39@@ -652,10 +652,9 @@ 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" ); host->clkrate =clk_get_rate (host->clk);@@ -703,46 +702,37 @@ static int pxamci_probe(struct platform_device *pdev)platform_set_drvdata (pdev, mmc); - host->dma_chan_rx =dma_request_chan (dev,"rx" ); -if (IS_ERR (host->dma_chan_rx)) { - host->dma_chan_rx =NULL ; + host->dma_chan_rx =devm_dma_request_chan (dev,"rx" ); +if (IS_ERR (host->dma_chan_rx))return dev_err_probe (dev,PTR_ERR (host->dma_chan_rx),"unable to request rx dma channel\n" ); - } - host->dma_chan_tx =dma_request_chan (dev,"tx" ); -if (IS_ERR (host->dma_chan_tx)) { -dev_err (dev,"unable to request tx dma channel\n" ); - ret =PTR_ERR (host->dma_chan_tx); - host->dma_chan_tx =NULL ; - goto out; - } + + host->dma_chan_tx =devm_dma_request_chan (dev,"tx" ); +if (IS_ERR (host->dma_chan_tx)) +return dev_err_probe (dev,PTR_ERR (host->dma_chan_tx), +"unable to request tx dma channel\n" );if (host->pdata) { host->detect_delay_ms = host->pdata->detect_delay_ms; host->power =devm_gpiod_get_optional (dev,"power" ,GPIOD_OUT_LOW ); -if (IS_ERR (host->power)) { - ret =PTR_ERR (host->power); -dev_err (dev,"Failed requesting gpio_power\n" ); - goto out; - } +if (IS_ERR (host->power)) +return dev_err_probe (dev,PTR_ERR (host->power), +"Failed requesting gpio_power\n" );/* FIXME: should we pass detection delay to debounce? */ ret =mmc_gpiod_request_cd (mmc,"cd" ,0 , false,0 ); -if (ret && ret != -ENOENT ) { -dev_err (dev,"Failed requesting gpio_cd\n" ); - goto out; - } +if (ret && ret != -ENOENT ) +return dev_err_probe (dev, ret,"Failed requesting gpio_cd\n" );if (!host->pdata->gpio_card_ro_invert) mmc->caps2 |=MMC_CAP2_RO_ACTIVE_HIGH ; ret =mmc_gpiod_request_ro (mmc,"wp" ,0 ,0 ); -if (ret && ret != -ENOENT ) { -dev_err (dev,"Failed requesting gpio_ro\n" ); - goto out; - } +if (ret && ret != -ENOENT ) +return dev_err_probe (dev, ret,"Failed requesting gpio_ro\n" ); +if (!ret) host->use_ro_gpio = true;@@ -759,16 +749,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);return ret; }@@ -791,8 +773,6 @@ static void pxamci_remove(struct platform_device *pdev)dmaengine_terminate_all (host->dma_chan_rx);dmaengine_terminate_all (host->dma_chan_tx); -dma_release_channel (host->dma_chan_rx); -dma_release_channel (host->dma_chan_tx); } } --2.48.1
Quoted 18 lines · Ulf Hansson
Quoted 9 lines · Rakuram Eswaran
This patch refactors
pxamci_probe()to use devm-managed resource allocation (e.g.devm_dma_request_chan) anddev_err_probe()for improved readability and automatic cleanup on probe failure.It also removes redundant NULL assignments and manual resource release logic from
pxamci_probe(), and eliminates the corresponding release calls frompxamci_remove().Quoted 6 lines
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Fixes 58c40f3faf742c ("mmc: pxamci: Use devm_mmc_alloc_host() helper")Suggested-by Uwe Kleine-König <[email protected]>Signed-off-by Rakuram Eswaran <[email protected]>
Quoted 5 lines
Applied for fixes, thanks!
Kind regards
Uffe
Hi Ulf Hansson,
Thank you for applying to fixes branch.
Hi Uwe,
Shall I start to send the patch to remove the redundant if condition check from pxamic_remove() function?
Link to prior discussion:
https://lore.kernel.org/linux-mmc/pvid2ycmgbkbmegnnzwl4hyev6e2smusxk5olkuqxfwxzykz2e@jlvolirolrxl/
I can pull Uffe fixes branch to send the above patch? Any inputs will be really helpful to start working on this.
Another point, I would like to ask is about the below discussion. You have mentioned about WIP suggestion for clk_get_rate().
Link to that discussion:
https://lore.kernel.org/linux-mmc/[email protected]/
Was my understanding is correct?
Best Regards,
Rakuram
Hello Rakuram,
Quoted 5 lines · Rakuram Eswaran
Shall I start to send the patch to remove the redundant if condition check from
pxamic_remove()function?
[...]
I can pull Uffe fixes branch to send the above patch? Any inputs will be really helpful to start working on this.
It's sensible to build on top of your previous patch, yes. If you do that by using next as development tree once Ulf's commit made it into there, or if you apply it yourself (and then use git format-patch --base correctly) doesn't matter much.
Quoted 7 lines
Another point, I would like to ask is about the below discussion. You have mentioned about WIP suggestion for
clk_get_rate().Link to that discussion:
https://lore.kernel.org/linux-mmc/[email protected]/Was my understanding is correct?
I think so. In my understanding clk_get_rate() must only called for an enabled clock. (Though the wording in include/linux/clk.h is a bit ambigous. It says: "[the returned clock rate] is only valid once the clock source has been enabled." That can mean "The return value doesn't mean anything when called for a disabled clock." or "The returned rate is the real one once the clock is enabled." Some time ago I tried to improve the wording, but IIRC I didn't get relevant feedback on my patch. Assuming the former semantic is safe for sure.
Best regards
Uwe
Quoted 10 lines · Uwe Kleine-König
Hello Rakuram,
Quoted 5 lines · Rakuram Eswaran
Shall I start to send the patch to remove the redundant if condition check from
pxamic_remove()function?
[...]
I can pull Uffe fixes branch to send the above patch? Any inputs will be really helpful to start working on this.
Quoted 5 lines
It's sensible to build on top of your previous patch, yes. If you do that by using next as development tree once Ulf's commit made it into there, or if you apply it yourself (and then use
git format-patch --basecorrectly) doesn't matter much.
Ok, Uwe. Previous patch is already made it to linux-next branch. I will send the patch for this on top of next.
I will make sure to run this command git format-patch --base before sending.
Quoted 8 lines
Quoted 7 lines
Another point, I would like to ask is about the below discussion. You have mentioned about WIP suggestion for
clk_get_rate().Link to that discussion:
https://lore.kernel.org/linux-mmc/[email protected]/Was my understanding is correct?
Quoted 9 lines
I think so. In my understanding
clk_get_rate()must only called for an enabled clock. (Though the wording ininclude/linux/clk.his a bit ambigous. It says: "[the returned clock rate] is only valid once the clock source has been enabled." That can mean "The return value doesn't mean anything when called for a disabled clock." or "The returned rate is the real one once the clock is enabled." Some time ago I tried to improve the wording, but IIRC I didn't get relevant feedback on my patch. Assuming the former semantic is safe for sure.
On this one, I'll look into other implementation on how they handled it in sometime.
Best Regards,
Rakuram
Quoted 12 lines · Rakuram Eswaran
Quoted 10 lines · Uwe Kleine-König
Hello Rakuram,
Quoted 5 lines · Rakuram Eswaran
Shall I start to send the patch to remove the redundant if condition check from
pxamic_remove()function?
[...]
I can pull Uffe fixes branch to send the above patch? Any inputs will be really helpful to start working on this.
Quoted 8 lines
Quoted 5 lines
It's sensible to build on top of your previous patch, yes. If you do that by using next as development tree once Ulf's commit made it into there, or if you apply it yourself (and then use
git format-patch --basecorrectly) doesn't matter much.Ok, Uwe. Previous patch is already made it to linux-next branch. I will send the patch for this on top of next.
If you are working on mmc I strongly recommend to base your patches on top of:
git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git next
As is described in the MAINTAINERS file.
[...]
Kind regards
Uffe