Commit 21629e1a authored by Alexander Shiyan's avatar Alexander Shiyan Committed by Marc Kleine-Budde

can: mcp251x: Convert to devm-* API

Replace existing resource handling in the driver with managed
device resource, this ensures more consistent error values and
simplifies error paths.
Signed-off-by: default avatarAlexander Shiyan <shc_work@mail.ru>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 05780d98
...@@ -1066,15 +1066,17 @@ static int mcp251x_can_probe(struct spi_device *spi) ...@@ -1066,15 +1066,17 @@ static int mcp251x_can_probe(struct spi_device *spi)
/* Allocate non-DMA buffers */ /* Allocate non-DMA buffers */
if (!mcp251x_enable_dma) { 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) { if (!priv->spi_tx_buf) {
ret = -ENOMEM; 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) { if (!priv->spi_rx_buf) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_rx_buf; goto error_probe;
} }
} }
...@@ -1107,12 +1109,6 @@ static int mcp251x_can_probe(struct spi_device *spi) ...@@ -1107,12 +1109,6 @@ static int mcp251x_can_probe(struct spi_device *spi)
return ret; return ret;
error_probe: 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) if (mcp251x_enable_dma)
dma_free_coherent(&spi->dev, PAGE_SIZE, dma_free_coherent(&spi->dev, PAGE_SIZE,
priv->spi_tx_buf, priv->spi_tx_dma); priv->spi_tx_buf, priv->spi_tx_dma);
...@@ -1135,9 +1131,6 @@ static int mcp251x_can_remove(struct spi_device *spi) ...@@ -1135,9 +1131,6 @@ static int mcp251x_can_remove(struct spi_device *spi)
if (mcp251x_enable_dma) { if (mcp251x_enable_dma) {
dma_free_coherent(&spi->dev, PAGE_SIZE, dma_free_coherent(&spi->dev, PAGE_SIZE,
priv->spi_tx_buf, priv->spi_tx_dma); 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); mcp251x_power_enable(priv->power, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment