]> Git Repo - J-linux.git/commitdiff
spi: Don't mark message DMA mapped when no transfer in it is
authorAndy Shevchenko <[email protected]>
Wed, 22 May 2024 17:09:49 +0000 (20:09 +0300)
committerMark Brown <[email protected]>
Thu, 23 May 2024 11:32:52 +0000 (12:32 +0100)
There is no need to set the DMA mapped flag of the message if it has
no mapped transfers. Moreover, it may give the code a chance to take
the wrong paths, i.e. to exercise DMA related APIs on unmapped data.
Make __spi_map_msg() to bail earlier on the above mentioned cases.

Fixes: 99adef310f68 ("spi: Provide core support for DMA mapping transfers")
Signed-off-by: Andy Shevchenko <[email protected]>
Link: https://msgid.link/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
drivers/spi/spi.c

index a8966caed84142bef669ad5aa57e489f49346cb7..d40ce0fdb1a81eaef44b28b6255180cfcac79f11 100644 (file)
@@ -1243,6 +1243,7 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
        else
                rx_dev = ctlr->dev.parent;
 
        else
                rx_dev = ctlr->dev.parent;
 
+       ret = -ENOMSG;
        list_for_each_entry(xfer, &msg->transfers, transfer_list) {
                /* The sync is done before each transfer. */
                unsigned long attrs = DMA_ATTR_SKIP_CPU_SYNC;
        list_for_each_entry(xfer, &msg->transfers, transfer_list) {
                /* The sync is done before each transfer. */
                unsigned long attrs = DMA_ATTR_SKIP_CPU_SYNC;
@@ -1272,6 +1273,9 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
                        }
                }
        }
                        }
                }
        }
+       /* No transfer has been mapped, bail out with success */
+       if (ret)
+               return 0;
 
        ctlr->cur_rx_dma_dev = rx_dev;
        ctlr->cur_tx_dma_dev = tx_dev;
 
        ctlr->cur_rx_dma_dev = rx_dev;
        ctlr->cur_tx_dma_dev = tx_dev;
This page took 0.062279 seconds and 4 git commands to generate.