Skip to content

Commit

Permalink
spi: Don't mark message DMA mapped when no transfer in it is
Browse files Browse the repository at this point in the history
[ Upstream commit 9f788ba ]

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: 99adef3 ("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]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
andy-shev authored and Florian Bezannier committed Aug 23, 2024
1 parent bfe9cdf commit 835ae51
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
else
rx_dev = ctlr->dev.parent;

ret = -ENOMSG;
list_for_each_entry(xfer, &msg->transfers, transfer_list) {
if (!ctlr->can_dma(ctlr, msg->spi, xfer))
continue;
Expand All @@ -1070,6 +1071,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_msg_mapped = true;

Expand Down

0 comments on commit 835ae51

Please sign in to comment.