Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: Fix zero length xfer bug

This fixes a bug for messages containing both zero length and
unidirectional xfers.

The function spi_map_msg will allocate dummy tx and/or rx buffers
for use with unidirectional transfers when the hardware can only do
a bidirectional transfer. That dummy buffer will be used in place
of a NULL buffer even when the xfer length is 0.

Then in the function __spi_map_msg, if he hardware can dma,
the zero length xfer will have spi_map_buf called on the dummy
buffer.

Eventually, __sg_alloc_table is called and returns -EINVAL
because nents == 0.

This fix prevents the error by not using the dummy buffer when
the xfer length is zero.

Signed-off-by: Chris Lesiak <chris.lesiak@licor.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Chris Lesiak and committed by
Mark Brown
5442dcaa 0e836c3b

+2
+2
drivers/spi/spi.c
··· 1039 1039 if (max_tx || max_rx) { 1040 1040 list_for_each_entry(xfer, &msg->transfers, 1041 1041 transfer_list) { 1042 + if (!xfer->len) 1043 + continue; 1042 1044 if (!xfer->tx_buf) 1043 1045 xfer->tx_buf = ctlr->dummy_tx; 1044 1046 if (!xfer->rx_buf)