Skip to content
/ linux Public

Commit 80f3e8c

Browse files
jhovoldgregkh
authored andcommitted
spi: fix use-after-free on controller registration failure
commit 8634e05 upstream. Make sure to deregister from driver core also in the unlikely event that per-cpu statistics allocation fails during controller registration to avoid use-after-free (of driver resources) and unclocked register accesses. Fixes: 6598b91 ("spi: spi.c: Convert statistics to per-cpu u64_stats_t") Cc: stable@vger.kernel.org # 6.0 Cc: David Jander <david@protonic.nl> Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://patch.msgid.link/20260312151817.32100-2-johan@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 18605b1 commit 80f3e8c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/spi/spi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,10 +3344,8 @@ int spi_register_controller(struct spi_controller *ctlr)
33443344
dev_info(dev, "controller is unqueued, this is deprecated\n");
33453345
} else if (ctlr->transfer_one || ctlr->transfer_one_message) {
33463346
status = spi_controller_initialize_queue(ctlr);
3347-
if (status) {
3348-
device_del(&ctlr->dev);
3349-
goto free_bus_id;
3350-
}
3347+
if (status)
3348+
goto del_ctrl;
33513349
}
33523350
/* Add statistics */
33533351
ctlr->pcpu_statistics = spi_alloc_pcpu_stats(dev);
@@ -3370,6 +3368,8 @@ int spi_register_controller(struct spi_controller *ctlr)
33703368

33713369
destroy_queue:
33723370
spi_destroy_queue(ctlr);
3371+
del_ctrl:
3372+
device_del(&ctlr->dev);
33733373
free_bus_id:
33743374
mutex_lock(&board_lock);
33753375
idr_remove(&spi_controller_idr, ctlr->bus_num);

0 commit comments

Comments
 (0)