linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] mmc: mtk-sd: add some devm
@ 2024-09-30 22:49 Rosen Penev
  2024-09-30 22:49 ` [PATCH 1/3] mmc: mtk-sd: use devm_mmc_alloc_host Rosen Penev
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Rosen Penev @ 2024-09-30 22:49 UTC (permalink / raw)
  To: linux-mmc
  Cc: Chaotian Jing, Ulf Hansson, Matthias Brugger,
	AngeloGioacchino Del Regno, open list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support

Simplifies the code. Also a bugfix with devm_clk_get_optional.

Rosen Penev (3):
  mmc: mtk-sd: use devm_mmc_alloc_host
  mmc: mtd-sd: use devm_platform_ioremap_resource
  mmc: mtk-sd: fix devm_clk_get_optional usage

 drivers/mmc/host/mtk-sd.c | 70 ++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 45 deletions(-)

-- 
2.46.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] mmc: mtk-sd: use devm_mmc_alloc_host
  2024-09-30 22:49 [PATCH 0/3] mmc: mtk-sd: add some devm Rosen Penev
@ 2024-09-30 22:49 ` Rosen Penev
  2024-09-30 22:49 ` [PATCH 2/3] mmc: mtd-sd: use devm_platform_ioremap_resource Rosen Penev
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Rosen Penev @ 2024-09-30 22:49 UTC (permalink / raw)
  To: linux-mmc
  Cc: Chaotian Jing, Ulf Hansson, Matthias Brugger,
	AngeloGioacchino Del Regno, open list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support

Allows removing several gotos.

Also fixed some wrong ones.

Added dev_err_probe where EPROBE_DEFER is possible.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/mmc/host/mtk-sd.c | 55 ++++++++++++++-------------------------
 1 file changed, 20 insertions(+), 35 deletions(-)

diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
index 89018b6c97b9..c607312dfe07 100644
--- a/drivers/mmc/host/mtk-sd.c
+++ b/drivers/mmc/host/mtk-sd.c
@@ -2736,20 +2736,18 @@ static int msdc_drv_probe(struct platform_device *pdev)
 	}
 
 	/* Allocate MMC host for this device */
-	mmc = mmc_alloc_host(sizeof(struct msdc_host), &pdev->dev);
+	mmc = devm_mmc_alloc_host(&pdev->dev, sizeof(struct msdc_host));
 	if (!mmc)
 		return -ENOMEM;
 
 	host = mmc_priv(mmc);
 	ret = mmc_of_parse(mmc);
 	if (ret)
-		goto host_free;
+		return ret;
 
 	host->base = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(host->base)) {
-		ret = PTR_ERR(host->base);
-		goto host_free;
-	}
+	if (IS_ERR(host->base))
+		return PTR_ERR(host->base);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (res) {
@@ -2760,18 +2758,16 @@ static int msdc_drv_probe(struct platform_device *pdev)
 
 	ret = mmc_regulator_get_supply(mmc);
 	if (ret)
-		goto host_free;
+		return ret;
 
 	ret = msdc_of_clock_parse(pdev, host);
 	if (ret)
-		goto host_free;
+		return ret;
 
 	host->reset = devm_reset_control_get_optional_exclusive(&pdev->dev,
 								"hrst");
-	if (IS_ERR(host->reset)) {
-		ret = PTR_ERR(host->reset);
-		goto host_free;
-	}
+	if (IS_ERR(host->reset))
+		return PTR_ERR(host->reset);
 
 	/* only eMMC has crypto property */
 	if (!(mmc->caps2 & MMC_CAP2_NO_MMC)) {
@@ -2783,30 +2779,24 @@ static int msdc_drv_probe(struct platform_device *pdev)
 	}
 
 	host->irq = platform_get_irq(pdev, 0);
-	if (host->irq < 0) {
-		ret = host->irq;
-		goto host_free;
-	}
+	if (host->irq < 0)
+		return host->irq;
 
 	host->pinctrl = devm_pinctrl_get(&pdev->dev);
-	if (IS_ERR(host->pinctrl)) {
-		ret = PTR_ERR(host->pinctrl);
-		dev_err(&pdev->dev, "Cannot find pinctrl!\n");
-		goto host_free;
-	}
+	if (IS_ERR(host->pinctrl))
+		return dev_err_probe(&pdev->dev, PTR_ERR(host->pinctrl),
+				     "Cannot find pinctrl");
 
 	host->pins_default = pinctrl_lookup_state(host->pinctrl, "default");
 	if (IS_ERR(host->pins_default)) {
-		ret = PTR_ERR(host->pins_default);
 		dev_err(&pdev->dev, "Cannot find pinctrl default!\n");
-		goto host_free;
+		return PTR_ERR(host->pins_default);
 	}
 
 	host->pins_uhs = pinctrl_lookup_state(host->pinctrl, "state_uhs");
 	if (IS_ERR(host->pins_uhs)) {
-		ret = PTR_ERR(host->pins_uhs);
 		dev_err(&pdev->dev, "Cannot find pinctrl uhs!\n");
-		goto host_free;
+		return PTR_ERR(host->pins_uhs);
 	}
 
 	/* Support for SDIO eint irq ? */
@@ -2895,14 +2885,14 @@ static int msdc_drv_probe(struct platform_device *pdev)
 					     GFP_KERNEL);
 		if (!host->cq_host) {
 			ret = -ENOMEM;
-			goto host_free;
+			goto release_mem;
 		}
 		host->cq_host->caps |= CQHCI_TASK_DESC_SZ_128;
 		host->cq_host->mmio = host->base + 0x800;
 		host->cq_host->ops = &msdc_cmdq_ops;
 		ret = cqhci_init(host->cq_host, mmc, true);
 		if (ret)
-			goto host_free;
+			goto release_mem;
 		mmc->max_segs = 128;
 		/* cqhci 16bit length */
 		/* 0 size, means 65536 so we don't have to -1 here */
@@ -2939,11 +2929,8 @@ static int msdc_drv_probe(struct platform_device *pdev)
 			host->dma.gpd, host->dma.gpd_addr);
 	if (host->dma.bd)
 		dma_free_coherent(&pdev->dev,
-			MAX_BD_NUM * sizeof(struct mt_bdma_desc),
-			host->dma.bd, host->dma.bd_addr);
-host_free:
-	mmc_free_host(mmc);
-
+				  MAX_BD_NUM * sizeof(struct mt_bdma_desc),
+				  host->dma.bd, host->dma.bd_addr);
 	return ret;
 }
 
@@ -2968,9 +2955,7 @@ static void msdc_drv_remove(struct platform_device *pdev)
 			2 * sizeof(struct mt_gpdma_desc),
 			host->dma.gpd, host->dma.gpd_addr);
 	dma_free_coherent(&pdev->dev, MAX_BD_NUM * sizeof(struct mt_bdma_desc),
-			host->dma.bd, host->dma.bd_addr);
-
-	mmc_free_host(mmc);
+			  host->dma.bd, host->dma.bd_addr);
 }
 
 static void msdc_save_reg(struct msdc_host *host)
-- 
2.46.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] mmc: mtd-sd: use devm_platform_ioremap_resource
  2024-09-30 22:49 [PATCH 0/3] mmc: mtk-sd: add some devm Rosen Penev
  2024-09-30 22:49 ` [PATCH 1/3] mmc: mtk-sd: use devm_mmc_alloc_host Rosen Penev
@ 2024-09-30 22:49 ` Rosen Penev
  2024-09-30 22:49 ` [PATCH 3/3] mmc: mtk-sd: fix devm_clk_get_optional usage Rosen Penev
  2024-10-08 14:36 ` [PATCH 0/3] mmc: mtk-sd: add some devm Ulf Hansson
  3 siblings, 0 replies; 5+ messages in thread
From: Rosen Penev @ 2024-09-30 22:49 UTC (permalink / raw)
  To: linux-mmc
  Cc: Chaotian Jing, Ulf Hansson, Matthias Brugger,
	AngeloGioacchino Del Regno, open list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support

My guess is some automated tool missed this transformation. Now looks
clearer as do what's happening. Also allows removal of struct resource.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/mmc/host/mtk-sd.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
index c607312dfe07..4be13b9c2d71 100644
--- a/drivers/mmc/host/mtk-sd.c
+++ b/drivers/mmc/host/mtk-sd.c
@@ -2727,7 +2727,6 @@ static int msdc_drv_probe(struct platform_device *pdev)
 {
 	struct mmc_host *mmc;
 	struct msdc_host *host;
-	struct resource *res;
 	int ret;
 
 	if (!pdev->dev.of_node) {
@@ -2749,12 +2748,9 @@ static int msdc_drv_probe(struct platform_device *pdev)
 	if (IS_ERR(host->base))
 		return PTR_ERR(host->base);
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	if (res) {
-		host->top_base = devm_ioremap_resource(&pdev->dev, res);
-		if (IS_ERR(host->top_base))
-			host->top_base = NULL;
-	}
+	host->top_base = devm_platform_ioremap_resource(pdev, 1);
+	if (IS_ERR(host->top_base))
+		host->top_base = NULL;
 
 	ret = mmc_regulator_get_supply(mmc);
 	if (ret)
-- 
2.46.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] mmc: mtk-sd: fix devm_clk_get_optional usage
  2024-09-30 22:49 [PATCH 0/3] mmc: mtk-sd: add some devm Rosen Penev
  2024-09-30 22:49 ` [PATCH 1/3] mmc: mtk-sd: use devm_mmc_alloc_host Rosen Penev
  2024-09-30 22:49 ` [PATCH 2/3] mmc: mtd-sd: use devm_platform_ioremap_resource Rosen Penev
@ 2024-09-30 22:49 ` Rosen Penev
  2024-10-08 14:36 ` [PATCH 0/3] mmc: mtk-sd: add some devm Ulf Hansson
  3 siblings, 0 replies; 5+ messages in thread
From: Rosen Penev @ 2024-09-30 22:49 UTC (permalink / raw)
  To: linux-mmc
  Cc: Chaotian Jing, Ulf Hansson, Matthias Brugger,
	AngeloGioacchino Del Regno, open list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support

This already returns NULL when not found. However, it can return
EPROBE_DEFER and should thus return here.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/mmc/host/mtk-sd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
index 4be13b9c2d71..b02cbae96e89 100644
--- a/drivers/mmc/host/mtk-sd.c
+++ b/drivers/mmc/host/mtk-sd.c
@@ -2769,9 +2769,8 @@ static int msdc_drv_probe(struct platform_device *pdev)
 	if (!(mmc->caps2 & MMC_CAP2_NO_MMC)) {
 		host->crypto_clk = devm_clk_get_optional(&pdev->dev, "crypto");
 		if (IS_ERR(host->crypto_clk))
-			host->crypto_clk = NULL;
-		else
-			mmc->caps2 |= MMC_CAP2_CRYPTO;
+			return PTR_ERR(host->crypto_clk);
+		mmc->caps2 |= MMC_CAP2_CRYPTO;
 	}
 
 	host->irq = platform_get_irq(pdev, 0);
-- 
2.46.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] mmc: mtk-sd: add some devm
  2024-09-30 22:49 [PATCH 0/3] mmc: mtk-sd: add some devm Rosen Penev
                   ` (2 preceding siblings ...)
  2024-09-30 22:49 ` [PATCH 3/3] mmc: mtk-sd: fix devm_clk_get_optional usage Rosen Penev
@ 2024-10-08 14:36 ` Ulf Hansson
  3 siblings, 0 replies; 5+ messages in thread
From: Ulf Hansson @ 2024-10-08 14:36 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-mmc, Chaotian Jing, Matthias Brugger,
	AngeloGioacchino Del Regno, open list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support

On Tue, 1 Oct 2024 at 00:49, Rosen Penev <rosenp@gmail.com> wrote:
>
> Simplifies the code. Also a bugfix with devm_clk_get_optional.
>
> Rosen Penev (3):
>   mmc: mtk-sd: use devm_mmc_alloc_host
>   mmc: mtd-sd: use devm_platform_ioremap_resource
>   mmc: mtk-sd: fix devm_clk_get_optional usage
>
>  drivers/mmc/host/mtk-sd.c | 70 ++++++++++++++-------------------------
>  1 file changed, 25 insertions(+), 45 deletions(-)
>

Applied for next, thanks!

Kind regards
Uffe


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-08 14:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-30 22:49 [PATCH 0/3] mmc: mtk-sd: add some devm Rosen Penev
2024-09-30 22:49 ` [PATCH 1/3] mmc: mtk-sd: use devm_mmc_alloc_host Rosen Penev
2024-09-30 22:49 ` [PATCH 2/3] mmc: mtd-sd: use devm_platform_ioremap_resource Rosen Penev
2024-09-30 22:49 ` [PATCH 3/3] mmc: mtk-sd: fix devm_clk_get_optional usage Rosen Penev
2024-10-08 14:36 ` [PATCH 0/3] mmc: mtk-sd: add some devm Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).