[PATCH] regulator: core: Fix coupled regulators reference leak on removal

Wentao Liang posted 1 patch 1 week ago
drivers/regulator/core.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] regulator: core: Fix coupled regulators reference leak on removal
Posted by Wentao Liang 1 week ago
of_parse_coupled_regulator() returns the coupled regulator with its
device reference incremented and regulator_resolve_coupling() stores it
in coupling_desc.coupled_rdevs[]. regulator_remove_coupling() clears
those pointers without dropping the references, so they are leaked when
the couple is torn down.

Release the reference of each coupled regulator while removing the
coupling.

Fixes: d3d64537c339 ("regulator: core: Resolve coupled regulators")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/regulator/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 31893c7decd5..59506547458e 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -5891,6 +5891,8 @@ static void regulator_remove_coupling(struct regulator_dev *rdev)
 
 		c_desc->coupled_rdevs[i] = NULL;
 		c_desc->n_resolved--;
+
+		put_device(&c_rdev->dev);
 	}
 
 	if (coupler && coupler->detach_regulator) {
-- 
2.34.1