Re: [PATCH v1 2/2] spi: Check if transfer is mapped before calling DMA sync APIs

From: Nícolas F. R. A. Prado
Date: Wed May 29 2024 - 08:35:41 EST


On Wed, May 22, 2024 at 02:41:51PM -0400, Nícolas F. R. A. Prado wrote:
> On Wed, May 22, 2024 at 08:09:50PM +0300, Andy Shevchenko wrote:
[..]
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index f94420858c22..9bc9fd10d538 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1220,6 +1220,11 @@ 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;
> @@ -1258,6 +1263,8 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
> attrs);
> if (ret != 0)
> return ret;
> + } else {
> + xfer->tx_sg.sgl = &dummy_sg;
> }
>
> if (xfer->rx_buf != NULL) {
> @@ -1271,6 +1278,8 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
>
> return ret;
> }
> + } else {
> + xfer->rx_sg.sgl = &dummy_sg;
> }
> }
> /* No transfer has been mapped, bail out with success */

Hi Andy,

I can send this patch to the list myself with your authorship, I just need your
SoB.

Thanks,
Nícolas