spi: mt7621: Don't leak SPI master in probe error path
authorLukas Wunner <lukas@wunner.de>
Mon, 7 Dec 2020 08:17:14 +0000 (09:17 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 7 Dec 2020 14:18:59 +0000 (14:18 +0000)
commit46b5c4fb87ce8211e0f9b0383dbde72c3652d2ba
treef19d22fa9e7a0238bd5ad3d73c19995e82278486
parent24f7033405abe195224ec793dbc3d7a27dec0b98
spi: mt7621: Don't leak SPI master in probe error path

If the calls to device_reset() or devm_spi_register_controller() fail on
probe of the MediaTek MT7621 SPI driver, the spi_controller struct is
erroneously not freed.  Fix by switching over to the new
devm_spi_alloc_master() helper.

Additionally, there's an ordering issue in mt7621_spi_remove() wherein
the spi_controller is unregistered after disabling the SYS clock.
The correct order is to call spi_unregister_controller() *before* this
teardown step because bus accesses may still be ongoing until that
function returns.

All of these bugs have existed since the driver was first introduced,
so it seems fair to fix them together in a single commit.

Fixes: 1ab7f2a43558 ("staging: mt7621-spi: add mt7621 support")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Stefan Roese <sr@denx.de>
Cc: <stable@vger.kernel.org> # v4.17+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation
Cc: <stable@vger.kernel.org> # v4.17+
Link: https://lore.kernel.org/r/72b680796149f5fcda0b3f530ffb7ee73b04f224.1607286887.git.lukas@wunner.de
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-mt7621.c