]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pmdomain: qcom-cpr: Use scope based of_node_put() to simplify code.
authorZhang Zekun <zhangzekun11@huawei.com>
Wed, 21 Aug 2024 03:40:22 +0000 (11:40 +0800)
committerUlf Hansson <ulf.hansson@linaro.org>
Fri, 13 Sep 2024 09:56:33 +0000 (11:56 +0200)
Use scope based of_node_put() to simplify the code logic, and we don't
need to call of_node_put(). This will simplify the code a lot.

Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
Link: https://lore.kernel.org/r/20240821034022.27394-3-zhangzekun11@huawei.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/pmdomain/qcom/cpr.c

index 1834b3861232e5be86352b8006085c51c30a3623..37b318bf505a1358609df481fe9de73006cad86b 100644 (file)
@@ -1040,36 +1040,30 @@ static unsigned int cpr_get_fuse_corner(struct dev_pm_opp *opp)
 static unsigned long cpr_get_opp_hz_for_req(struct dev_pm_opp *ref,
                                            struct device *cpu_dev)
 {
-       u64 rate = 0;
-       struct device_node *ref_np;
-       struct device_node *desc_np;
-       struct device_node *child_np = NULL;
-       struct device_node *child_req_np = NULL;
+       struct device_node *ref_np __free(device_node) = NULL;
+       struct device_node *desc_np __free(device_node) =
+               dev_pm_opp_of_get_opp_desc_node(cpu_dev);
 
-       desc_np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
        if (!desc_np)
                return 0;
 
        ref_np = dev_pm_opp_get_of_node(ref);
        if (!ref_np)
-               goto out_ref;
+               return 0;
+
+       for_each_available_child_of_node_scoped(desc_np, child_np) {
+               struct device_node *child_req_np __free(device_node) =
+                       of_parse_phandle(child_np, "required-opps", 0);
 
-       for_each_available_child_of_node(desc_np, child_np) {
-               of_node_put(child_req_np);
-               child_req_np = of_parse_phandle(child_np, "required-opps", 0);
                if (child_req_np == ref_np) {
+                       u64 rate;
+
                        of_property_read_u64(child_np, "opp-hz", &rate);
-                       break;
+                       return (unsigned long) rate;
                }
        }
 
-       of_node_put(child_req_np);
-       of_node_put(child_np);
-       of_node_put(ref_np);
-out_ref:
-       of_node_put(desc_np);
-
-       return (unsigned long) rate;
+       return 0;
 }
 
 static int cpr_corner_init(struct cpr_drv *drv)