Skip to content

Commit e13ee6c

Browse files
l1kbroonie
authored andcommitted
spi: bcm2835aux: Fix use-after-free on unbind
bcm2835aux_spi_remove() accesses the driver's private data after calling spi_unregister_master() even though that function releases the last reference on the spi_master 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: b9dd3f6 ("spi: bcm2835aux: Fix controller unregister order") Signed-off-by: Lukas Wunner <lukas@wunner.de> Cc: <stable@vger.kernel.org> # v4.4+: 123456789abc: spi: Introduce device-managed SPI controller allocation Cc: <stable@vger.kernel.org> # v4.4+: b9dd3f6: spi: bcm2835aux: Fix controller unregister order Cc: <stable@vger.kernel.org> # v4.4+ Link: https://lore.kernel.org/r/b290b06357d0c0bdee9cecc539b840a90630f101.1605121038.git.lukas@wunner.de Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent e1483ac commit e13ee6c

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

drivers/spi/spi-bcm2835aux.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
494494
unsigned long clk_hz;
495495
int err;
496496

497-
master = spi_alloc_master(&pdev->dev, sizeof(*bs));
497+
master = devm_spi_alloc_master(&pdev->dev, sizeof(*bs));
498498
if (!master)
499499
return -ENOMEM;
500500

@@ -524,29 +524,24 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
524524

525525
/* the main area */
526526
bs->regs = devm_platform_ioremap_resource(pdev, 0);
527-
if (IS_ERR(bs->regs)) {
528-
err = PTR_ERR(bs->regs);
529-
goto out_master_put;
530-
}
527+
if (IS_ERR(bs->regs))
528+
return PTR_ERR(bs->regs);
531529

532530
bs->clk = devm_clk_get(&pdev->dev, NULL);
533531
if (IS_ERR(bs->clk)) {
534-
err = PTR_ERR(bs->clk);
535532
dev_err(&pdev->dev, "could not get clk: %d\n", err);
536-
goto out_master_put;
533+
return PTR_ERR(bs->clk);
537534
}
538535

539536
bs->irq = platform_get_irq(pdev, 0);
540-
if (bs->irq <= 0) {
541-
err = bs->irq ? bs->irq : -ENODEV;
542-
goto out_master_put;
543-
}
537+
if (bs->irq <= 0)
538+
return bs->irq ? bs->irq : -ENODEV;
544539

545540
/* this also enables the HW block */
546541
err = clk_prepare_enable(bs->clk);
547542
if (err) {
548543
dev_err(&pdev->dev, "could not prepare clock: %d\n", err);
549-
goto out_master_put;
544+
return err;
550545
}
551546

552547
/* just checking if the clock returns a sane value */
@@ -581,8 +576,6 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
581576

582577
out_clk_disable:
583578
clk_disable_unprepare(bs->clk);
584-
out_master_put:
585-
spi_master_put(master);
586579
return err;
587580
}
588581

0 commit comments

Comments
 (0)