提交 9506e9ea 编写于 作者: U Uwe Kleine-König 提交者: Yang Yingliang

spi: fix resource leak for drivers without .remove callback

stable inclusion
from linux-4.19.164
commit d85ed98f5a91acb93b23b0e648f9c5c8fb426f14

--------------------------------

[ Upstream commit 440408db ]

Consider an spi driver with a .probe but without a .remove callback (e.g.
rtc-ds1347). The function spi_drv_probe() is called to bind a device and
so dev_pm_domain_attach() is called. As there is no remove callback
spi_drv_remove() isn't called at unbind time however and so calling
dev_pm_domain_detach() is missed and the pm domain keeps active.

To fix this always use both spi_drv_probe() and spi_drv_remove() and
make them handle the respective callback not being set. This has the
side effect that for a (hypothetical) driver that has neither .probe nor
remove the clk and pm domain setup is done.

Fixes: 33cf00e5 ("spi: attach/detach SPI device to the ACPI power domain")
Signed-off-by: NUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20201119161604.2633521-1-u.kleine-koenig@pengutronix.deSigned-off-by: NMark Brown <broonie@kernel.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
上级 861ef070
...@@ -362,9 +362,11 @@ static int spi_drv_probe(struct device *dev) ...@@ -362,9 +362,11 @@ static int spi_drv_probe(struct device *dev)
if (ret) if (ret)
return ret; return ret;
if (sdrv->probe) {
ret = sdrv->probe(spi); ret = sdrv->probe(spi);
if (ret) if (ret)
dev_pm_domain_detach(dev, true); dev_pm_domain_detach(dev, true);
}
return ret; return ret;
} }
...@@ -372,8 +374,9 @@ static int spi_drv_probe(struct device *dev) ...@@ -372,8 +374,9 @@ static int spi_drv_probe(struct device *dev)
static int spi_drv_remove(struct device *dev) static int spi_drv_remove(struct device *dev)
{ {
const struct spi_driver *sdrv = to_spi_driver(dev->driver); const struct spi_driver *sdrv = to_spi_driver(dev->driver);
int ret; int ret = 0;
if (sdrv->remove)
ret = sdrv->remove(to_spi_device(dev)); ret = sdrv->remove(to_spi_device(dev));
dev_pm_domain_detach(dev, true); dev_pm_domain_detach(dev, true);
...@@ -399,9 +402,7 @@ int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) ...@@ -399,9 +402,7 @@ int __spi_register_driver(struct module *owner, struct spi_driver *sdrv)
{ {
sdrv->driver.owner = owner; sdrv->driver.owner = owner;
sdrv->driver.bus = &spi_bus_type; sdrv->driver.bus = &spi_bus_type;
if (sdrv->probe)
sdrv->driver.probe = spi_drv_probe; sdrv->driver.probe = spi_drv_probe;
if (sdrv->remove)
sdrv->driver.remove = spi_drv_remove; sdrv->driver.remove = spi_drv_remove;
if (sdrv->shutdown) if (sdrv->shutdown)
sdrv->driver.shutdown = spi_drv_shutdown; sdrv->driver.shutdown = spi_drv_shutdown;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册