linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] can: mcp251x: Convert to devm-* API
@ 2013-12-15 14:16 Alexander Shiyan
  2013-12-15 14:16 ` [PATCH v2 2/2] can: mcp251x: Add device tree support Alexander Shiyan
  2013-12-16 10:17 ` [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Marc Kleine-Budde
  0 siblings, 2 replies; 6+ messages in thread
From: Alexander Shiyan @ 2013-12-15 14:16 UTC (permalink / raw)
  To: linux-can
  Cc: devicetree, Wolfgang Grandegger, Marc Kleine-Budde, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Grant Likely,
	Alexander Shiyan

Replace existing resource handling in the driver with managed
device resource, this ensures more consistent error values and
simplifies error paths.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/net/can/mcp251x.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index 08ac401..7a35729 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -1067,15 +1067,17 @@ static int mcp251x_can_probe(struct spi_device *spi)
 
 	/* Allocate non-DMA buffers */
 	if (!mcp251x_enable_dma) {
-		priv->spi_tx_buf = kmalloc(SPI_TRANSFER_BUF_LEN, GFP_KERNEL);
+		priv->spi_tx_buf = devm_kzalloc(&spi->dev, SPI_TRANSFER_BUF_LEN,
+						GFP_KERNEL);
 		if (!priv->spi_tx_buf) {
 			ret = -ENOMEM;
-			goto error_tx_buf;
+			goto error_probe;
 		}
-		priv->spi_rx_buf = kmalloc(SPI_TRANSFER_BUF_LEN, GFP_KERNEL);
+		priv->spi_rx_buf = devm_kzalloc(&spi->dev, SPI_TRANSFER_BUF_LEN,
+						GFP_KERNEL);
 		if (!priv->spi_rx_buf) {
 			ret = -ENOMEM;
-			goto error_rx_buf;
+			goto error_probe;
 		}
 	}
 
@@ -1108,12 +1110,6 @@ static int mcp251x_can_probe(struct spi_device *spi)
 	return ret;
 
 error_probe:
-	if (!mcp251x_enable_dma)
-		kfree(priv->spi_rx_buf);
-error_rx_buf:
-	if (!mcp251x_enable_dma)
-		kfree(priv->spi_tx_buf);
-error_tx_buf:
 	if (mcp251x_enable_dma)
 		dma_free_coherent(&spi->dev, PAGE_SIZE,
 				  priv->spi_tx_buf, priv->spi_tx_dma);
@@ -1136,9 +1132,6 @@ static int mcp251x_can_remove(struct spi_device *spi)
 	if (mcp251x_enable_dma) {
 		dma_free_coherent(&spi->dev, PAGE_SIZE,
 				  priv->spi_tx_buf, priv->spi_tx_dma);
-	} else {
-		kfree(priv->spi_tx_buf);
-		kfree(priv->spi_rx_buf);
 	}
 
 	mcp251x_power_enable(priv->power, 0);
-- 
1.8.3.2


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

end of thread, other threads:[~2013-12-17 11:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-15 14:16 [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Alexander Shiyan
2013-12-15 14:16 ` [PATCH v2 2/2] can: mcp251x: Add device tree support Alexander Shiyan
2013-12-16 10:20   ` Marc Kleine-Budde
2013-12-16 10:53     ` Alexander Shiyan
2013-12-16 10:17 ` [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Marc Kleine-Budde
2013-12-17 11:08   ` Marc Kleine-Budde

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).