Skip to contentSkip to conversation

mmc: omap: Convert to devm_kzalloc

PATCH In review Jarkko Nikula 1 participant 7 messages Sep 11, 2013 – Oct 6, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 mmc: omap: Convert to devm_kzalloc

---
 drivers/mmc/host/omap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/mmc/host/omap.c +2 -4
index b94f38e..03179da 100644
@@ -1354,7 +1354,8 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	if (res == NULL)
 		return -EBUSY;
 
-	host = kzalloc(sizeof(struct mmc_omap_host), GFP_KERNEL);
+	host = devm_kzalloc(&pdev->dev, sizeof(struct mmc_omap_host),
+			    GFP_KERNEL);
 	if (host == NULL) {
 		ret = -ENOMEM;
 		goto err_free_mem_region;
@@ -1473,7 +1474,6 @@ err_free_iclk:
 err_free_mmc_host:
 	iounmap(host->virt_base);
 err_ioremap:
-	kfree(host);
 err_free_mem_region:
 	release_mem_region(res->start, resource_size(res));
 	return ret;
@@ -1508,8 +1508,6 @@ static int mmc_omap_remove(struct platform_device *pdev)
 			   pdev->resource[0].end - pdev->resource[0].start + 1);
 	destroy_workqueue(host->mmc_omap_wq);
 
-	kfree(host);
-
 	return 0;
 }
 
Signature · 1 line
1.8.4.rc3
#1 lore raw

PATCH 2/6 mmc: omap: Remove duplicate host->irq assignment

host-irq is set twice so remove needless one.

---
 drivers/mmc/host/omap.c | 1 -
 1 file changed, 1 deletion(-)
drivers/mmc/host/omap.c +0 -1
index 03179da..4d9fc5c 100644
@@ -1384,7 +1384,6 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	host->mem_res = res;
 	host->irq = irq;
 	host->use_dma = 1;
-	host->irq = irq;
 	host->phys_base = host->mem_res->start;
 	host->virt_base = ioremap(res->start, resource_size(res));
 	if (!host->virt_base)
Signature · 1 line
1.8.4.rc3
#2 lore raw

PATCH 3/6 mmc: omap: Remove mem_res field from struct mmc_omap_host

In reply to Jarkko Nikula

Field mem_res in struct mmc_omap_host is used only once in mmc_omap_probe when setting the phys_base field so we may just se the phys_base straight and remove needless mem_res.

---
 drivers/mmc/host/omap.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mmc/host/omap.c +1 -3
index 4d9fc5c..088432d 100644
@@ -141,7 +141,6 @@ struct mmc_omap_host {
 	u32			dma_rx_burst;
 	struct dma_chan		*dma_tx;
 	u32			dma_tx_burst;
-	struct resource		*mem_res;
 	void __iomem		*virt_base;
 	unsigned int		phys_base;
 	int			irq;
@@ -1381,10 +1380,9 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, host);
 
 	host->id = pdev->id;
-	host->mem_res = res;
 	host->irq = irq;
 	host->use_dma = 1;
-	host->phys_base = host->mem_res->start;
+	host->phys_base = res->start;
 	host->virt_base = ioremap(res->start, resource_size(res));
 	if (!host->virt_base)
 		goto err_ioremap;
Signature · 1 line
1.8.4.rc3
#3 lore raw

PATCH 4/6 mmc: omap: Convert to devm_ioremap_resource

In reply to Jarkko Nikula

Simplify probe and cleanup code by using devm_ioremap_resource. This also makes probe code to follow more common allocate private struct followed by other initialization style.

---
 drivers/mmc/host/omap.c | 41 ++++++++++++-----------------------------
 1 file changed, 12 insertions(+), 29 deletions(-)
drivers/mmc/host/omap.c +12 -29
index 088432d..5ff6da9 100644
@@ -1343,22 +1343,19 @@ static int mmc_omap_probe(struct platform_device *pdev)
 		return -ENXIO;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	host = devm_kzalloc(&pdev->dev, sizeof(struct mmc_omap_host),
+			    GFP_KERNEL);
+	if (host == NULL)
+		return -ENOMEM;
+
 	irq = platform_get_irq(pdev, 0);
-	if (res == NULL || irq < 0)
+	if (irq < 0)
 		return -ENXIO;
 
-	res = request_mem_region(res->start, resource_size(res),
-				 pdev->name);
-	if (res == NULL)
-		return -EBUSY;
-
-	host = devm_kzalloc(&pdev->dev, sizeof(struct mmc_omap_host),
-			    GFP_KERNEL);
-	if (host == NULL) {
-		ret = -ENOMEM;
-		goto err_free_mem_region;
-	}
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	host->virt_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(host->virt_base))
+		return PTR_ERR(host->virt_base);
 
 	INIT_WORK(&host->slot_release_work, mmc_omap_slot_release_work);
 	INIT_WORK(&host->send_stop_work, mmc_omap_send_stop_work);
@@ -1383,15 +1380,9 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	host->irq = irq;
 	host->use_dma = 1;
 	host->phys_base = res->start;
-	host->virt_base = ioremap(res->start, resource_size(res));
-	if (!host->virt_base)
-		goto err_ioremap;
-
 	host->iclk = clk_get(&pdev->dev, "ick");
-	if (IS_ERR(host->iclk)) {
-		ret = PTR_ERR(host->iclk);
-		goto err_free_mmc_host;
-	}
+	if (IS_ERR(host->iclk))
+		return PTR_ERR(host->iclk);
 	clk_enable(host->iclk);
 
 	host->fclk = clk_get(&pdev->dev, "fck");
@@ -1468,11 +1459,6 @@ err_free_dma:
 err_free_iclk:
 	clk_disable(host->iclk);
 	clk_put(host->iclk);
-err_free_mmc_host:
-	iounmap(host->virt_base);
-err_ioremap:
-err_free_mem_region:
-	release_mem_region(res->start, resource_size(res));
 	return ret;
 }
 
@@ -1500,9 +1486,6 @@ static int mmc_omap_remove(struct platform_device *pdev)
 	if (host->dma_rx)
 		dma_release_channel(host->dma_rx);
 
-	iounmap(host->virt_base);
-	release_mem_region(pdev->resource[0].start,
-			   pdev->resource[0].end - pdev->resource[0].start + 1);
 	destroy_workqueue(host->mmc_omap_wq);
 
 	return 0;
Signature · 1 line
1.8.4.rc3
#4 lore raw

PATCH 5/6 mmc: omap: Remove always set use_dma flag from struct mmc_omap_host

In reply to Jarkko Nikula

Because use_dma is set only in mmc_omap_probe and unset nowhere there is no need to carry that flag in struct mmc_omap_host for mmc_omap_prepare_data function.

---
 drivers/mmc/host/omap.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/mmc/host/omap.c +5 -10
index 5ff6da9..ce455da 100644
@@ -163,7 +163,6 @@ struct mmc_omap_host {
 	u32			total_bytes_left;
 
 	unsigned		features;
-	unsigned		use_dma:1;
 	unsigned		brs_received:1, dma_done:1;
 	unsigned		dma_in_use:1;
 	spinlock_t		dma_lock;
@@ -955,7 +954,7 @@ static void
 mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
 {
 	struct mmc_data *data = req->data;
-	int i, use_dma, block_size;
+	int i, use_dma = 1, block_size;
 	unsigned sg_len;
 
 	host->data = data;
@@ -980,13 +979,10 @@ mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
 	sg_len = (data->blocks == 1) ? 1 : data->sg_len;
 
 	/* Only do DMA for entire blocks */
-	use_dma = host->use_dma;
-	if (use_dma) {
-		for (i = 0; i < sg_len; i++) {
-			if ((data->sg[i].length % block_size) != 0) {
-				use_dma = 0;
-				break;
-			}
+	for (i = 0; i < sg_len; i++) {
+		if ((data->sg[i].length % block_size) != 0) {
+			use_dma = 0;
+			break;
 		}
 	}
 
@@ -1378,7 +1374,6 @@ static int mmc_omap_probe(struct platform_device *pdev)
 
 	host->id = pdev->id;
 	host->irq = irq;
-	host->use_dma = 1;
 	host->phys_base = res->start;
 	host->iclk = clk_get(&pdev->dev, "ick");
 	if (IS_ERR(host->iclk))
Signature · 1 line
1.8.4.rc3
#5 lore raw

PATCH 6/6 mmc: omap: Get DMA request numbers via platform resource

In reply to Jarkko Nikula

There is no need to define MMC DMA TX and RX request numbers locally for OMAP1xxx and OMAP24xx and assign them non-portable way since they already come via platform resources. See commits

6c432f7 ("ARM: OMAP1: Pass dma request lines in platform data to MMC driver") b955eef ("ARM: OMAP2: Use hwmod to initialize mmc for 2420")

Note that mmc_omap_probe doesn't change failure mechanism in case if it fails get DMA request number or DMA channel. In that case it just falls back to PIO transfer for TX and/or RX.

---
Aaro:
Sorry to bother you but I know you have OMAP1xxx based boards and I apreciate if you can give a quick test :-)
I have tested this set on OMAP2420 based Nokia N810.

---
 drivers/mmc/host/omap.c | 39 +++++++++++++--------------------------
 1 file changed, 13 insertions(+), 26 deletions(-)
drivers/mmc/host/omap.c +13 -26
index ce455da..5f9e472 100644
@@ -90,17 +90,6 @@
 #define OMAP_MMC_CMDTYPE_AC	2
 #define OMAP_MMC_CMDTYPE_ADTC	3
 
-#define OMAP_DMA_MMC_TX		21
-#define OMAP_DMA_MMC_RX		22
-#define OMAP_DMA_MMC2_TX	54
-#define OMAP_DMA_MMC2_RX	55
-
-#define OMAP24XX_DMA_MMC2_TX	47
-#define OMAP24XX_DMA_MMC2_RX	48
-#define OMAP24XX_DMA_MMC1_TX	61
-#define OMAP24XX_DMA_MMC1_RX	62
-
-
 #define DRIVER_NAME "mmci-omap"
 
 /* Specifies how often in millisecs to poll for card status changes
@@ -1326,7 +1315,6 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	struct mmc_omap_host *host = NULL;
 	struct resource *res;
 	dma_cap_mask_t mask;
-	unsigned sig;
 	int i, ret = 0;
 	int irq;
 
@@ -1392,22 +1380,21 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	host->dma_tx_burst = -1;
 	host->dma_rx_burst = -1;
 
-	if (mmc_omap2())
-		sig = host->id == 0 ? OMAP24XX_DMA_MMC1_TX : OMAP24XX_DMA_MMC2_TX;
-	else
-		sig = host->id == 0 ? OMAP_DMA_MMC_TX : OMAP_DMA_MMC2_TX;
-	host->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig);
+	res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
+	if (res)
+		host->dma_tx = dma_request_channel(mask, omap_dma_filter_fn,
+						   &res->start);
 	if (!host->dma_tx)
-		dev_warn(host->dev, "unable to obtain TX DMA engine channel %u\n",
-			sig);
-	if (mmc_omap2())
-		sig = host->id == 0 ? OMAP24XX_DMA_MMC1_RX : OMAP24XX_DMA_MMC2_RX;
-	else
-		sig = host->id == 0 ? OMAP_DMA_MMC_RX : OMAP_DMA_MMC2_RX;
-	host->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig);
+		dev_warn(host->dev,
+			 "unable to obtain TX DMA. Falling back to PIO\n");
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
+	if (res)
+		host->dma_rx = dma_request_channel(mask, omap_dma_filter_fn,
+						   &res->start);
 	if (!host->dma_rx)
-		dev_warn(host->dev, "unable to obtain RX DMA engine channel %u\n",
-			sig);
+		dev_warn(host->dev,
+			 "unable to obtain RX DMA. Falling back to PIO\n");
 
 	ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host);
 	if (ret)
Signature · 1 line
1.8.4.rc3
#6 lore raw
In reply to Jarkko Nikula

Hi

Quoted 5 lines · Jarkko Nikula
---
 drivers/mmc/host/omap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

I resent this set with a subject prefix "PATCH FIX+RESEND" since I found a NULL pointer dereference case from this driver and I put a fix for it first and rebased these 6 patches on top of it.

Signature · 1 line
Jarkko