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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 May 2021 07:50:11 +0000 (09:50 +0200)
commit05b3f9b0ac32fb3714efa13270700868b3000019
treea0f690176d749dd69a332af55b44de815bc5dee0
parent75a7a8920a57c28cf870bc7644608755a602a82a
spi: stm32: Fix use-after-free on unbind

[ Upstream commit 79c6246ae8793448c05da86a4c82298eed8549b0 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/spi/spi-stm32.c