Skip to content

Commit 9ed5570

Browse files
joehattoriopsiff
authored andcommitted
regulator: of: Implement the unwind path of of_regulator_match()
[ Upstream commit dddca3b ] of_regulator_match() does not release the OF node reference in the error path, resulting in an OF node leak. Therefore, call of_node_put() on the obtained nodes before returning the EINVAL error. Since it is possible that some drivers call this function and do not exit on failure, such as s2mps11_pmic_driver, clear the init_data and of_node in the error path. This was reported by an experimental verification tool that I am developing. As I do not have access to actual devices nor the QEMU board configuration to test drivers that call this function, no runtime test was able to be performed. Fixes: 1c8fa58 ("regulator: Add generic DT parsing for regulators") Signed-off-by: Joe Hattori <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit c22e13ecc9ca7d23423e28d70170b01d991281a4)
1 parent 330445d commit 9ed5570

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/regulator/of_regulator.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ int of_regulator_match(struct device *dev, struct device_node *node,
435435
"failed to parse DT for regulator %pOFn\n",
436436
child);
437437
of_node_put(child);
438-
return -EINVAL;
438+
goto err_put;
439439
}
440440
match->of_node = of_node_get(child);
441441
count++;
@@ -444,6 +444,18 @@ int of_regulator_match(struct device *dev, struct device_node *node,
444444
}
445445

446446
return count;
447+
448+
err_put:
449+
for (i = 0; i < num_matches; i++) {
450+
struct of_regulator_match *match = &matches[i];
451+
452+
match->init_data = NULL;
453+
if (match->of_node) {
454+
of_node_put(match->of_node);
455+
match->of_node = NULL;
456+
}
457+
}
458+
return -EINVAL;
447459
}
448460
EXPORT_SYMBOL_GPL(of_regulator_match);
449461

0 commit comments

Comments
 (0)