spi: lpspi: Fix use-after-free on unbind
authorLukas Wunner <lukas@wunner.de>
Sun, 8 Nov 2020 22:41:00 +0000 (23:41 +0100)
committerMark Brown <broonie@kernel.org>
Thu, 12 Nov 2020 18:45:56 +0000 (18:45 +0000)
commit4def49da620c84a682d9361d6bef0a97eed46fe0
treee82d40796ad98670819b98451647b1b58a0d17f5
parentee4ad5d06509b3aea79b6a77bebd09ef891bed8d
spi: lpspi: Fix use-after-free on unbind

Normally the last reference on an spi_controller is released by
spi_unregister_controller().  In the case of the i.MX lpspi driver,
the spi_controller is registered with devm_spi_register_controller(),
so spi_unregister_controller() is invoked automatically after the driver
has unbound.

However the driver already releases the last reference in
fsl_lpspi_remove() through a gratuitous call to spi_master_put(),
causing a use-after-free when spi_unregister_controller() is
subsequently invoked by the devres framework.

Fix by dropping the superfluous spi_master_put().

Fixes: 944c01a889d9 ("spi: lpspi: enable runtime pm for lpspi")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Cc: <stable@vger.kernel.org> # v5.2+
Cc: Han Xu <han.xu@nxp.com>
Link: https://lore.kernel.org/r/ab3c0b18bd820501a12c85e440006e09ec0e275f.1604874488.git.lukas@wunner.de
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-fsl-lpspi.c