]> git.baikalelectronics.ru Git - kernel.git/commit
spi: core: Fix deadlock when sending messages
authorJon Hunter <jonathanh@nvidia.com>
Tue, 8 Mar 2016 12:28:20 +0000 (12:28 +0000)
committerMark Brown <broonie@kernel.org>
Wed, 9 Mar 2016 02:31:39 +0000 (09:31 +0700)
commit115f63c81b2c036ed9f58c020d23e8cd357fdc47
tree4550038559a27f6698a6702b3ee20c833a669f7c
parent5c3748d785d5f67c3b1df911d437c05e864d3652
spi: core: Fix deadlock when sending messages

The function __spi_pump_messages() is called by spi_pump_messages() and
__spi_sync(). The function __spi_sync() has an argument 'bus_locked'
that indicates if it is called with the SPI bus mutex held or not. If
'bus_locked' is false then __spi_sync() will acquire the mutex itself.

Commit 4a2c3ca0e466 ("spi: introduce accelerated read support for spi
flash devices") made a change to acquire the SPI bus mutex within
__spi_pump_messages(). However, this change did not check to see if the
mutex is already held. If __spi_sync() is called with the mutex held
(ie. 'bus_locked' is true), then a deadlock occurs when
__spi_pump_messages() is called.

Fix this deadlock by passing the 'bus_locked' state from __spi_sync() to
__spi_pump_messages() and only acquire the mutex if not already held. In
the case where __spi_pump_messages() is called from spi_pump_messages()
it is assumed that the mutex is not held and so call
__spi_pump_messages() with 'bus_locked' set to false. Finally, move the
unlocking of the mutex to the end of the __spi_pump_messages() function
to simplify the code and only call cond_resched() if there are no
errors.

Fixes: 4a2c3ca0e466 ("spi: introduce accelerated read support for spi flash devices")
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c