[PATCH v2 18/20] pinctrl: freescale: mxs: Fix refcount of child

Peng Fan (OSS) posted 20 patches 4 months, 2 weeks ago
[PATCH v2 18/20] pinctrl: freescale: mxs: Fix refcount of child
Posted by Peng Fan (OSS) 4 months, 2 weeks ago
From: Peng Fan <peng.fan@nxp.com>

of_get_next_child() will increase refcount of the returned node, need
use of_node_put() on it when done.

Per current implementation, 'child' will be override by
for_each_child_of_node(np, child), so use of_get_child_count to avoid
refcount leakage.

Fixes: 17723111e64f ("pinctrl: add pinctrl-mxs support")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/pinctrl/freescale/pinctrl-mxs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/freescale/pinctrl-mxs.c b/drivers/pinctrl/freescale/pinctrl-mxs.c
index aee70fa55bec..edb242d30609 100644
--- a/drivers/pinctrl/freescale/pinctrl-mxs.c
+++ b/drivers/pinctrl/freescale/pinctrl-mxs.c
@@ -413,8 +413,8 @@ static int mxs_pinctrl_probe_dt(struct platform_device *pdev,
 	int ret;
 	u32 val;
 
-	child = of_get_next_child(np, NULL);
-	if (!child) {
+	val = of_get_child_count(np);
+	if (val == 0) {
 		dev_err(&pdev->dev, "no group is defined\n");
 		return -ENOENT;
 	}

-- 
2.37.1
Re: [PATCH v2 18/20] pinctrl: freescale: mxs: Fix refcount of child
Posted by Markus Elfring 3 months, 3 weeks ago
How do you think about to use the summary phrase “Fix reference counting for children in mxs_pinctrl_probe_dt()”?


…
> of_get_next_child() will increase refcount …

                                    the reference counter?


> Per current implementation, 'child' will be override by

                                              overridden?


> for_each_child_of_node(np, child), so use of_get_child_count to avoid
> refcount leakage.

Another wording suggestion:
  for_each_child_of_node(np, child). Thus use an of_get_child_count() call
  to avoid reference counting leakage.


Regards,
Markus