Message ID | 1415567571-6144-1-git-send-email-alchark@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Sun, Nov 9, 2014 at 7:12 PM, Alexey Charkov <alchark@gmail.com> wrote: > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + if (!res) { > + ret = -ENODEV; > + goto fail1; You could save this NULL check... > + } > mmc = mmc_alloc_host(sizeof(struct wmt_mci_priv), &pdev->dev); > if (!mmc) { > dev_err(&pdev->dev, "Failed to allocate mmc_host\n"); > @@ -813,7 +819,7 @@ static int wmt_mci_probe(struct platform_device *pdev) > if (of_get_property(np, "cd-inverted", NULL)) > priv->cd_inverted = 1; > > - priv->sdmmc_base = of_iomap(np, 0); If you move ' res = platform_get_resource' right here as devm_ioremap_resource() already does the NULL check. > + priv->sdmmc_base = devm_ioremap_resource(&pdev->dev, res); > if (!priv->sdmmc_base) { > dev_err(&pdev->dev, "Failed to map IO space\n"); > ret = -ENOMEM;
On 11/09/2014 10:55 PM, Fabio Estevam wrote: > On Sun, Nov 9, 2014 at 7:12 PM, Alexey Charkov <alchark@gmail.com> wrote: > >> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); >> + if (!res) { >> + ret = -ENODEV; >> + goto fail1; > You could save this NULL check... > >> + } >> mmc = mmc_alloc_host(sizeof(struct wmt_mci_priv), &pdev->dev); >> if (!mmc) { >> dev_err(&pdev->dev, "Failed to allocate mmc_host\n"); >> @@ -813,7 +819,7 @@ static int wmt_mci_probe(struct platform_device *pdev) >> if (of_get_property(np, "cd-inverted", NULL)) >> priv->cd_inverted = 1; >> >> - priv->sdmmc_base = of_iomap(np, 0); > If you move ' res = platform_get_resource' right here as > devm_ioremap_resource() already does the NULL check. > >> + priv->sdmmc_base = devm_ioremap_resource(&pdev->dev, res); >> if (!priv->sdmmc_base) { >> dev_err(&pdev->dev, "Failed to map IO space\n"); >> ret = -ENOMEM; This was the original intention but it would fall between the failX jumps, i discussed that with Alexey and we decided to change it with the cleanup to hold this patch small.
2014-11-10 1:18 GMT+03:00 lautriv <lautriv@coldplug.net>: > On 11/09/2014 10:55 PM, Fabio Estevam wrote: >> >> On Sun, Nov 9, 2014 at 7:12 PM, Alexey Charkov <alchark@gmail.com> wrote: >> >>> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); >>> + if (!res) { >>> + ret = -ENODEV; >>> + goto fail1; >> >> You could save this NULL check... >> >>> + } >>> mmc = mmc_alloc_host(sizeof(struct wmt_mci_priv), &pdev->dev); >>> if (!mmc) { >>> dev_err(&pdev->dev, "Failed to allocate mmc_host\n"); >>> @@ -813,7 +819,7 @@ static int wmt_mci_probe(struct platform_device >>> *pdev) >>> if (of_get_property(np, "cd-inverted", NULL)) >>> priv->cd_inverted = 1; >>> >>> - priv->sdmmc_base = of_iomap(np, 0); >> >> If you move ' res = platform_get_resource' right here as >> devm_ioremap_resource() already does the NULL check. >> >>> + priv->sdmmc_base = devm_ioremap_resource(&pdev->dev, res); >>> if (!priv->sdmmc_base) { >>> dev_err(&pdev->dev, "Failed to map IO space\n"); >>> ret = -ENOMEM; > > This was the original intention but it would fall between the failX jumps, i > discussed that with Alexey and we decided to change it with the cleanup to > hold this patch small. I think Fabio means something slightly different than what we discussed. We haven't realized that the first thing devm_ioremap_resource does is exactly that (!res) check, so we can skip ours altogether. Looking at the function code a bit closer, we should also make the check look like "if (IS_ERR(priv->sdmmc_base)", kill the dev_err call (as it's also done internally), and then just do "ret = PTR_ERR(priv->sdmmc_base)" and jump to the label. Thanks a lot, Alexey
diff --git a/drivers/mmc/host/wmt-sdmmc.c b/drivers/mmc/host/wmt-sdmmc.c index 54181b4..02b5e6b 100644 --- a/drivers/mmc/host/wmt-sdmmc.c +++ b/drivers/mmc/host/wmt-sdmmc.c @@ -759,6 +759,7 @@ static int wmt_mci_probe(struct platform_device *pdev) const struct wmt_mci_caps *wmt_caps; int ret; int regular_irq, dma_irq; + struct resource *res; if (!of_id || !of_id->data) { dev_err(&pdev->dev, "Controller capabilities data missing\n"); @@ -781,6 +782,11 @@ static int wmt_mci_probe(struct platform_device *pdev) goto fail1; } + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + ret = -ENODEV; + goto fail1; + } mmc = mmc_alloc_host(sizeof(struct wmt_mci_priv), &pdev->dev); if (!mmc) { dev_err(&pdev->dev, "Failed to allocate mmc_host\n"); @@ -813,7 +819,7 @@ static int wmt_mci_probe(struct platform_device *pdev) if (of_get_property(np, "cd-inverted", NULL)) priv->cd_inverted = 1; - priv->sdmmc_base = of_iomap(np, 0); + priv->sdmmc_base = devm_ioremap_resource(&pdev->dev, res); if (!priv->sdmmc_base) { dev_err(&pdev->dev, "Failed to map IO space\n"); ret = -ENOMEM; @@ -826,7 +832,7 @@ static int wmt_mci_probe(struct platform_device *pdev) ret = request_irq(regular_irq, wmt_mci_regular_isr, 0, "sdmmc", priv); if (ret) { dev_err(&pdev->dev, "Register regular IRQ fail\n"); - goto fail3; + goto fail2; } ret = request_irq(dma_irq, wmt_mci_dma_isr, 0, "sdmmc", priv); @@ -869,8 +875,6 @@ fail5: free_irq(dma_irq, priv); fail4: free_irq(regular_irq, priv); -fail3: - iounmap(priv->sdmmc_base); fail2: mmc_free_host(mmc); fail1: @@ -881,7 +885,6 @@ static int wmt_mci_remove(struct platform_device *pdev) { struct mmc_host *mmc; struct wmt_mci_priv *priv; - struct resource *res; u32 reg_tmp; mmc = platform_get_drvdata(pdev); @@ -904,14 +907,9 @@ static int wmt_mci_remove(struct platform_device *pdev) free_irq(priv->irq_regular, priv); free_irq(priv->irq_dma, priv); - iounmap(priv->sdmmc_base); - clk_disable_unprepare(priv->clk_sdmmc); clk_put(priv->clk_sdmmc); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - release_mem_region(res->start, resource_size(res)); - mmc_free_host(mmc); dev_info(&pdev->dev, "WMT MCI device removed\n");