aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2014-05-21 09:31:05 -0400
committerSimon Horman <horms+renesas@verge.net.au>2014-06-16 06:52:00 -0400
commitedc8fb1d6ebdfc4efa009073586d3567c3368475 (patch)
tree9037a559fcb690dbf43ddd3b806e42cf5ec03341
parent7171511eaec5bf23fb06078f59784a3a0626b38f (diff)
ARM: shmobile: Fix device node reference leakage in shmobile_init_delay
The of_find_compatible_node() function returns a new reference to the found node. Instead of just adding of_node_put() calls, simplify the code by moving the CPU identification logic inside the loop over cpu nodes, in order to lower complexity from O(n) to O(1) by replacing of_find_compatible_node() calls with of_device_is_compatible(). Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Acked-by: Magnus Damm <damm+renesas@opensource.se> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
-rw-r--r--arch/arm/mach-shmobile/timer.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/arch/arm/mach-shmobile/timer.c b/arch/arm/mach-shmobile/timer.c
index 68bc0b82226d..942efdc82a62 100644
--- a/arch/arm/mach-shmobile/timer.c
+++ b/arch/arm/mach-shmobile/timer.c
@@ -59,29 +59,37 @@ void __init shmobile_setup_delay(unsigned int max_cpu_core_mhz,
59 59
60void __init shmobile_init_delay(void) 60void __init shmobile_init_delay(void)
61{ 61{
62 struct device_node *np, *parent; 62 struct device_node *np, *cpus;
63 u32 max_freq, freq; 63 bool is_a8_a9 = false;
64 64 bool is_a15 = false;
65 max_freq = 0; 65 u32 max_freq = 0;
66 66
67 parent = of_find_node_by_path("/cpus"); 67 cpus = of_find_node_by_path("/cpus");
68 if (parent) { 68 if (!cpus)
69 for_each_child_of_node(parent, np) { 69 return;
70 if (!of_property_read_u32(np, "clock-frequency", &freq)) 70
71 max_freq = max(max_freq, freq); 71 for_each_child_of_node(cpus, np) {
72 } 72 u32 freq;
73 of_node_put(parent); 73
74 } 74 if (!of_property_read_u32(np, "clock-frequency", &freq))
75 max_freq = max(max_freq, freq);
75 76
76 if (max_freq) { 77 if (of_device_is_compatible(np, "arm,cortex-a8") ||
77 if (of_find_compatible_node(NULL, NULL, "arm,cortex-a8")) 78 of_device_is_compatible(np, "arm,cortex-a9"))
78 shmobile_setup_delay_hz(max_freq, 1, 3); 79 is_a8_a9 = true;
79 else if (of_find_compatible_node(NULL, NULL, "arm,cortex-a9")) 80 else if (of_device_is_compatible(np, "arm,cortex-a15"))
80 shmobile_setup_delay_hz(max_freq, 1, 3); 81 is_a15 = true;
81 else if (of_find_compatible_node(NULL, NULL, "arm,cortex-a15"))
82 if (!IS_ENABLED(CONFIG_ARM_ARCH_TIMER))
83 shmobile_setup_delay_hz(max_freq, 2, 4);
84 } 82 }
83
84 of_node_put(cpus);
85
86 if (!max_freq)
87 return;
88
89 if (is_a8_a9)
90 shmobile_setup_delay_hz(max_freq, 1, 3);
91 else if (is_a15 && !IS_ENABLED(CONFIG_ARM_ARCH_TIMER))
92 shmobile_setup_delay_hz(max_freq, 2, 4);
85} 93}
86 94
87static void __init shmobile_late_time_init(void) 95static void __init shmobile_late_time_init(void)