Skip to content

Commit 0586421

Browse files
author
Daniel Lezcano
committed
clocksource/drivers/microblaze: Convert init function to return error
The init functions do not return any error. They behave as the following: - panic, thus leading to a kernel crash while another timer may work and make the system boot up correctly or - print an error and let the caller unaware if the state of the system Change that by converting the init functions to return an error conforming to the CLOCKSOURCE_OF_RET prototype. Proper error handling (rollback, errno value) will be changed later case by case, thus this change just return back an error or success in the init function. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
1 parent 4245250 commit 0586421

1 file changed

Lines changed: 38 additions & 13 deletions

File tree

‎arch/microblaze/kernel/timer.c‎

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static struct irqaction timer_irqaction = {
170170
.dev_id = &clockevent_xilinx_timer,
171171
};
172172

173-
static __init void xilinx_clockevent_init(void)
173+
static __init int xilinx_clockevent_init(void)
174174
{
175175
clockevent_xilinx_timer.mult =
176176
div_sc(timer_clock_freq, NSEC_PER_SEC,
@@ -181,6 +181,8 @@ static __init void xilinx_clockevent_init(void)
181181
clockevent_delta2ns(1, &clockevent_xilinx_timer);
182182
clockevent_xilinx_timer.cpumask = cpumask_of(0);
183183
clockevents_register_device(&clockevent_xilinx_timer);
184+
185+
return 0;
184186
}
185187

186188
static u64 xilinx_clock_read(void)
@@ -229,8 +231,14 @@ static struct clocksource clocksource_microblaze = {
229231

230232
static int __init xilinx_clocksource_init(void)
231233
{
232-
if (clocksource_register_hz(&clocksource_microblaze, timer_clock_freq))
233-
panic("failed to register clocksource");
234+
int ret;
235+
236+
ret = clocksource_register_hz(&clocksource_microblaze,
237+
timer_clock_freq);
238+
if (ret) {
239+
pr_err("failed to register clocksource");
240+
return ret;
241+
}
234242

235243
/* stop timer1 */
236244
write_fn(read_fn(timer_baseaddr + TCSR1) & ~TCSR_ENT,
@@ -239,16 +247,16 @@ static int __init xilinx_clocksource_init(void)
239247
write_fn(TCSR_TINT|TCSR_ENT|TCSR_ARHT, timer_baseaddr + TCSR1);
240248

241249
/* register timecounter - for ftrace support */
242-
init_xilinx_timecounter();
243-
return 0;
250+
return init_xilinx_timecounter();
244251
}
245252

246-
static void __init xilinx_timer_init(struct device_node *timer)
253+
static int __init xilinx_timer_init(struct device_node *timer)
247254
{
248255
struct clk *clk;
249256
static int initialized;
250257
u32 irq;
251258
u32 timer_num = 1;
259+
int ret;
252260

253261
if (initialized)
254262
return;
@@ -258,7 +266,7 @@ static void __init xilinx_timer_init(struct device_node *timer)
258266
timer_baseaddr = of_iomap(timer, 0);
259267
if (!timer_baseaddr) {
260268
pr_err("ERROR: invalid timer base address\n");
261-
BUG();
269+
return -ENXIO;
262270
}
263271

264272
write_fn = timer_write32;
@@ -271,11 +279,15 @@ static void __init xilinx_timer_init(struct device_node *timer)
271279
}
272280

273281
irq = irq_of_parse_and_map(timer, 0);
282+
if (irq <= 0) {
283+
pr_err("Failed to parse and map irq");
284+
return -EINVAL;
285+
}
274286

275287
of_property_read_u32(timer, "xlnx,one-timer-only", &timer_num);
276288
if (timer_num) {
277-
pr_emerg("Please enable two timers in HW\n");
278-
BUG();
289+
pr_err("Please enable two timers in HW\n");
290+
return -EINVAL;
279291
}
280292

281293
pr_info("%s: irq=%d\n", timer->full_name, irq);
@@ -297,15 +309,28 @@ static void __init xilinx_timer_init(struct device_node *timer)
297309

298310
freq_div_hz = timer_clock_freq / HZ;
299311

300-
setup_irq(irq, &timer_irqaction);
312+
ret = setup_irq(irq, &timer_irqaction);
313+
if (ret) {
314+
pr_err("Failed to setup IRQ");
315+
return ret;
316+
}
317+
301318
#ifdef CONFIG_HEART_BEAT
302319
microblaze_setup_heartbeat();
303320
#endif
304-
xilinx_clocksource_init();
305-
xilinx_clockevent_init();
321+
322+
ret = xilinx_clocksource_init();
323+
if (ret)
324+
return ret;
325+
326+
ret = xilinx_clockevent_init();
327+
if (ret)
328+
return ret;
306329

307330
sched_clock_register(xilinx_clock_read, 32, timer_clock_freq);
331+
332+
return 0;
308333
}
309334

310-
CLOCKSOURCE_OF_DECLARE(xilinx_timer, "xlnx,xps-timer-1.00.a",
335+
CLOCKSOURCE_OF_DECLARE_RET(xilinx_timer, "xlnx,xps-timer-1.00.a",
311336
xilinx_timer_init);

0 commit comments

Comments
 (0)