spi: atcspi200: two cleanup
Subsystems (2)
cover spi: atcspi200: two cleanup
---
Felix Gu (2):
spi: atcspi200: fix use-after-free when driver unbind
spi: atcspi200: switch to devm functions
drivers/spi/spi-atcspi200.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
---
base-commit: 936c21068d7ade00325e40d82bfd2f3f29d9f659
change-id: 20260416-atcspi-96784f8f2a56
Best regards,
Signature · 1 line
Felix Gu <[email protected]>
PATCH 1/2 spi: atcspi200: fix use-after-free when driver unbind
DMA resource is initialized after SPI controller registration. So when driver unbind, this can trigger a use-after-free when DMA is torn down while the controller is still alive and triggers DMA transfers.
--- drivers/spi/spi-atcspi200.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/spi/spi-atcspi200.c +7 -6
@@ -575,12 +575,6 @@ static int atcspi_probe(struct platform_device *pdev)if (ret) goto free_controller; - ret =devm_spi_register_controller (&pdev->dev, host); -if (ret) { -dev_err_probe (spi->dev, ret, -"Failed to register SPI controller\n" ); - goto free_controller; - } spi->use_dma = false;if (ATCSPI_DMA_SUPPORT ) { ret =atcspi_configure_dma (spi);
@@ -591,6 +585,13 @@ static int atcspi_probe(struct platform_device *pdev) spi->use_dma = true; } + ret =devm_spi_register_controller (&pdev->dev, host); +if (ret) { +dev_err_probe (spi->dev, ret, +"Failed to register SPI controller\n" ); + goto free_controller; + } +return 0 ; free_controller:
Signature · 1 line
2.43.0
PATCH 2/2 spi: atcspi200: switch to devm functions
In reply to Felix GuSwitch to use devm_spi_alloc_host and devm_mutex_init to make code clean.
--- drivers/spi/spi-atcspi200.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/spi/spi-atcspi200.c +10 -15
@@ -550,7 +550,7 @@ static int atcspi_probe(struct platform_device *pdev)struct resource *mem_res;int ret; - host =spi_alloc_host (&pdev->dev,sizeof (*spi)); + host =devm_spi_alloc_host (&pdev->dev,sizeof (*spi));if (!host)return -ENOMEM ;
@@ -559,21 +559,23 @@ static int atcspi_probe(struct platform_device *pdev) spi->dev = &pdev->dev;dev_set_drvdata (&pdev->dev, host); -mutex_init (&spi->mutex_lock); + ret =devm_mutex_init (&pdev->dev, &spi->mutex_lock); +if (ret) +return ret; ret =atcspi_init_resources (pdev, spi, &mem_res);if (ret) - goto free_controller; +return ret; ret =atcspi_enable_clk (spi);if (ret) - goto free_controller; +return ret;atcspi_init_controller (pdev, spi, host, mem_res); ret =atcspi_setup (spi);if (ret) - goto free_controller; +return ret; spi->use_dma = false;if (ATCSPI_DMA_SUPPORT ) {
@@ -586,18 +588,11 @@ static int atcspi_probe(struct platform_device *pdev) } ret =devm_spi_register_controller (&pdev->dev, host); -if (ret) { -dev_err_probe (spi->dev, ret, -"Failed to register SPI controller\n" ); - goto free_controller; - } +if (ret) +return dev_err_probe (spi->dev, ret, +"Failed to register SPI controller\n" );return 0 ; - -free_controller: -mutex_destroy (&spi->mutex_lock); -spi_controller_put (host); -return ret; }static int atcspi_suspend (struct device *dev)
Signature · 1 line
2.43.0
Mark Brown
maintainerQuoted 1 line · Felix Gu
spi: atcspi200: two cleanup
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.2
Thanks!
[1/2] spi: atcspi200: fix use-after-free when driver unbind
https://git.kernel.org/broonie/spi/c/565bdf45125a [2/2] spi: atcspi200: switch to devm functions https://git.kernel.org/broonie/spi/c/aaea50c3bd76
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark