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


Groups > linux.kernel > #1432776

[PATCH 65/92] clocksource/drivers/microblaze: Convert init function to return error

From Daniel Lezcano <daniel.lezcano@linaro.org>
Newsgroups linux.kernel
Subject [PATCH 65/92] clocksource/drivers/microblaze: Convert init function to return error
Date 2016-06-28 12:40 +0200
Message-ID <rOYAX-5IE-85@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>
---
 arch/microblaze/kernel/timer.c | 51 +++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/arch/microblaze/kernel/timer.c b/arch/microblaze/kernel/timer.c
index 67e2ef4..7f35e7b 100644
--- a/arch/microblaze/kernel/timer.c
+++ b/arch/microblaze/kernel/timer.c
@@ -170,7 +170,7 @@ static struct irqaction timer_irqaction = {
 	.dev_id = &clockevent_xilinx_timer,
 };
 
-static __init void xilinx_clockevent_init(void)
+static __init int xilinx_clockevent_init(void)
 {
 	clockevent_xilinx_timer.mult =
 		div_sc(timer_clock_freq, NSEC_PER_SEC,
@@ -181,6 +181,8 @@ static __init void xilinx_clockevent_init(void)
 		clockevent_delta2ns(1, &clockevent_xilinx_timer);
 	clockevent_xilinx_timer.cpumask = cpumask_of(0);
 	clockevents_register_device(&clockevent_xilinx_timer);
+
+	return 0;
 }
 
 static u64 xilinx_clock_read(void)
@@ -229,8 +231,14 @@ static struct clocksource clocksource_microblaze = {
 
 static int __init xilinx_clocksource_init(void)
 {
-	if (clocksource_register_hz(&clocksource_microblaze, timer_clock_freq))
-		panic("failed to register clocksource");
+	int ret;
+
+	ret = clocksource_register_hz(&clocksource_microblaze,
+				      timer_clock_freq);
+	if (ret) {
+		pr_err("failed to register clocksource");
+		return ret;
+	}
 
 	/* stop timer1 */
 	write_fn(read_fn(timer_baseaddr + TCSR1) & ~TCSR_ENT,
@@ -239,16 +247,16 @@ static int __init xilinx_clocksource_init(void)
 	write_fn(TCSR_TINT|TCSR_ENT|TCSR_ARHT, timer_baseaddr + TCSR1);
 
 	/* register timecounter - for ftrace support */
-	init_xilinx_timecounter();
-	return 0;
+	return init_xilinx_timecounter();
 }
 
-static void __init xilinx_timer_init(struct device_node *timer)
+static int __init xilinx_timer_init(struct device_node *timer)
 {
 	struct clk *clk;
 	static int initialized;
 	u32 irq;
 	u32 timer_num = 1;
+	int ret;
 
 	if (initialized)
 		return;
@@ -258,7 +266,7 @@ static void __init xilinx_timer_init(struct device_node *timer)
 	timer_baseaddr = of_iomap(timer, 0);
 	if (!timer_baseaddr) {
 		pr_err("ERROR: invalid timer base address\n");
-		BUG();
+		return -ENXIO;
 	}
 
 	write_fn = timer_write32;
@@ -271,11 +279,15 @@ static void __init xilinx_timer_init(struct device_node *timer)
 	}
 
 	irq = irq_of_parse_and_map(timer, 0);
+	if (irq <= 0) {
+		pr_err("Failed to parse and map irq");
+		return -EINVAL;
+	}
 
 	of_property_read_u32(timer, "xlnx,one-timer-only", &timer_num);
 	if (timer_num) {
-		pr_emerg("Please enable two timers in HW\n");
-		BUG();
+		pr_err("Please enable two timers in HW\n");
+		return -EINVAL;
 	}
 
 	pr_info("%s: irq=%d\n", timer->full_name, irq);
@@ -297,15 +309,28 @@ static void __init xilinx_timer_init(struct device_node *timer)
 
 	freq_div_hz = timer_clock_freq / HZ;
 
-	setup_irq(irq, &timer_irqaction);
+	ret = setup_irq(irq, &timer_irqaction);
+	if (ret) {
+		pr_err("Failed to setup IRQ");
+		return ret;
+	}
+
 #ifdef CONFIG_HEART_BEAT
 	microblaze_setup_heartbeat();
 #endif
-	xilinx_clocksource_init();
-	xilinx_clockevent_init();
+
+	ret = xilinx_clocksource_init();
+	if (ret)
+		return ret;
+
+	ret = xilinx_clockevent_init();
+	if (ret)
+		return ret;
 
 	sched_clock_register(xilinx_clock_read, 32, timer_clock_freq);
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(xilinx_timer, "xlnx,xps-timer-1.00.a",
+CLOCKSOURCE_OF_DECLARE_RET(xilinx_timer, "xlnx,xps-timer-1.00.a",
 		       xilinx_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