summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAtish Patra <atish.patra@wdc.com>2019-02-13 15:18:10 -0500
committerDaniel Lezcano <daniel.lezcano@linaro.org>2019-02-23 06:13:45 -0500
commit26478b2f6a06ca36816e8f473aebe6f686b0df90 (patch)
tree834cf937888db0d419c8428c2caa1c2cf0af5a33
parent29f970cf670f12d72580662b2f291cf2dc86aaf5 (diff)
clocksource/drivers/riscv: Add required checks during clock source init
Currently, clocksource registration happens for an invalid cpu for non-smp kernels. This lead to kernel panic as cpu hotplug registration will fail for those cpus. Moreover, riscv_hartid_to_cpuid can return errors now. Do not proceed if hartid or cpuid is invalid. Take this opportunity to print appropriate error strings for different failure cases. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Palmer Dabbelt <palmer@sifive.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--drivers/clocksource/timer-riscv.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c
index 431892200a08..e8163693e936 100644
--- a/drivers/clocksource/timer-riscv.c
+++ b/drivers/clocksource/timer-riscv.c
@@ -95,13 +95,30 @@ static int __init riscv_timer_init_dt(struct device_node *n)
95 struct clocksource *cs; 95 struct clocksource *cs;
96 96
97 hartid = riscv_of_processor_hartid(n); 97 hartid = riscv_of_processor_hartid(n);
98 if (hartid < 0) {
99 pr_warn("Not valid hartid for node [%pOF] error = [%d]\n",
100 n, hartid);
101 return hartid;
102 }
103
98 cpuid = riscv_hartid_to_cpuid(hartid); 104 cpuid = riscv_hartid_to_cpuid(hartid);
105 if (cpuid < 0) {
106 pr_warn("Invalid cpuid for hartid [%d]\n", hartid);
107 return cpuid;
108 }
99 109
100 if (cpuid != smp_processor_id()) 110 if (cpuid != smp_processor_id())
101 return 0; 111 return 0;
102 112
113 pr_info("%s: Registering clocksource cpuid [%d] hartid [%d]\n",
114 __func__, cpuid, hartid);
103 cs = per_cpu_ptr(&riscv_clocksource, cpuid); 115 cs = per_cpu_ptr(&riscv_clocksource, cpuid);
104 clocksource_register_hz(cs, riscv_timebase); 116 error = clocksource_register_hz(cs, riscv_timebase);
117 if (error) {
118 pr_err("RISCV timer register failed [%d] for cpu = [%d]\n",
119 error, cpuid);
120 return error;
121 }
105 122
106 sched_clock_register(riscv_sched_clock, 123 sched_clock_register(riscv_sched_clock,
107 BITS_PER_LONG, riscv_timebase); 124 BITS_PER_LONG, riscv_timebase);
@@ -110,8 +127,8 @@ static int __init riscv_timer_init_dt(struct device_node *n)
110 "clockevents/riscv/timer:starting", 127 "clockevents/riscv/timer:starting",
111 riscv_timer_starting_cpu, riscv_timer_dying_cpu); 128 riscv_timer_starting_cpu, riscv_timer_dying_cpu);
112 if (error) 129 if (error)
113 pr_err("RISCV timer register failed [%d] for cpu = [%d]\n", 130 pr_err("cpu hp setup state failed for RISCV timer [%d]\n",
114 error, cpuid); 131 error);
115 return error; 132 return error;
116} 133}
117 134