Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1432793

[PATCH 52/92] clocksource/drivers/prima2: Convert init function to return error

From Daniel Lezcano <daniel.lezcano@linaro.org>
Newsgroups linux.kernel
Subject [PATCH 52/92] clocksource/drivers/prima2: Convert init function to return error
Date 2016-06-28 12:50 +0200
Message-ID <rOYKC-5Nk-27@gated-at.bofh.it> (permalink)
References <rOYAV-5IE-3@gated-at.bofh.it> <rOYAV-5IE-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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/timer-prima2.c | 43 ++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/drivers/clocksource/timer-prima2.c b/drivers/clocksource/timer-prima2.c
index 2854c66..7b1084d 100644
--- a/drivers/clocksource/timer-prima2.c
+++ b/drivers/clocksource/timer-prima2.c
@@ -189,24 +189,36 @@ static void __init sirfsoc_clockevent_init(void)
 }
 
 /* initialize the kernel jiffy timer source */
-static void __init sirfsoc_prima2_timer_init(struct device_node *np)
+static int __init sirfsoc_prima2_timer_init(struct device_node *np)
 {
 	unsigned long rate;
 	struct clk *clk;
+	int ret;
 
 	clk = of_clk_get(np, 0);
-	BUG_ON(IS_ERR(clk));
+	if (IS_ERR(clk)) {
+		pr_err("Failed to get clock");
+		return PTR_ERR(clk);
+	}
 
-	BUG_ON(clk_prepare_enable(clk));
+	ret = clk_prepare_enable(clk);
+	if (ret) {
+		pr_err("Failed to enable clock");
+		return ret;
+	}
 
 	rate = clk_get_rate(clk);
 
-	BUG_ON(rate < PRIMA2_CLOCK_FREQ);
-	BUG_ON(rate % PRIMA2_CLOCK_FREQ);
+	if (rate < PRIMA2_CLOCK_FREQ || rate % PRIMA2_CLOCK_FREQ) {
+		pr_err("Invalid clock rate");
+		return -EINVAL;
+	}
 
 	sirfsoc_timer_base = of_iomap(np, 0);
-	if (!sirfsoc_timer_base)
-		panic("unable to map timer cpu registers\n");
+	if (!sirfsoc_timer_base) {
+		pr_err("unable to map timer cpu registers\n");
+		return -ENXIO;
+	}
 
 	sirfsoc_timer_irq.irq = irq_of_parse_and_map(np, 0);
 
@@ -216,14 +228,23 @@ static void __init sirfsoc_prima2_timer_init(struct device_node *np)
 	writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_COUNTER_HI);
 	writel_relaxed(BIT(0), sirfsoc_timer_base + SIRFSOC_TIMER_STATUS);
 
-	BUG_ON(clocksource_register_hz(&sirfsoc_clocksource,
-				       PRIMA2_CLOCK_FREQ));
+	ret = clocksource_register_hz(&sirfsoc_clocksource, PRIMA2_CLOCK_FREQ);
+	if (ret) {
+		pr_err("Failed to register clocksource");
+		return ret;
+	}
 
 	sched_clock_register(sirfsoc_read_sched_clock, 64, PRIMA2_CLOCK_FREQ);
 
-	BUG_ON(setup_irq(sirfsoc_timer_irq.irq, &sirfsoc_timer_irq));
+	ret = setup_irq(sirfsoc_timer_irq.irq, &sirfsoc_timer_irq);
+	if (ret) {
+		pr_err("Failed to setup irq");
+		return ret;
+	}
 
 	sirfsoc_clockevent_init();
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(sirfsoc_prima2_timer,
+CLOCKSOURCE_OF_DECLARE_RET(sirfsoc_prima2_timer,
 	"sirf,prima2-tick", sirfsoc_prima2_timer_init);
-- 
1.9.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 01/92] clocksource/drivers/armada-370-xp: Make syscore_ops static Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
  [PATCH 63/92] clocksource/drivers/vt8500: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
  [PATCH 15/92] clocksource/drivers/exynos_mct: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
  [PATCH 74/92] clocksource/drivers/bcm_kona: Remove useless header <asm/mach/time.h> Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
    Re: [PATCH 74/92] clocksource/drivers/bcm_kona: Remove useless header  <asm/mach/time.h> Ray Jui <ray.jui@broadcom.com> - 2016-06-29 08:00 +0200
  [PATCH 14/92] clocksource/drivers/mtk_timer: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
  [PATCH 65/92] clocksource/drivers/microblaze: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
  [PATCH 66/92] clocksource/drivers/ralink: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
  [PATCH 58/92] clocksource/drivers/sun5i: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
  [PATCH 04/92] clocksource/drivers/samsung_pwm: Fix typo in Kconfig Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
  [PATCH 71/92] clocksource/drivers/oxnas-rps: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:40 +0200
  [PATCH 42/92] clocksource/drivers/tango_xtal: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 30/92] clocksource/drivers/h8300_timer8: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 43/92] clocksource/drivers/tegra20: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 41/92] clocksource/drivers/sun4i: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 47/92] clocksource/drivers/orion: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 52/92] clocksource/drivers/prima2: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 23/92] clocksource/drivers/bcm2835_timer: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 26/92] clocksource/drivers/fsl_ftm_timer: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 37/92] clocksource/drivers/nomadik-mtu: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 49/92] clocksource/drivers/atlas7: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 40/92] clocksource/drivers/samsung_pwm: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 46/92] clocksource/drivers/time-lpc32xx: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 45/92] clocksource/drivers/time-efm32: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 20/92] clocksource/drivers/clps711x: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 44/92] clocksource/drivers/time-armada-370-xp: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 25/92] clocksource/drivers/clksrc-dbx500: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 54/92] clocksource/drivers/integrator-ap: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 48/92] clocksource/drivers/pistachio: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 12:50 +0200
  [PATCH 38/92] clocksource/drivers/pxa: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 32/92] clocksource/drivers/meson6_timer.c: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 29/92] clocksource/drivers/h8300_timer16: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 13/92] clocksource/drivers/rockchip_timer: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 24/92] clocksource/drivers/bcm_kona: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 34/92] clocksource/drivers/moxart: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 27/92] clocksource/drivers/arm_arch_timer: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 17/92] clocksource/drivers/cadence_ttc: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 35/92] clocksource/drivers/mps2-timer: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 31/92] clocksource/drivers/h8300_tpu: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 28/92] clocksource/drivers/arm_global_timer: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 39/92] clocksource/drivers/qcom: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 22/92] clocksource/drivers/armv7m_systick: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 36/92] clocksource/drivers/mxs: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 33/92] clocksource/drivers/mips-gic-timer: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:00 +0200
  [PATCH 06/92] clocksource/drivers/rockchip: Add the dynamic irq flag to the timer Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:10 +0200
  [PATCH 08/92] arm64: dts: rockchip: Add rktimer device node for rk3399 Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:10 +0200
  [PATCH 18/92] clocksource/drivers/st_lpc: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:10 +0200
  [PATCH 07/92] clocksource/drivers/rockchip: Add support for the rk3399 SoC Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:10 +0200
  [PATCH 12/92] clocksource/drivers/clksrc-probe: Introduce init functions with return code Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:10 +0200
  [PATCH 02/92] clocksource/drivers/digicolor: Fix warning of non-static function Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:10 +0200
  [PATCH 10/92] dt-bindings: clocksource: Add Oxford Semiconductor RPS Timer bindings Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:10 +0200
  [PATCH 09/92] clocksource/drivers/oxnas-rps: Add Oxford Semiconductor RPS Dual Timer Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:10 +0200
  [PATCH 19/92] clocksource/drivers/dw_apb_timer: Convert init function to return error Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-06-28 13:10 +0200

csiph-web