spi: rpc-if: Fix use-after-free on unbind

rpcif_spi_remove() accesses the driver's private data after calling
spi_unregister_controller() even though that function releases the last
reference on the spi_controller 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: eb8d6d464a ("spi: add Renesas RPC-IF driver")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Cc: <stable@vger.kernel.org> # v5.9+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation
Cc: <stable@vger.kernel.org> # v5.9+
Cc: Sergei Shtylyov <s.shtylyov@omprussia.ru>
Link: https://lore.kernel.org/r/c5da472c28021da2f6517441685cef033d40b140.1607286887.git.lukas@wunner.de
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Lukas Wunner 2020-12-07 09:17:06 +01:00 committed by Mark Brown
parent 5626308bb9
commit 393f981ca5
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
1 changed files with 2 additions and 7 deletions

View File

@ -134,7 +134,7 @@ static int rpcif_spi_probe(struct platform_device *pdev)
struct rpcif *rpc; struct rpcif *rpc;
int error; int error;
ctlr = spi_alloc_master(&pdev->dev, sizeof(*rpc)); ctlr = devm_spi_alloc_master(&pdev->dev, sizeof(*rpc));
if (!ctlr) if (!ctlr)
return -ENOMEM; return -ENOMEM;
@ -159,13 +159,8 @@ static int rpcif_spi_probe(struct platform_device *pdev)
error = spi_register_controller(ctlr); error = spi_register_controller(ctlr);
if (error) { if (error) {
dev_err(&pdev->dev, "spi_register_controller failed\n"); dev_err(&pdev->dev, "spi_register_controller failed\n");
goto err_put_ctlr; rpcif_disable_rpm(rpc);
} }
return 0;
err_put_ctlr:
rpcif_disable_rpm(rpc);
spi_controller_put(ctlr);
return error; return error;
} }