]> git.ipfire.org Git - thirdparty/linux.git/commit
spi: spidev: fix a race condition when accessing spidev->spi
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 6 Jan 2023 10:07:18 +0000 (11:07 +0100)
committerMark Brown <broonie@kernel.org>
Wed, 11 Jan 2023 14:15:10 +0000 (14:15 +0000)
commita720416d94634068951773cb9e9d6f1b73769e5b
treeb793e5cfbf2e810155721e0433865257edf0de6c
parente8bb8f19e73a1e855e54788f8673b9b49e46b5cd
spi: spidev: fix a race condition when accessing spidev->spi

There's a spinlock in place that is taken in file_operations callbacks
whenever we check if spidev->spi is still alive (not null). It's also
taken when spidev->spi is set to NULL in remove().

This however doesn't protect the code against driver unbind event while
one of the syscalls is still in progress. To that end we need a lock taken
continuously as long as we may still access spidev->spi. As both the file
ops and the remove callback are never called from interrupt context, we
can replace the spinlock with a mutex.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Link: https://lore.kernel.org/r/20230106100719.196243-1-brgl@bgdev.pl
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spidev.c