drivers:clocksource:Modify timer driver and add exit codes
authorxingyu.wu <xingyu.wu@starfivetech.com>
Thu, 23 Jun 2022 01:48:12 +0000 (09:48 +0800)
committerxingyu.wu <xingyu.wu@starfivetech.com>
Thu, 30 Jun 2022 14:24:24 +0000 (22:24 +0800)
Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com>
drivers/clocksource/timer-starfive.c
drivers/clocksource/timer-starfive.h

index dbfa284..33f257b 100755 (executable)
@@ -368,7 +368,7 @@ static int __init do_starfive_timer_of_init(struct device_node *np,
        count = of_irq_count(np);
        if (count > NR_TIMERS || count <= 0) {
                ret = -EINVAL;
-               goto err;
+               goto count_err;
        }
 
        for (index = 0; index < count; index++) {
@@ -387,27 +387,45 @@ static int __init do_starfive_timer_of_init(struct device_node *np,
                        if (clk_prepare_enable(clk))
                                pr_warn("clk for %pOFn is present,"
                                        "but could not be activated\n", np);
-
                }
 
                irq = irq_of_parse_and_map(np, index);
                if (irq < 0) {
                        ret = -EINVAL;
-                       goto err;
+                       goto irq_err;
                }
 
                ret = starfive_clockevents_register(clkevt, irq, np, name);
                if (ret) {
                        pr_err("%s: init clockevents failed.\n", name);
-                       goto err;
+                       goto irq_err;
                }
+               clkevt->irq = irq;
 
                ret = starfive_clocksource_init(clkevt, name, np);
                if (ret)
-                       goto err;
+                       goto irq_err;
        }
+       if (!IS_ERR(pclk))
+               clk_put(pclk);
 
        return 0;
+
+irq_err:
+       for (; index > -1; index--) {
+               clkevt = &starfive_jh7100_clkevt[index];
+               if (!clkevt->irq)
+                       free_irq(clkevt->irq, &clkevt->evt);
+               if (!clkevt->clk) {
+                       clk_disable_unprepare(clkevt->clk);
+                       clk_put(clkevt->clk);
+               }
+       }
+count_err:
+       if (!IS_ERR(pclk)) {
+               clk_disable_unprepare(pclk);
+               clk_put(pclk);
+       }
 err:
        iounmap(base);
        return ret;
index a54aadd..3d702e4 100644 (file)
@@ -84,6 +84,7 @@ struct starfive_timer {
 struct starfive_clkevt {
        struct clock_event_device evt;
        struct clk *clk;
+       int irq;
        u64 periodic;
        u64 rate;
        u32 reload_val;