Skip to content

Commit f42abc7

Browse files
lunnJason Cooper
authored andcommitted
mmc: mvsdio: use devm_ API to simplify/correct error paths.
There are a number of bugs in the error paths of this driver. Make use of devm_ functions to simplify the cleanup on error. Based on a patch by Russell King. Signed-off-by: Andrew Lunn <[email protected]> Signed-off-by: Jason Cooper <[email protected]>
1 parent d6f620a commit f42abc7

File tree

1 file changed

+30
-62
lines changed

1 file changed

+30
-62
lines changed

drivers/mmc/host/mvsdio.c

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ struct mvsd_host {
5050
struct timer_list timer;
5151
struct mmc_host *mmc;
5252
struct device *dev;
53-
struct resource *res;
54-
int irq;
5553
struct clk *clk;
5654
int gpio_card_detect;
5755
int gpio_write_protect;
@@ -718,10 +716,6 @@ static int __init mvsd_probe(struct platform_device *pdev)
718716
if (!r || irq < 0 || !mvsd_data)
719717
return -ENXIO;
720718

721-
r = request_mem_region(r->start, SZ_1K, DRIVER_NAME);
722-
if (!r)
723-
return -EBUSY;
724-
725719
mmc = mmc_alloc_host(sizeof(struct mvsd_host), &pdev->dev);
726720
if (!mmc) {
727721
ret = -ENOMEM;
@@ -731,8 +725,8 @@ static int __init mvsd_probe(struct platform_device *pdev)
731725
host = mmc_priv(mmc);
732726
host->mmc = mmc;
733727
host->dev = &pdev->dev;
734-
host->res = r;
735728
host->base_clock = mvsd_data->clock / 2;
729+
host->clk = ERR_PTR(-EINVAL);
736730

737731
mmc->ops = &mvsd_ops;
738732

@@ -752,7 +746,7 @@ static int __init mvsd_probe(struct platform_device *pdev)
752746

753747
spin_lock_init(&host->lock);
754748

755-
host->base = ioremap(r->start, SZ_4K);
749+
host->base = devm_request_and_ioremap(&pdev->dev, r);
756750
if (!host->base) {
757751
ret = -ENOMEM;
758752
goto out;
@@ -765,44 +759,45 @@ static int __init mvsd_probe(struct platform_device *pdev)
765759

766760
mvsd_power_down(host);
767761

768-
ret = request_irq(irq, mvsd_irq, 0, DRIVER_NAME, host);
762+
ret = devm_request_irq(&pdev->dev, irq, mvsd_irq, 0, DRIVER_NAME, host);
769763
if (ret) {
770764
pr_err("%s: cannot assign irq %d\n", DRIVER_NAME, irq);
771765
goto out;
772-
} else
773-
host->irq = irq;
766+
}
774767

775768
/* Not all platforms can gate the clock, so it is not
776769
an error if the clock does not exists. */
777-
host->clk = clk_get(&pdev->dev, NULL);
778-
if (!IS_ERR(host->clk)) {
770+
host->clk = devm_clk_get(&pdev->dev, NULL);
771+
if (!IS_ERR(host->clk))
779772
clk_prepare_enable(host->clk);
780-
}
781773

782774
if (mvsd_data->gpio_card_detect) {
783-
ret = gpio_request(mvsd_data->gpio_card_detect,
784-
DRIVER_NAME " cd");
775+
ret = devm_gpio_request_one(&pdev->dev,
776+
mvsd_data->gpio_card_detect,
777+
GPIOF_IN, DRIVER_NAME " cd");
785778
if (ret == 0) {
786-
gpio_direction_input(mvsd_data->gpio_card_detect);
787779
irq = gpio_to_irq(mvsd_data->gpio_card_detect);
788-
ret = request_irq(irq, mvsd_card_detect_irq,
789-
IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING,
790-
DRIVER_NAME " cd", host);
780+
ret = devm_request_irq(&pdev->dev, irq,
781+
mvsd_card_detect_irq,
782+
IRQ_TYPE_EDGE_RISING |
783+
IRQ_TYPE_EDGE_FALLING,
784+
DRIVER_NAME " cd", host);
791785
if (ret == 0)
792786
host->gpio_card_detect =
793787
mvsd_data->gpio_card_detect;
794788
else
795-
gpio_free(mvsd_data->gpio_card_detect);
789+
devm_gpio_free(&pdev->dev,
790+
mvsd_data->gpio_card_detect);
796791
}
797792
}
798793
if (!host->gpio_card_detect)
799794
mmc->caps |= MMC_CAP_NEEDS_POLL;
800795

801796
if (mvsd_data->gpio_write_protect) {
802-
ret = gpio_request(mvsd_data->gpio_write_protect,
803-
DRIVER_NAME " wp");
797+
ret = devm_gpio_request_one(&pdev->dev,
798+
mvsd_data->gpio_write_protect,
799+
GPIOF_IN, DRIVER_NAME " wp");
804800
if (ret == 0) {
805-
gpio_direction_input(mvsd_data->gpio_write_protect);
806801
host->gpio_write_protect =
807802
mvsd_data->gpio_write_protect;
808803
}
@@ -824,26 +819,11 @@ static int __init mvsd_probe(struct platform_device *pdev)
824819
return 0;
825820

826821
out:
827-
if (host) {
828-
if (host->irq)
829-
free_irq(host->irq, host);
830-
if (host->gpio_card_detect) {
831-
free_irq(gpio_to_irq(host->gpio_card_detect), host);
832-
gpio_free(host->gpio_card_detect);
833-
}
834-
if (host->gpio_write_protect)
835-
gpio_free(host->gpio_write_protect);
836-
if (host->base)
837-
iounmap(host->base);
838-
}
839-
if (r)
840-
release_resource(r);
841-
if (mmc)
842-
if (!IS_ERR_OR_NULL(host->clk)) {
822+
if (mmc) {
823+
if (!IS_ERR(host->clk))
843824
clk_disable_unprepare(host->clk);
844-
clk_put(host->clk);
845-
}
846825
mmc_free_host(mmc);
826+
}
847827

848828
return ret;
849829
}
@@ -852,28 +832,16 @@ static int __exit mvsd_remove(struct platform_device *pdev)
852832
{
853833
struct mmc_host *mmc = platform_get_drvdata(pdev);
854834

855-
if (mmc) {
856-
struct mvsd_host *host = mmc_priv(mmc);
835+
struct mvsd_host *host = mmc_priv(mmc);
857836

858-
if (host->gpio_card_detect) {
859-
free_irq(gpio_to_irq(host->gpio_card_detect), host);
860-
gpio_free(host->gpio_card_detect);
861-
}
862-
mmc_remove_host(mmc);
863-
free_irq(host->irq, host);
864-
if (host->gpio_write_protect)
865-
gpio_free(host->gpio_write_protect);
866-
del_timer_sync(&host->timer);
867-
mvsd_power_down(host);
868-
iounmap(host->base);
869-
release_resource(host->res);
837+
mmc_remove_host(mmc);
838+
del_timer_sync(&host->timer);
839+
mvsd_power_down(host);
840+
841+
if (!IS_ERR(host->clk))
842+
clk_disable_unprepare(host->clk);
843+
mmc_free_host(mmc);
870844

871-
if (!IS_ERR(host->clk)) {
872-
clk_disable_unprepare(host->clk);
873-
clk_put(host->clk);
874-
}
875-
mmc_free_host(mmc);
876-
}
877845
platform_set_drvdata(pdev, NULL);
878846
return 0;
879847
}

0 commit comments

Comments
 (0)