Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: Avoid a bad reference count on CPU node

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>

authored by

Miquel Sabaté Solà and committed by
Rafael J. Wysocki
c0f02536 8b4865cd

+1 -5
+1 -5
include/linux/cpufreq.h
··· 1107 1107 const char *cell_name, 1108 1108 struct of_phandle_args *args) 1109 1109 { 1110 - struct device_node *cpu_np; 1111 1110 int ret; 1112 1111 1113 - cpu_np = of_cpu_device_node_get(cpu); 1112 + struct device_node *cpu_np __free(device_node) = of_cpu_device_node_get(cpu); 1114 1113 if (!cpu_np) 1115 1114 return -ENODEV; 1116 1115 ··· 1117 1118 args); 1118 1119 if (ret < 0) 1119 1120 return ret; 1120 - 1121 - of_node_put(cpu_np); 1122 - 1123 1121 return 0; 1124 1122 } 1125 1123