]> git.dujemihanovic.xyz Git - linux.git/commitdiff
cpufreq: Avoid a bad reference count on CPU node
authorMiquel Sabaté Solà <mikisabate@gmail.com>
Tue, 17 Sep 2024 13:42:46 +0000 (15:42 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 1 Oct 2024 18:43:44 +0000 (20:43 +0200)
In the parse_perf_domain function, if the call to
of_parse_phandle_with_args returns an error, then the reference to the
CPU device node that was acquired at the start of the function would not
be properly decremented.

Address this by declaring the variable with the __free(device_node)
cleanup attribute.

Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://patch.msgid.link/20240917134246.584026-1-mikisabate@gmail.com
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
include/linux/cpufreq.h

index e0e19d9c13231ce96218f15fcbf82c4316ebb986..7fe0981a7e4674f801201c11e7ebaf9c1b9e34d9 100644 (file)
@@ -1107,10 +1107,9 @@ static inline int parse_perf_domain(int cpu, const char *list_name,
                                    const char *cell_name,
                                    struct of_phandle_args *args)
 {
-       struct device_node *cpu_np;
        int ret;
 
-       cpu_np = of_cpu_device_node_get(cpu);
+       struct device_node *cpu_np __free(device_node) = of_cpu_device_node_get(cpu);
        if (!cpu_np)
                return -ENODEV;
 
@@ -1118,9 +1117,6 @@ static inline int parse_perf_domain(int cpu, const char *list_name,
                                         args);
        if (ret < 0)
                return ret;
-
-       of_node_put(cpu_np);
-
        return 0;
 }