Skip to contentSkip to conversation

regulator: tps6594: Fix device node reference leaks in multiphase loop

PATCH Applied Uday Khare 2 participants 4 messages Jun 18 1 message not in the archive Voltage and current regulator framework

lore
Share & tools
lore

Uday Khare

author
#0 lore raw

PATCH 4/4 regulator: tps6594: Fix device node reference leaks in multiphase loop

In tps6594_regulator_probe(), the multi-phase configuration loop calls of_find_node_by_name() to find buck nodes by name, and of_get_parent() twice to navigate to the PMIC parent node. None of the acquired node references (np, intermediate parent, np_pmic_parent) are ever released via of_node_put(), causing a reference leak on every loop iteration.

Additionally, of_find_node_by_name() can return NULL, but the result was immediately passed to of_node_full_name() and of_get_parent() without a NULL check, which could lead to a NULL pointer dereference.

Fix this by:
- Adding a NULL check for np after of_find_node_by_name()
- Storing the intermediate parent node in a local variable np_parent
- Calling of_node_put() on np, np_parent and np_pmic_parent at the end of each loop iteration

Fixes f17ccc5deb4d ("regulator: tps6594-regulator: Add driver for TI TPS6594 regulators")
---
 drivers/regulator/tps6594-regulator.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/regulator/tps6594-regulator.c +15 -4
index 645e83462c64..31a5218d5510 100644
@@ -669,13 +669,20 @@ static int tps6594_regulator_probe(struct platform_device *pdev)
 	 * buck_configured to avoid creating bucks for every buck in multiphase
 	 */
 	for (multi = 0; multi < desc->num_multi_phase_regs; multi++) {
+		struct device_node *np_parent;
+
 		multi_regs = &desc->multi_phase_regs[multi];
 		np = of_find_node_by_name(tps->dev->of_node, multi_regs->supply_name);
-		npname = of_node_full_name(np);
-		np_pmic_parent = of_get_parent(of_get_parent(np));
-		if (of_node_cmp(of_node_full_name(np_pmic_parent), tps->dev->of_node->full_name))
+		if (!np)
 			continue;
-		if (strcmp(npname, multi_regs->supply_name) == 0) {
+
+		npname = of_node_full_name(np);
+		np_parent = of_get_parent(np);
+		np_pmic_parent = of_get_parent(np_parent);
+
+		if (np_pmic_parent &&
+		    !of_node_cmp(of_node_full_name(np_pmic_parent), tps->dev->of_node->full_name) &&
+		    strcmp(npname, multi_regs->supply_name) == 0) {
 			switch (multi) {
 			case MULTI_BUCK12:
 				buck_multi[0] = true;
@@ -706,6 +713,10 @@ static int tps6594_regulator_probe(struct platform_device *pdev)
 				break;
 			}
 		}
+
+		of_node_put(np_pmic_parent);
+		of_node_put(np_parent);
+		of_node_put(np);
 	}
 
 	reg_irq_nb = desc->num_irq_types * (desc->num_buck_regs + desc->num_ldo_regs);
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 5 lines · Uday Khare

In tps6594_regulator_probe(), the multi-phase configuration loop calls of_find_node_by_name() to find buck nodes by name, and of_get_parent() twice to navigate to the PMIC parent node. None of the acquired node references (np, intermediate parent, np_pmic_parent) are ever released via of_node_put(), causing a reference leak on every loop iteration.

You've not copied me on the rest of the series so I don't know what's going on with dependencies. When sending a patch series it is important to ensure that all the various maintainers understand what the relationship between the patches as the expecation is that there will be interdependencies. Either copy everyone on the whole series or at least copy them on the cover letter and explain what's going on. If there are no strong interdependencies then it's generally simplest to just send the patches separately to avoid any possible confusion.

author
#2 lore raw

Thank you for the feedback.

The 4 patches in this series fix independent resource leaks in 4 separate drivers across different subsystems (remoteproc, i2c, power supply, and regulator). There are no interdependencies between them. Each patch can be applied independently to its respective subsystem tree.

I sent them as a numbered series (1/4 through 4/4) for organizational clarity, but they can be picked up separately.

Apologies for the confusion.

A message that is not in the archive (sent off-list or not yet received): CAFVYD-Hq+kfe2R28HhjMHboVjt6dZDf-85CJfvMfT6BdMVKdew@mail.gmail.com

maintainer
#4 lore raw
Quoted 9 lines · Uday Khare

Thank you for the feedback.

The 4 patches in this series fix independent resource leaks in 4 separate drivers across different subsystems (remoteproc, i2c, power supply, and regulator). There are no interdependencies between them. Each patch can be applied independently to its respective subsystem tree.

I sent them as a numbered series (1/4 through 4/4) for organizational clarity, but they can be picked up separately.

I see. Doing that actually makes things less clear since normally things sent in a series need to be applied together and if things cross subsystems that needs coordination. If there are no dependencies then you should send a series per subsystem.