From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Mark Brown <broonie@kernel.org>,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Nícolas F . R . A . Prado" <nfraprado@collabora.com>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Andy Shevchenko" <andy.shevchenko@gmail.com>
Subject: [PATCH v1 2/2] spi: Do not rely on the SG table and respective API implementations
Date: Fri, 31 May 2024 12:44:33 +0300 [thread overview]
Message-ID: <20240531094658.1598969-3-andy.shevchenko@gmail.com> (raw)
In-Reply-To: <20240531094658.1598969-1-andy.shevchenko@gmail.com>
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@gmail.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
next prev parent reply other threads:[~2024-05-31 9:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-31 9:44 [PATCH v1 0/2] spi: Make dummy SG handling robust Andy Shevchenko
2024-05-31 9:44 ` [PATCH v1 1/2] spi: Revert "Check if transfer is mapped before calling DMA sync APIs" Andy Shevchenko
2024-05-31 12:15 ` Mark Brown
2024-05-31 13:10 ` Andy Shevchenko
2024-05-31 9:44 ` Andy Shevchenko [this message]
2024-05-31 14:37 ` [PATCH v1 0/2] spi: Make dummy SG handling robust Nícolas F. R. A. Prado
2024-05-31 15:46 ` Andy Shevchenko
2024-05-31 15:51 ` Andy Shevchenko
2024-05-31 17:14 ` Nícolas F. R. A. Prado
2024-05-31 21:45 ` Andy Shevchenko
2024-05-31 21:59 ` Nícolas F. R. A. Prado
2024-06-03 12:26 ` Mark Brown
2024-06-03 17:37 ` Nícolas F. R. A. Prado
2024-06-03 17:44 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240531094658.1598969-3-andy.shevchenko@gmail.com \
--to=andy.shevchenko@gmail.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=nfraprado@collabora.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).