clocksource/drivers/asm9260: Convert init function to return error
authorDaniel Lezcano <daniel.lezcano@linaro.org>
Tue, 31 May 2016 17:38:30 +0000 (19:38 +0200)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Tue, 28 Jun 2016 08:19:18 +0000 (10:19 +0200)
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>
drivers/clocksource/asm9260_timer.c

index 217438d..d113c02 100644 (file)
@@ -184,7 +184,7 @@ static irqreturn_t asm9260_timer_interrupt(int irq, void *dev_id)
  * Timer initialization
  * ---------------------------------------------------------------------------
  */
-static void __init asm9260_timer_init(struct device_node *np)
+static int __init asm9260_timer_init(struct device_node *np)
 {
        int irq;
        struct clk *clk;
@@ -192,20 +192,26 @@ static void __init asm9260_timer_init(struct device_node *np)
        unsigned long rate;
 
        priv.base = of_io_request_and_map(np, 0, np->name);
-       if (IS_ERR(priv.base))
-               panic("%s: unable to map resource", np->name);
+       if (IS_ERR(priv.base)) {
+               pr_err("%s: unable to map resource", np->name);
+               return PTR_ERR(priv.base);
+       }
 
        clk = of_clk_get(np, 0);
 
        ret = clk_prepare_enable(clk);
-       if (ret)
-               panic("Failed to enable clk!\n");
+       if (ret) {
+               pr_err("Failed to enable clk!\n");
+               return ret;
+       }
 
        irq = irq_of_parse_and_map(np, 0);
        ret = request_irq(irq, asm9260_timer_interrupt, IRQF_TIMER,
                        DRIVER_NAME, &event_dev);
-       if (ret)
-               panic("Failed to setup irq!\n");
+       if (ret) {
+               pr_err("Failed to setup irq!\n");
+               return ret;
+       }
 
        /* set all timers for count-up */
        writel_relaxed(BM_DIR_DEFAULT, priv.base + HW_DIR);
@@ -229,6 +235,8 @@ static void __init asm9260_timer_init(struct device_node *np)
        priv.ticks_per_jiffy = DIV_ROUND_CLOSEST(rate, HZ);
        event_dev.cpumask = cpumask_of(0);
        clockevents_config_and_register(&event_dev, rate, 0x2c00, 0xfffffffe);
+
+       return 0;
 }
-CLOCKSOURCE_OF_DECLARE(asm9260_timer, "alphascale,asm9260-timer",
+CLOCKSOURCE_OF_DECLARE_RET(asm9260_timer, "alphascale,asm9260-timer",
                asm9260_timer_init);