]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
spi: Fix zero length xfer bug
authorChris Lesiak <chris.lesiak@licor.com>
Thu, 7 Mar 2019 20:39:00 +0000 (20:39 +0000)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
commitf77b78a4088e8c3670c098b9db5bc1804ea4171a
tree17ce7750f2259251e20d6abb7bd97225efff725c
parent92104f1813e97256316c53eda6ea9c1fec91bb4b
spi: Fix zero length xfer bug

BugLink: https://bugs.launchpad.net/bugs/1838700
[ Upstream commit 5442dcaa0d90fc376bdfc179a018931a8f43dea4 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/spi/spi.c