[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240531094658.1598969-3-andy.shevchenko@gmail.com>
Date: Fri, 31 May 2024 12:44:33 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Mark Brown <broonie@...nel.org>,
linux-spi@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: NĂcolas F . R . A . Prado <nfraprado@...labora.com>,
Neil Armstrong <neil.armstrong@...aro.org>,
Andy Shevchenko <andy.shevchenko@...il.com>
Subject: [PATCH v1 2/2] spi: Do not rely on the SG table and respective API implementations
Currently we use global non-constant SG list to cover DMA unmmaped
part of unidirection transfer. This is heavily relies on the internal
implementation of the SG table and respective APIs. Instead, and
to be pair with the DMA mapped part of the transfer, use SG table
allocation for a single entry without any mapping done on top. This
also will be symmetrical to the respective sg_free_table() call.
Signed-off-by: Andy Shevchenko <andy.shevchenko@...il.com>
---
drivers/spi/spi.c | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 43cd3e5bccbe..da978ee262d8 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1220,11 +1220,6 @@ void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev,
spi_unmap_buf_attrs(ctlr, dev, sgt, dir, 0);
}
-/* Dummy SG for unidirect transfers */
-static struct scatterlist dummy_sg = {
- .page_link = SG_END,
-};
-
static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
{
struct device *tx_dev, *rx_dev;
@@ -1261,25 +1256,26 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
(void *)xfer->tx_buf,
xfer->len, DMA_TO_DEVICE,
attrs);
- if (ret != 0)
- return ret;
} else {
- xfer->tx_sg.sgl = &dummy_sg;
+ /* Allocate dummy SG table for unidirect transfers */
+ ret = sg_alloc_table(&xfer->tx_sg, 1, GFP_KERNEL);
}
+ if (ret)
+ return ret;
if (xfer->rx_buf != NULL) {
ret = spi_map_buf_attrs(ctlr, rx_dev, &xfer->rx_sg,
xfer->rx_buf, xfer->len,
DMA_FROM_DEVICE, attrs);
- if (ret != 0) {
- spi_unmap_buf_attrs(ctlr, tx_dev,
- &xfer->tx_sg, DMA_TO_DEVICE,
- attrs);
-
- return ret;
- }
} else {
- xfer->rx_sg.sgl = &dummy_sg;
+ /* Allocate dummy SG table for unidirect transfers */
+ ret = sg_alloc_table(&xfer->rx_sg, 1, GFP_KERNEL);
+ }
+ if (ret) {
+ spi_unmap_buf_attrs(ctlr, tx_dev, &xfer->tx_sg,
+ DMA_TO_DEVICE, attrs);
+
+ return ret;
}
}
/* No transfer has been mapped, bail out with success */
--
2.45.1
Powered by blists - more mailing lists