Skip to content

Commit 9e80562

Browse files
rakurame96storulf
authored andcommitted
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(). Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/r/202510041841.pRlunIfl-lkp@intel.com/ Fixes: 58c40f3 ("mmc: pxamci: Use devm_mmc_alloc_host() helper") Suggested-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Signed-off-by: Rakuram Eswaran <rakuram.e96@gmail.com> Reviewed-by: Khalid Aziz <khalid@kernel.org> Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent a28352c commit 9e80562

1 file changed

Lines changed: 18 additions & 38 deletions

File tree

drivers/mmc/host/pxamci.c

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,9 @@ static int pxamci_probe(struct platform_device *pdev)
652652
host->clkrt = CLKRT_OFF;
653653

654654
host->clk = devm_clk_get(dev, NULL);
655-
if (IS_ERR(host->clk)) {
656-
host->clk = NULL;
657-
return PTR_ERR(host->clk);
658-
}
655+
if (IS_ERR(host->clk))
656+
return dev_err_probe(dev, PTR_ERR(host->clk),
657+
"Failed to acquire clock\n");
659658

660659
host->clkrate = clk_get_rate(host->clk);
661660

@@ -703,46 +702,37 @@ static int pxamci_probe(struct platform_device *pdev)
703702

704703
platform_set_drvdata(pdev, mmc);
705704

706-
host->dma_chan_rx = dma_request_chan(dev, "rx");
707-
if (IS_ERR(host->dma_chan_rx)) {
708-
host->dma_chan_rx = NULL;
705+
host->dma_chan_rx = devm_dma_request_chan(dev, "rx");
706+
if (IS_ERR(host->dma_chan_rx))
709707
return dev_err_probe(dev, PTR_ERR(host->dma_chan_rx),
710708
"unable to request rx dma channel\n");
711-
}
712709

713-
host->dma_chan_tx = dma_request_chan(dev, "tx");
714-
if (IS_ERR(host->dma_chan_tx)) {
715-
dev_err(dev, "unable to request tx dma channel\n");
716-
ret = PTR_ERR(host->dma_chan_tx);
717-
host->dma_chan_tx = NULL;
718-
goto out;
719-
}
710+
711+
host->dma_chan_tx = devm_dma_request_chan(dev, "tx");
712+
if (IS_ERR(host->dma_chan_tx))
713+
return dev_err_probe(dev, PTR_ERR(host->dma_chan_tx),
714+
"unable to request tx dma channel\n");
720715

721716
if (host->pdata) {
722717
host->detect_delay_ms = host->pdata->detect_delay_ms;
723718

724719
host->power = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
725-
if (IS_ERR(host->power)) {
726-
ret = PTR_ERR(host->power);
727-
dev_err(dev, "Failed requesting gpio_power\n");
728-
goto out;
729-
}
720+
if (IS_ERR(host->power))
721+
return dev_err_probe(dev, PTR_ERR(host->power),
722+
"Failed requesting gpio_power\n");
730723

731724
/* FIXME: should we pass detection delay to debounce? */
732725
ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0);
733-
if (ret && ret != -ENOENT) {
734-
dev_err(dev, "Failed requesting gpio_cd\n");
735-
goto out;
736-
}
726+
if (ret && ret != -ENOENT)
727+
return dev_err_probe(dev, ret, "Failed requesting gpio_cd\n");
737728

738729
if (!host->pdata->gpio_card_ro_invert)
739730
mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
740731

741732
ret = mmc_gpiod_request_ro(mmc, "wp", 0, 0);
742-
if (ret && ret != -ENOENT) {
743-
dev_err(dev, "Failed requesting gpio_ro\n");
744-
goto out;
745-
}
733+
if (ret && ret != -ENOENT)
734+
return dev_err_probe(dev, ret, "Failed requesting gpio_ro\n");
735+
746736
if (!ret)
747737
host->use_ro_gpio = true;
748738

@@ -759,16 +749,8 @@ static int pxamci_probe(struct platform_device *pdev)
759749
if (ret) {
760750
if (host->pdata && host->pdata->exit)
761751
host->pdata->exit(dev, mmc);
762-
goto out;
763752
}
764753

765-
return 0;
766-
767-
out:
768-
if (host->dma_chan_rx)
769-
dma_release_channel(host->dma_chan_rx);
770-
if (host->dma_chan_tx)
771-
dma_release_channel(host->dma_chan_tx);
772754
return ret;
773755
}
774756

@@ -791,8 +773,6 @@ static void pxamci_remove(struct platform_device *pdev)
791773

792774
dmaengine_terminate_all(host->dma_chan_rx);
793775
dmaengine_terminate_all(host->dma_chan_tx);
794-
dma_release_channel(host->dma_chan_rx);
795-
dma_release_channel(host->dma_chan_tx);
796776
}
797777
}
798778

0 commit comments

Comments
 (0)