Skip to contentSkip to conversation

spi: spi-atmel: Use devm_*() functions

PATCH Applied Jingoo Han 3 participants 7 messages Dec 4, 2013 – Dec 5, 2013 4 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Jingoo Han

author
#0 lore raw

PATCH 1/2 spi: spi-atmel: Use devm_*() functions

Use devm_*() functions to make cleanup paths simpler.

---
 drivers/spi/spi-atmel.c |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/spi/spi-atmel.c +6 -12
index 273db0b..57fa738 100644
@@ -1510,7 +1510,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
-	clk = clk_get(&pdev->dev, "spi_clk");
+	clk = devm_clk_get(&pdev->dev, "spi_clk");
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 
@@ -1570,14 +1570,14 @@ static int atmel_spi_probe(struct platform_device *pdev)
 		dev_info(&pdev->dev, "Atmel SPI Controller using PIO only\n");
 
 	if (as->use_pdc) {
-		ret = request_irq(irq, atmel_spi_pdc_interrupt, 0,
-					dev_name(&pdev->dev), master);
+		ret = devm_request_irq(&pdev->dev, irq, atmel_spi_pdc_interrupt,
+					0, dev_name(&pdev->dev), master);
 	} else {
 		tasklet_init(&as->tasklet, atmel_spi_tasklet_func,
 					(unsigned long)master);
 
-		ret = request_irq(irq, atmel_spi_pio_interrupt, 0,
-					dev_name(&pdev->dev), master);
+		ret = devm_request_irq(&pdev->dev, irq, atmel_spi_pio_interrupt,
+					0, dev_name(&pdev->dev), master);
 	}
 	if (ret)
 		goto out_unmap_regs;
@@ -1603,7 +1603,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	dev_info(&pdev->dev, "Atmel SPI Controller at 0x%08lx (irq %d)\n",
 			(unsigned long)regs->start, irq);
 
-	ret = spi_register_master(master);
+	ret = devm_spi_register_master(&pdev->dev, master);
 	if (ret)
 		goto out_free_dma;
 
@@ -1617,7 +1617,6 @@ out_free_dma:
 	spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
 	clk_disable_unprepare(clk);
 out_free_irq:
-	free_irq(irq, master);
 out_unmap_regs:
 out_free_buffer:
 	if (!as->use_pdc)
@@ -1625,7 +1624,6 @@ out_free_buffer:
 	dma_free_coherent(&pdev->dev, BUFFER_SIZE, as->buffer,
 			as->buffer_dma);
 out_free:
-	clk_put(clk);
 	spi_master_put(master);
 	return ret;
 }
@@ -1668,10 +1666,6 @@ static int atmel_spi_remove(struct platform_device *pdev)
 			as->buffer_dma);
 
 	clk_disable_unprepare(as->clk);
-	clk_put(as->clk);
-	free_irq(as->irq, master);
-
-	spi_unregister_master(master);
 
 	return 0;
 }
Signature · 7 lines
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 002b01cef0ae$c8261dc0$58725940$%[email protected]

author
#2 lore raw

PATCH 2/2 spi: coldfire-qspi: Use devm_*() functions

Use devm_*() functions to make cleanup paths simpler.

---
 drivers/spi/spi-coldfire-qspi.c |   47 ++++++++++++---------------------------
 1 file changed, 14 insertions(+), 33 deletions(-)
drivers/spi/spi-coldfire-qspi.c +14 -33
index cc5b75d..9ee81a4 100644
@@ -403,38 +403,31 @@ static int mcfqspi_probe(struct platform_device *pdev)
 		goto fail0;
 	}
 
-	if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
-		dev_dbg(&pdev->dev, "request_mem_region failed\n");
-		status = -EBUSY;
+	mcfqspi->iobase = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(mcfqspi->iobase)) {
+		status = PTR_ERR(mcfqspi->iobase);
 		goto fail0;
 	}
 
-	mcfqspi->iobase = ioremap(res->start, resource_size(res));
-	if (!mcfqspi->iobase) {
-		dev_dbg(&pdev->dev, "ioremap failed\n");
-		status = -ENOMEM;
-		goto fail1;
-	}
-
 	mcfqspi->irq = platform_get_irq(pdev, 0);
 	if (mcfqspi->irq < 0) {
 		dev_dbg(&pdev->dev, "platform_get_irq failed\n");
 		status = -ENXIO;
-		goto fail2;
+		goto fail0;
 	}
 
-	status = request_irq(mcfqspi->irq, mcfqspi_irq_handler, 0,
-			     pdev->name, mcfqspi);
+	status = devm_request_irq(&pdev->dev, mcfqspi->irq, mcfqspi_irq_handler,
+				0, pdev->name, mcfqspi);
 	if (status) {
 		dev_dbg(&pdev->dev, "request_irq failed\n");
-		goto fail2;
+		goto fail0;
 	}
 
-	mcfqspi->clk = clk_get(&pdev->dev, "qspi_clk");
+	mcfqspi->clk = devm_clk_get(&pdev->dev, "qspi_clk");
 	if (IS_ERR(mcfqspi->clk)) {
 		dev_dbg(&pdev->dev, "clk_get failed\n");
 		status = PTR_ERR(mcfqspi->clk);
-		goto fail3;
+		goto fail0;
 	}
 	clk_enable(mcfqspi->clk);
 
@@ -445,7 +438,7 @@ static int mcfqspi_probe(struct platform_device *pdev)
 	status = mcfqspi_cs_setup(mcfqspi);
 	if (status) {
 		dev_dbg(&pdev->dev, "error initializing cs_control\n");
-		goto fail4;
+		goto fail1;
 	}
 
 	init_waitqueue_head(&mcfqspi->waitq);
@@ -459,10 +452,10 @@ static int mcfqspi_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, master);
 
-	status = spi_register_master(master);
+	status = devm_spi_register_master(&pdev->dev, master);
 	if (status) {
 		dev_dbg(&pdev->dev, "spi_register_master failed\n");
-		goto fail5;
+		goto fail2;
 	}
 	pm_runtime_enable(mcfqspi->dev);
 
@@ -470,17 +463,10 @@ static int mcfqspi_probe(struct platform_device *pdev)
 
 	return 0;
 
-fail5:
-	mcfqspi_cs_teardown(mcfqspi);
-fail4:
-	clk_disable(mcfqspi->clk);
-	clk_put(mcfqspi->clk);
-fail3:
-	free_irq(mcfqspi->irq, mcfqspi);
 fail2:
-	iounmap(mcfqspi->iobase);
+	mcfqspi_cs_teardown(mcfqspi);
 fail1:
-	release_mem_region(res->start, resource_size(res));
+	clk_disable(mcfqspi->clk);
 fail0:
 	spi_master_put(master);
 
@@ -501,11 +487,6 @@ static int mcfqspi_remove(struct platform_device *pdev)
 
 	mcfqspi_cs_teardown(mcfqspi);
 	clk_disable(mcfqspi->clk);
-	clk_put(mcfqspi->clk);
-	free_irq(mcfqspi->irq, mcfqspi);
-	iounmap(mcfqspi->iobase);
-	release_mem_region(res->start, resource_size(res));
-	spi_unregister_master(master);
 
 	return 0;
 }
Signature · 7 lines
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 002c01cef0af$1b3a4630$51aed290$%[email protected]

Applied
#4 lore raw

Re: [PATCH 2/2] spi: coldfire-qspi: Use devm_*() functions

Quoted 1 line · Jingoo Han

Use devm_*() functions to make cleanup paths simpler.

Applied, thanks.

Acked-by
#5 lore raw
In reply to a message not in the archive

On 04/12/2013 06:07, Jingoo Han :

Quoted 49 lines

Use devm_*() functions to make cleanup paths simpler.

---
  drivers/spi/spi-atmel.c |   18 ++++++------------
  1 file changed, 6 insertions(+), 12 deletions(-)
drivers/spi/spi-atmel.c +6 -6
index 273db0b..57fa738 100644
@@ -1510,7 +1510,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
  	if (irq < 0)
  		return irq;
 
-	clk = clk_get(&pdev->dev, "spi_clk");
+	clk = devm_clk_get(&pdev->dev, "spi_clk");
  	if (IS_ERR(clk))
  		return PTR_ERR(clk);
 
@@ -1570,14 +1570,14 @@ static int atmel_spi_probe(struct platform_device *pdev)
  		dev_info(&pdev->dev, "Atmel SPI Controller using PIO only\n");
 
  	if (as->use_pdc) {
-		ret = request_irq(irq, atmel_spi_pdc_interrupt, 0,
-					dev_name(&pdev->dev), master);
+		ret = devm_request_irq(&pdev->dev, irq, atmel_spi_pdc_interrupt,
+					0, dev_name(&pdev->dev), master);
  	} else {
  		tasklet_init(&as->tasklet, atmel_spi_tasklet_func,
  					(unsigned long)master);
 
-		ret = request_irq(irq, atmel_spi_pio_interrupt, 0,
-					dev_name(&pdev->dev), master);
+		ret = devm_request_irq(&pdev->dev, irq, atmel_spi_pio_interrupt,
+					0, dev_name(&pdev->dev), master);
  	}
  	if (ret)
  		goto out_unmap_regs;
@@ -1603,7 +1603,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
  	dev_info(&pdev->dev, "Atmel SPI Controller at 0x%08lx (irq %d)\n",
  			(unsigned long)regs->start, irq);
 
-	ret = spi_register_master(master);
+	ret = devm_spi_register_master(&pdev->dev, master);
  	if (ret)
  		goto out_free_dma;
 

drivers/spi/spi-atmel.c out_free_dma: · line 1621

Quoted 6 lines
drivers/spi/spi-atmel.c +0 -1
@@ -1617,7 +1617,6 @@ out_free_dma:
  	spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
  	clk_disable_unprepare(clk);
  out_free_irq:
-	free_irq(irq, master);
  out_unmap_regs:
  out_free_buffer:

What about taking advantage of this cleanup patch to remove the 3 above unneeded tags?

Otherwise, you can add my:

Quoted 21 lines
drivers/spi/spi-atmel.c +0 -5
  	if (!as->use_pdc)
@@ -1625,7 +1624,6 @@ out_free_buffer:
  	dma_free_coherent(&pdev->dev, BUFFER_SIZE, as->buffer,
  			as->buffer_dma);
  out_free:
-	clk_put(clk);
  	spi_master_put(master);
  	return ret;
  }
@@ -1668,10 +1666,6 @@ static int atmel_spi_remove(struct platform_device *pdev)
  			as->buffer_dma);
 
  	clk_disable_unprepare(as->clk);
-	clk_put(as->clk);
-	free_irq(as->irq, master);
-
-	spi_unregister_master(master);
 
  	return 0;
  }
Signature · 5 lines
Nicolas Ferre
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 10 lines · Nicolas Ferre

On 04/12/2013 06:07, Jingoo Han :

drivers/spi/spi-atmel.c out_free_dma: · line 1621

Quoted 4 lines

out_free_irq:

drivers/spi/spi-atmel.c +0 -1
-	free_irq(irq, master);
 out_unmap_regs:
 out_free_buffer:

What about taking advantage of this cleanup patch to remove the 3 above unneeded tags?

Quoted 2 lines

Otherwise, you can add my:

That's a good idea but it means going and changing all the gotos as well so it probably warrants a separate patch. I applied this one as-is.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

On 04/12/2013 12:59, Mark Brown :

Quoted 11 lines · Nicolas Ferre
Quoted 9 lines

On 04/12/2013 06:07, Jingoo Han :

drivers/spi/spi-atmel.c out_free_dma: · line 1621

Quoted 4 lines

out_free_irq:

drivers/spi/spi-atmel.c +0 -1
-	free_irq(irq, master);
  out_unmap_regs:
  out_free_buffer:

What about taking advantage of this cleanup patch to remove the 3 above unneeded tags?

Quoted 5 lines
Quoted 2 lines

Otherwise, you can add my:

That's a good idea but it means going and changing all the gotos as well so it probably warrants a separate patch. I applied this one as-is.

True! Thanks Mark.

Bye,

Signature · 5 lines
Nicolas Ferre
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#10 lore raw
In reply to a message not in the archive
Quoted 11 lines · Mark Brown
Quoted 9 lines · Nicolas Ferre

On 04/12/2013 06:07, Jingoo Han :

drivers/spi/spi-atmel.c out_free_dma: · line 1621

Quoted 4 lines

out_free_irq:

drivers/spi/spi-atmel.c +0 -1
-	free_irq(irq, master);
 out_unmap_regs:
 out_free_buffer:

What about taking advantage of this cleanup patch to remove the 3 above unneeded tags?

Quoted 5 lines
Quoted 2 lines

Otherwise, you can add my:

That's a good idea but it means going and changing all the gotos as well so it probably warrants a separate patch. I applied this one as-is.

Hi Mark Brown,

I checked your for-next branch of spi.git. However, in this commit, 'Acked-by:' was omitted as below:

Nicolas Ferre <[email protected]> ---> Acked-by: Nicolas Ferre <[email protected]>

When you merge your topics next time, would you add 'Acked-by:' to this commit? :-)
Thank you.

Best regards,
Jingoo Han

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html