Skip to content

Commit 9dedabe

Browse files
andy-shevbroonie
authored andcommitted
spi: Assign dummy scatterlist to unidirectional transfers
Commit 8cc3bad ("spi: Remove unneded check for orig_nents") introduced a regression: unmapped data could now be passed to the DMA APIs, resulting in null pointer dereferences. Commit 9f788ba ("spi: Don't mark message DMA mapped when no transfer in it is") and commit da56009 ("spi: Check if transfer is mapped before calling DMA sync APIs") addressed the problem, but only partially. Unidirectional transactions will still result in null pointer dereference. To prevent that from happening, assign a dummy scatterlist when no data is mapped, so that the DMA API can be called and not result in a null pointer dereference. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reported-by: Neil Armstrong <neil.armstrong@linaro.org> Closes: https://lore.kernel.org/r/8ae675b5-fcf9-4c9b-b06a-4462f70e1322@linaro.org Reported-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Closes: https://lore.kernel.org/all/d3679496-2e4e-4a7c-97ed-f193bd53af1d@notapiano Closes: https://lore.kernel.org/all/4748499f-789c-45a8-b50a-2dd09f4bac8c@notapiano Fixes: 8cc3bad ("spi: Remove unneded check for orig_nents") Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> [nfraprado: wrote the commit message] Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Link: https://msgid.link/r/20240529-dma-oops-dummy-v1-1-bb43aacfb11b@collabora.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 4a69c12 commit 9dedabe

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/spi/spi.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,11 @@ void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev,
12201220
spi_unmap_buf_attrs(ctlr, dev, sgt, dir, 0);
12211221
}
12221222

1223+
/* Dummy SG for unidirect transfers */
1224+
static struct scatterlist dummy_sg = {
1225+
.page_link = SG_END,
1226+
};
1227+
12231228
static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
12241229
{
12251230
struct device *tx_dev, *rx_dev;
@@ -1258,6 +1263,8 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
12581263
attrs);
12591264
if (ret != 0)
12601265
return ret;
1266+
} else {
1267+
xfer->tx_sg.sgl = &dummy_sg;
12611268
}
12621269

12631270
if (xfer->rx_buf != NULL) {
@@ -1271,6 +1278,8 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
12711278

12721279
return ret;
12731280
}
1281+
} else {
1282+
xfer->rx_sg.sgl = &dummy_sg;
12741283
}
12751284
}
12761285
/* No transfer has been mapped, bail out with success */

0 commit comments

Comments
 (0)