[PATCH] i2c: st: Fix clock reference leak in st_i2c_probe()

Wentao Liang vulab at iscas.ac.cn
Wed Sep 16 09:02:35 PDT 2026


The clock obtained with of_clk_get_by_name() is never released: the
probe error paths after it, irq request failure, deglitch setup
failure and adapter registration failure, return without clk_put(),
and st_i2c_remove() does not drop the reference either.

Add a cleanup label that drops the clock reference on the probe error
paths and release the reference in the remove path.

Fixes: 85b4fab26960 ("i2c: i2c-st: Add ST I2C controller")
Cc: stable at vger.kernel.org
Signed-off-by: Wentao Liang <vulab at iscas.ac.cn>
---
 drivers/i2c/busses/i2c-st.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c
index 751ea421caaf..2049bbce3656 100644
--- a/drivers/i2c/busses/i2c-st.c
+++ b/drivers/i2c/busses/i2c-st.c
@@ -831,7 +831,7 @@ static int st_i2c_probe(struct platform_device *pdev)
 			IRQF_ONESHOT, pdev->name, i2c_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq);
-		return ret;
+		goto err_clk;
 	}
 
 	pinctrl_pm_select_default_state(i2c_dev->dev);
@@ -840,7 +840,7 @@ static int st_i2c_probe(struct platform_device *pdev)
 
 	ret = st_i2c_of_get_deglitch(np, i2c_dev);
 	if (ret)
-		return ret;
+		goto err_clk;
 
 	adap = &i2c_dev->adap;
 	i2c_set_adapdata(adap, i2c_dev);
@@ -857,13 +857,17 @@ static int st_i2c_probe(struct platform_device *pdev)
 
 	ret = i2c_add_adapter(adap);
 	if (ret)
-		return ret;
+		goto err_clk;
 
 	platform_set_drvdata(pdev, i2c_dev);
 
 	dev_info(i2c_dev->dev, "%s initialized\n", adap->name);
 
 	return 0;
+
+err_clk:
+	clk_put(i2c_dev->clk);
+	return ret;
 }
 
 static void st_i2c_remove(struct platform_device *pdev)
@@ -871,6 +875,7 @@ static void st_i2c_remove(struct platform_device *pdev)
 	struct st_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
 
 	i2c_del_adapter(&i2c_dev->adap);
+	clk_put(i2c_dev->clk);
 }
 
 static const struct of_device_id st_i2c_match[] = {
-- 
2.34.1




More information about the linux-arm-kernel mailing list