mirror of https://gitee.com/openkylin/linux.git
spi: spi-sh: Fix use-after-free on unbind
spi_sh_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: 680c1305e2
("spi/spi_sh: use spi_unregister_master instead of spi_master_put in remove path")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Cc: <stable@vger.kernel.org> # v3.0+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation
Cc: <stable@vger.kernel.org> # v3.0+
Cc: Axel Lin <axel.lin@ingics.com>
Link: https://lore.kernel.org/r/6d97628b536baf01d5e3e39db61108f84d44c8b2.1607286887.git.lukas@wunner.de
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
6cfd39e212
commit
e77df3eca1
|
@ -440,7 +440,7 @@ static int spi_sh_probe(struct platform_device *pdev)
|
||||||
if (irq < 0)
|
if (irq < 0)
|
||||||
return irq;
|
return irq;
|
||||||
|
|
||||||
master = spi_alloc_master(&pdev->dev, sizeof(struct spi_sh_data));
|
master = devm_spi_alloc_master(&pdev->dev, sizeof(struct spi_sh_data));
|
||||||
if (master == NULL) {
|
if (master == NULL) {
|
||||||
dev_err(&pdev->dev, "spi_alloc_master error.\n");
|
dev_err(&pdev->dev, "spi_alloc_master error.\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -458,16 +458,14 @@ static int spi_sh_probe(struct platform_device *pdev)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_err(&pdev->dev, "No support width\n");
|
dev_err(&pdev->dev, "No support width\n");
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto error1;
|
|
||||||
}
|
}
|
||||||
ss->irq = irq;
|
ss->irq = irq;
|
||||||
ss->master = master;
|
ss->master = master;
|
||||||
ss->addr = devm_ioremap(&pdev->dev, res->start, resource_size(res));
|
ss->addr = devm_ioremap(&pdev->dev, res->start, resource_size(res));
|
||||||
if (ss->addr == NULL) {
|
if (ss->addr == NULL) {
|
||||||
dev_err(&pdev->dev, "ioremap error.\n");
|
dev_err(&pdev->dev, "ioremap error.\n");
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto error1;
|
|
||||||
}
|
}
|
||||||
INIT_LIST_HEAD(&ss->queue);
|
INIT_LIST_HEAD(&ss->queue);
|
||||||
spin_lock_init(&ss->lock);
|
spin_lock_init(&ss->lock);
|
||||||
|
@ -477,7 +475,7 @@ static int spi_sh_probe(struct platform_device *pdev)
|
||||||
ret = request_irq(irq, spi_sh_irq, 0, "spi_sh", ss);
|
ret = request_irq(irq, spi_sh_irq, 0, "spi_sh", ss);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&pdev->dev, "request_irq error\n");
|
dev_err(&pdev->dev, "request_irq error\n");
|
||||||
goto error1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
master->num_chipselect = 2;
|
master->num_chipselect = 2;
|
||||||
|
@ -496,9 +494,6 @@ static int spi_sh_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
error3:
|
error3:
|
||||||
free_irq(irq, ss);
|
free_irq(irq, ss);
|
||||||
error1:
|
|
||||||
spi_master_put(master);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue