spi: stm32: Fix use-after-free on unbind
authorAlain Volmat <alain.volmat@foss.st.com>
Thu, 18 Mar 2021 07:24:50 +0000 (08:24 +0100)
committerMark Brown <broonie@kernel.org>
Fri, 19 Mar 2021 12:24:09 +0000 (12:24 +0000)
commit79c6246ae8793448c05da86a4c82298eed8549b0
tree1e8468df61a64f3e33fa8db441d5a3e861344738
parent92bad4a4c755cdf286f6b303dd482a573f2b89e6
spi: stm32: Fix use-after-free on unbind

stm32_spi_remove() accesses the driver's private data after calling
spi_unregister_master() even though that function releases the last
reference on the spi_master and thereby frees the private data.

Fix by switching over to the new devm_spi_alloc_master() helper which
keeps the private data accessible until the driver has unbound.

Fixes: 8d559a64f00b ("spi: stm32: drop devres version of spi_register_master")
Reported-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Link: https://lore.kernel.org/r/1616052290-10887-1-git-send-email-alain.volmat@foss.st.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-stm32.c