Message ID | 20240926012551.31712-3-zhangzekun11@huawei.com (mailing list archive) |
---|---|
State | Handled Elsewhere, archived |
Headers | show |
Series | Some cleanup and fix the missing of_node_put() | expand |
On Sep 26, 2024 at 09:25:51 +0800, Zhang Zekun wrote: > Use scope based of_node_put() to simplify the code logic, and we don't > need to call of_node_put(). Besides, put of_parse_phandle_with_args() in > the while loop to make code more simple. > > Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com> > --- > drivers/pmdomain/ti/ti_sci_pm_domains.c | 20 ++++++-------------- > 1 file changed, 6 insertions(+), 14 deletions(-) > > diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c > index 0df3eb7ff09a..83729bc52c09 100644 > --- a/drivers/pmdomain/ti/ti_sci_pm_domains.c > +++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c > @@ -131,9 +131,8 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) > struct device *dev = &pdev->dev; > struct ti_sci_genpd_provider *pd_provider; > struct ti_sci_pm_domain *pd; > - struct device_node *np; > + struct device_node *np __free(device_node) = NULL; > struct of_phandle_args args; > - int ret; > u32 max_id = 0; > int index; > > @@ -153,12 +152,9 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) > for_each_node_with_property(np, "power-domains") { > index = 0; > > - while (1) { > - ret = of_parse_phandle_with_args(np, "power-domains", > - "#power-domain-cells", > - index, &args); > - if (ret) > - break; > + while (!of_parse_phandle_with_args(np, "power-domains", > + "#power-domain-cells", > + index, &args)) { > > if (args.args_count >= 1 && args.np == dev->of_node) { > of_node_put(args.np); > @@ -172,18 +168,14 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) > } > > pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); > - if (!pd) { > - of_node_put(np); > + if (!pd) > return -ENOMEM; > - } > > pd->pd.name = devm_kasprintf(dev, GFP_KERNEL, > "pd:%d", > args.args[0]); > - if (!pd->pd.name) { > - of_node_put(np); > + if (!pd->pd.name) > return -ENOMEM; > - } Actually, just noticed there's a chance that we return early inside this if block, so the else part now makes sense to me in the previous patch. Please ignore my code comment but fix the commit message if you re spin. Reviewed-by: Dhruva Gole <d-gole@ti.com>
diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c index 0df3eb7ff09a..83729bc52c09 100644 --- a/drivers/pmdomain/ti/ti_sci_pm_domains.c +++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c @@ -131,9 +131,8 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct ti_sci_genpd_provider *pd_provider; struct ti_sci_pm_domain *pd; - struct device_node *np; + struct device_node *np __free(device_node) = NULL; struct of_phandle_args args; - int ret; u32 max_id = 0; int index; @@ -153,12 +152,9 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) for_each_node_with_property(np, "power-domains") { index = 0; - while (1) { - ret = of_parse_phandle_with_args(np, "power-domains", - "#power-domain-cells", - index, &args); - if (ret) - break; + while (!of_parse_phandle_with_args(np, "power-domains", + "#power-domain-cells", + index, &args)) { if (args.args_count >= 1 && args.np == dev->of_node) { of_node_put(args.np); @@ -172,18 +168,14 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) } pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); - if (!pd) { - of_node_put(np); + if (!pd) return -ENOMEM; - } pd->pd.name = devm_kasprintf(dev, GFP_KERNEL, "pd:%d", args.args[0]); - if (!pd->pd.name) { - of_node_put(np); + if (!pd->pd.name) return -ENOMEM; - } pd->pd.power_off = ti_sci_pd_power_off; pd->pd.power_on = ti_sci_pd_power_on;
Use scope based of_node_put() to simplify the code logic, and we don't need to call of_node_put(). Besides, put of_parse_phandle_with_args() in the while loop to make code more simple. Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com> --- drivers/pmdomain/ti/ti_sci_pm_domains.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)