[PATCH] soc: mediatek: mtk-svs: Fix device leak in svs_add_device_link()

Wentao Liang posted 1 patch 1 week ago
drivers/soc/mediatek/mtk-svs.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] soc: mediatek: mtk-svs: Fix device leak in svs_add_device_link()
Posted by Wentao Liang 1 week ago
svs_get_subsys_device() returns a reference to the supplier device that
the caller must drop.  svs_add_device_link() returns the reference to
its callers on success, but the device_link_add() failure path and the
probe deferral path return an error pointer without putting the device,
so the reference is leaked.

Drop the reference on both error paths.

Fixes: 681a02e95000 ("soc: mediatek: SVS: introduce MTK SVS engine")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/soc/mediatek/mtk-svs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/mediatek/mtk-svs.c b/drivers/soc/mediatek/mtk-svs.c
index 99edecb204f2..dd9643026c66 100644
--- a/drivers/soc/mediatek/mtk-svs.c
+++ b/drivers/soc/mediatek/mtk-svs.c
@@ -2155,11 +2155,14 @@ static struct device *svs_add_device_link(struct svs_platform *svsp,
 				   DL_FLAG_AUTOREMOVE_CONSUMER);
 	if (!sup_link) {
 		dev_err(svsp->dev, "sup_link is NULL\n");
+		put_device(dev);
 		return ERR_PTR(-EINVAL);
 	}
 
-	if (sup_link->supplier->links.status != DL_DEV_DRIVER_BOUND)
+	if (sup_link->supplier->links.status != DL_DEV_DRIVER_BOUND) {
+		put_device(dev);
 		return ERR_PTR(-EPROBE_DEFER);
+	}
 
 	return dev;
 }
-- 
2.34.1