cpufreq: pmac64-cpufreq: Fix refcount leak on error paths
Subsystems (3)
PATCH 1/1 cpufreq: pmac64-cpufreq: Fix refcount leak on error paths
of_cpu_device_node_get obtain a reference to the device node which must be released with of_node_put().
Add missing of_node_put() on error paths to fix.
Found via static analysis and code review.
Fixes 760287ab90a3 ("cpufreq: pmac64-cpufreq: remove device tree parsing for cpu nodes")
Fixes 4350147a816b ("[PATCH] ppc64: SMU based macs cpufreq support")
Signed-off-by Miaoqian Lin <[email protected]>
--- drivers/cpufreq/pmac64-cpufreq.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/cpufreq/pmac64-cpufreq.c +9 -4
@@ -356,8 +356,10 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpunode) use_volts_smu =1 ; else if (of_machine_is_compatible("PowerMac11,2")) use_volts_vdnap =1 ; - else - return -ENODEV; + else { + rc = -ENODEV ; + goto bail_noprops; + }/* Check 970FX for now */ valp =of_get_property (cpunode,"cpu-version" ,NULL );
@@ -430,8 +432,11 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpunode)* supporting anything else. */ valp =of_get_property (cpunode,"clock-frequency" ,NULL ); -if (!valp) -return -ENODEV ; +if (!valp) { + rc = -ENODEV ; + goto bail_noprops; + } + max_freq = (*valp)/1000 ; g5_cpu_freqs[0 ].frequency = max_freq; g5_cpu_freqs[1 ].frequency = max_freq/2 ;
Signature · 1 line
2.25.1
Viresh Kumar
maintainerQuoted 36 lines · Miaoqian Lin
of_cpu_device_node_getobtain a reference to the device node which must be released withof_node_put().Add missing
of_node_put()on error paths to fix.Found via static analysis and code review.
Fixes 760287ab90a3 ("cpufreq: pmac64-cpufreq: remove device tree parsing for cpu nodes")Fixes 4350147a816b ("[PATCH] ppc64: SMU based macs cpufreq support")Signed-off-by Miaoqian Lin <[email protected]>--- drivers/cpufreq/pmac64-cpufreq.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/cpufreq/pmac64-cpufreq.c +4
-2@@ -356,8 +356,10 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpunode) use_volts_smu =1 ; else if (of_machine_is_compatible("PowerMac11,2")) use_volts_vdnap =1 ; - else - return -ENODEV; + else { + rc = -ENODEV ; + goto bail_noprops; + }/* Check 970FX for now */ valp =of_get_property (cpunode,"cpu-version" ,NULL );@@ -430,8 +432,11 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpunode)* supporting anything else. */ valp =of_get_property (cpunode,"clock-frequency" ,NULL );
drivers/cpufreq/pmac64-cpufreq.c static int __init g5_neo2_cpufreq_init(struct device_node *cpunode) · line 442
Quoted 10 lines
drivers/cpufreq/pmac64-cpufreq.c +5
-2-if (!valp) -return -ENODEV ; +if (!valp) { + rc = -ENODEV ; + goto bail_noprops; + } + max_freq = (*valp)/1000 ; g5_cpu_freqs[0 ].frequency = max_freq; g5_cpu_freqs[1 ].frequency = max_freq/2 ;
I would rather handle this in the function that gets the reference of the node in the first place: g5_cpufreq_init().
Signature · 1 line
viresh