Skip to content

Commit 73d5fe0

Browse files
vaishnavachathbroonie
authored andcommitted
spi: cadence-quadspi: Remove spi_master_put() in probe failure path
Currently the spi_master is allocated by devm_spi_alloc_master() and devres core manages the deallocation, but in probe failure path spi_master_put() is being handled manually which causes "refcount underflow use-after-free" warning when probe failure happens after allocating spi_master. Trimmed backtrace during failure: refcount_t: underflow; use-after-free. pc : refcount_warn_saturate+0xf4/0x144 Call trace: refcount_warn_saturate kobject_put put_device devm_spi_release_controller devres_release_all This commit makes relevant changes to remove spi_master_put() from probe failure path. Fixes: 606e5d4 ("spi: cadence-quadspi: Handle spi_unregister_master() in remove()") Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com> Link: https://lore.kernel.org/r/20220601071611.11853-1-vaishnav.a@ti.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent a77c46f commit 73d5fe0

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

drivers/spi/spi-cadence-quadspi.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,16 +1578,15 @@ static int cqspi_probe(struct platform_device *pdev)
15781578
ret = cqspi_of_get_pdata(cqspi);
15791579
if (ret) {
15801580
dev_err(dev, "Cannot get mandatory OF data.\n");
1581-
ret = -ENODEV;
1582-
goto probe_master_put;
1581+
return -ENODEV;
15831582
}
15841583

15851584
/* Obtain QSPI clock. */
15861585
cqspi->clk = devm_clk_get(dev, NULL);
15871586
if (IS_ERR(cqspi->clk)) {
15881587
dev_err(dev, "Cannot claim QSPI clock.\n");
15891588
ret = PTR_ERR(cqspi->clk);
1590-
goto probe_master_put;
1589+
return ret;
15911590
}
15921591

15931592
/* Obtain and remap controller address. */
@@ -1596,7 +1595,7 @@ static int cqspi_probe(struct platform_device *pdev)
15961595
if (IS_ERR(cqspi->iobase)) {
15971596
dev_err(dev, "Cannot remap controller address.\n");
15981597
ret = PTR_ERR(cqspi->iobase);
1599-
goto probe_master_put;
1598+
return ret;
16001599
}
16011600

16021601
/* Obtain and remap AHB address. */
@@ -1605,7 +1604,7 @@ static int cqspi_probe(struct platform_device *pdev)
16051604
if (IS_ERR(cqspi->ahb_base)) {
16061605
dev_err(dev, "Cannot remap AHB address.\n");
16071606
ret = PTR_ERR(cqspi->ahb_base);
1608-
goto probe_master_put;
1607+
return ret;
16091608
}
16101609
cqspi->mmap_phys_base = (dma_addr_t)res_ahb->start;
16111610
cqspi->ahb_size = resource_size(res_ahb);
@@ -1614,15 +1613,13 @@ static int cqspi_probe(struct platform_device *pdev)
16141613

16151614
/* Obtain IRQ line. */
16161615
irq = platform_get_irq(pdev, 0);
1617-
if (irq < 0) {
1618-
ret = -ENXIO;
1619-
goto probe_master_put;
1620-
}
1616+
if (irq < 0)
1617+
return -ENXIO;
16211618

16221619
pm_runtime_enable(dev);
16231620
ret = pm_runtime_resume_and_get(dev);
16241621
if (ret < 0)
1625-
goto probe_master_put;
1622+
return ret;
16261623

16271624
ret = clk_prepare_enable(cqspi->clk);
16281625
if (ret) {
@@ -1716,8 +1713,6 @@ static int cqspi_probe(struct platform_device *pdev)
17161713
probe_clk_failed:
17171714
pm_runtime_put_sync(dev);
17181715
pm_runtime_disable(dev);
1719-
probe_master_put:
1720-
spi_master_put(master);
17211716
return ret;
17221717
}
17231718

0 commit comments

Comments
 (0)