linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: daniel.lezcano@linaro.org, tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH V2 34/63] clocksource/drivers/time-efm32: Convert init function to return error
Date: Thu, 16 Jun 2016 23:26:53 +0200	[thread overview]
Message-ID: <1466112442-31105-35-git-send-email-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <1466112442-31105-1-git-send-email-daniel.lezcano@linaro.org>

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/time-armada-370-xp.c | 102 +++++++++++++++++++++++--------
 1 file changed, 76 insertions(+), 26 deletions(-)

diff --git a/drivers/clocksource/time-armada-370-xp.c b/drivers/clocksource/time-armada-370-xp.c
index 601dbf74..bc4ab48 100644
--- a/drivers/clocksource/time-armada-370-xp.c
+++ b/drivers/clocksource/time-armada-370-xp.c
@@ -260,14 +260,22 @@ static struct delay_timer armada_370_delay_timer = {
 	.read_current_timer = armada_370_delay_timer_read,
 };
 
-static void __init armada_370_xp_timer_common_init(struct device_node *np)
+static int __init armada_370_xp_timer_common_init(struct device_node *np)
 {
 	u32 clr = 0, set = 0;
 	int res;
 
 	timer_base = of_iomap(np, 0);
-	WARN_ON(!timer_base);
+	if (!timer_base) {
+		pr_err("Failed to iomap");
+		return -ENXIO;
+	}
+
 	local_base = of_iomap(np, 1);
+	if (!local_base) {
+		pr_err("Failed to iomap");
+		return -ENXIO;
+	}
 
 	if (timer25Mhz) {
 		set = TIMER0_25MHZ;		
@@ -306,14 +314,19 @@ static void __init armada_370_xp_timer_common_init(struct device_node *np)
 	 */
 	sched_clock_register(armada_370_xp_read_sched_clock, 32, timer_clk);
 
-	clocksource_mmio_init(timer_base + TIMER0_VAL_OFF,
-			      "armada_370_xp_clocksource",
-			      timer_clk, 300, 32, clocksource_mmio_readl_down);
+	res = clocksource_mmio_init(timer_base + TIMER0_VAL_OFF,
+				    "armada_370_xp_clocksource",
+				    timer_clk, 300, 32, clocksource_mmio_readl_down);
+	if (res) {
+		pr_err("Failed to initialize clocksource mmio");
+		return res;
+	}
 
 	register_cpu_notifier(&armada_370_xp_timer_cpu_nb);
 
 	armada_370_xp_evt = alloc_percpu(struct clock_event_device);
-
+	if (!armada_370_xp_evt)
+		return -ENOMEM;
 
 	/*
 	 * Setup clockevent timer (interrupt-driven).
@@ -323,33 +336,54 @@ static void __init armada_370_xp_timer_common_init(struct device_node *np)
 				"armada_370_xp_per_cpu_tick",
 				armada_370_xp_evt);
 	/* Immediately configure the timer on the boot CPU */
-	if (!res)
-		armada_370_xp_timer_setup(this_cpu_ptr(armada_370_xp_evt));
+	if (res) {
+		pr_err("Failed to request percpu irq");
+		return res;
+	}
+
+	res = armada_370_xp_timer_setup(this_cpu_ptr(armada_370_xp_evt));
+	if (!res) {
+		pr_err("Failed to setup timer");
+		return res;
+	}
 
 	register_syscore_ops(&armada_370_xp_timer_syscore_ops);
+	
+	return 0;
 }
 
-static void __init armada_xp_timer_init(struct device_node *np)
+static int __init armada_xp_timer_init(struct device_node *np)
 {
 	struct clk *clk = of_clk_get_by_name(np, "fixed");
+	int ret;
+
+	clk = of_clk_get(np, 0);
+	if (IS_ERR(clk)) {
+		pr_err("Failed to get clock");
+		return PTR_ERR(clk);
+	}
+
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		return ret;
 
-	/* The 25Mhz fixed clock is mandatory, and must always be available */
-	BUG_ON(IS_ERR(clk));
-	clk_prepare_enable(clk);
 	timer_clk = clk_get_rate(clk);
 
-	armada_370_xp_timer_common_init(np);
+	return armada_370_xp_timer_common_init(np);
 }
-CLOCKSOURCE_OF_DECLARE(armada_xp, "marvell,armada-xp-timer",
+CLOCKSOURCE_OF_DECLARE_RET(armada_xp, "marvell,armada-xp-timer",
 		       armada_xp_timer_init);
 
-static void __init armada_375_timer_init(struct device_node *np)
+static int __init armada_375_timer_init(struct device_node *np)
 {
 	struct clk *clk;
+	int ret;
 
 	clk = of_clk_get_by_name(np, "fixed");
 	if (!IS_ERR(clk)) {
-		clk_prepare_enable(clk);
+		ret = clk_prepare_enable(clk);
+		if (ret)
+			return ret;
 		timer_clk = clk_get_rate(clk);
 	} else {
 
@@ -360,27 +394,43 @@ static void __init armada_375_timer_init(struct device_node *np)
 		clk = of_clk_get(np, 0);
 
 		/* Must have at least a clock */
-		BUG_ON(IS_ERR(clk));
-		clk_prepare_enable(clk);
+		if (IS_ERR(clk)) {
+			pr_err("Failed to get clock");
+			return PTR_ERR(clk);
+		}
+
+		ret = clk_prepare_enable(clk);
+		if (ret)
+			return ret;
+
 		timer_clk = clk_get_rate(clk) / TIMER_DIVIDER;
 		timer25Mhz = false;
 	}
 
-	armada_370_xp_timer_common_init(np);
+	return armada_370_xp_timer_common_init(np);
 }
-CLOCKSOURCE_OF_DECLARE(armada_375, "marvell,armada-375-timer",
+CLOCKSOURCE_OF_DECLARE_RET(armada_375, "marvell,armada-375-timer",
 		       armada_375_timer_init);
 
-static void __init armada_370_timer_init(struct device_node *np)
+static int __init armada_370_timer_init(struct device_node *np)
 {
-	struct clk *clk = of_clk_get(np, 0);
+	struct clk *clk;
+	int ret;
+
+	clk = of_clk_get(np, 0);
+	if (IS_ERR(clk)) {
+		pr_err("Failed to get clock");
+		return PTR_ERR(clk);
+	}
+
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		return ret;
 
-	BUG_ON(IS_ERR(clk));
-	clk_prepare_enable(clk);
 	timer_clk = clk_get_rate(clk) / TIMER_DIVIDER;
 	timer25Mhz = false;
 
-	armada_370_xp_timer_common_init(np);
+	return armada_370_xp_timer_common_init(np);
 }
-CLOCKSOURCE_OF_DECLARE(armada_370, "marvell,armada-370-timer",
+CLOCKSOURCE_OF_DECLARE_RET(armada_370, "marvell,armada-370-timer",
 		       armada_370_timer_init);
-- 
1.9.1

  parent reply	other threads:[~2016-06-16 21:37 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 01/63] of: Add a new macro to declare_of for one parameter function returning a value Daniel Lezcano
2016-06-20 21:03   ` Rob Herring
2016-06-16 21:26 ` [PATCH V2 02/63] clocksource/drivers/clksrc-probe: Introduce init functions with return code Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 03/63] clocksource/drivers/rockchip_timer: Convert init function to return error Daniel Lezcano
2016-06-18 10:38   ` Heiko Stübner
2016-06-18 12:54     ` [PATCH V3] " Daniel Lezcano
2016-06-18 13:47       ` Heiko Stübner
2016-06-16 21:26 ` [PATCH V2 04/63] clocksource/drivers/mkt_timer: " Daniel Lezcano
2016-06-17 16:16   ` Matthias Brugger
2016-06-16 21:26 ` [PATCH V2 05/63] clocksource/drivers/exynos_mct: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 06/63] clocksource/drivers/asm9260: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 07/63] clocksource/drivers/cadence_ttc: " Daniel Lezcano
2016-06-16 21:43   ` Sören Brinkmann
2016-06-16 21:26 ` [PATCH V2 08/63] clocksource/drivers/st_lpc: " Daniel Lezcano
2016-06-20  7:39   ` Patrice Chotard
2016-06-20 11:33   ` Maxime Coquelin
2016-06-16 21:26 ` [PATCH V2 09/63] clocksource/drivers/dw_apb_timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 10/63] clocksource/drivers/clps711x: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 11/63] clocksource/drivers/digitcolor: " Daniel Lezcano
2016-06-17  3:15   ` Baruch Siach
2016-06-16 21:26 ` [PATCH V2 12/63] clocksource/drivers/armv7m_systick: " Daniel Lezcano
2016-06-20 11:31   ` Maxime Coquelin
2016-06-16 21:26 ` [PATCH V2 13/63] clocksource/drivers/bcm2835_timer: " Daniel Lezcano
2016-06-26  3:10   ` Eric Anholt
2016-06-16 21:26 ` [PATCH V2 14/63] clocksource/drivers/bcm_kona: " Daniel Lezcano
2016-06-20 17:22   ` Ray Jui
2016-06-20 17:40     ` Daniel Lezcano
2016-06-20 17:48     ` [PATCH V3] " Daniel Lezcano
2016-06-20 17:50       ` Ray Jui
2016-06-20 20:12         ` Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 15/63] clocksource/drivers/clksrc-dbx500: " Daniel Lezcano
2016-06-17 16:10   ` Linus Walleij
2016-06-16 21:26 ` [PATCH V2 16/63] clocksource/drivers/fsl_ftm_timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 17/63] clocksource/drivers/arm_arch_timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 18/63] clocksource/drivers/arm_global_timer: " Daniel Lezcano
2016-06-20 11:32   ` Maxime Coquelin
2016-06-16 21:26 ` [PATCH V2 19/63] clocksource/drivers/h8300_timer16: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 20/63] clocksource/drivers/h8300_tpu: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 21/63] " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 22/63] clocksource/drivers/mips-gic-timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 23/63] clocksource/drivers/moxart_timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 24/63] clocksource/drivers/mps2-timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 25/63] clocksource/drivers/mxs_timer: " Daniel Lezcano
2016-06-17  6:33   ` Uwe Kleine-König
2016-06-17 10:43     ` [PATCH V3] clocksource/drivers/mxs: " Daniel Lezcano
2016-06-20  9:15   ` [PATCH V2 25/63] clocksource/drivers/mxs_timer: " Liviu Dudau
2016-06-20  9:24     ` Daniel Lezcano
2016-06-20  9:26     ` [PATCH V3] clocksource/drivers/mps2-timer: " Daniel Lezcano
2016-06-20  9:42       ` liviu.dudau
2016-06-16 21:26 ` [PATCH V2 26/63] clocksource/drivers/nomadik-mtu: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 27/63] clocksource/drivers/pxa_timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 28/63] clocksource/drivers/qcom-timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 29/63] clocksource/drivers/samsung_pwm_timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 30/63] clocksource/drivers/sun4i_time: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 31/63] clocksource/drivers/tango_xtal: " Daniel Lezcano
2016-06-17  9:19   ` Mason
2016-06-17 10:26     ` [PATCH V3] " Daniel Lezcano
2016-06-17 12:35       ` Marc Gonzalez
2016-06-17 12:43         ` Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 32/63] clocksource/drivers/tegra20_timer: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 33/63] clocksource/drivers/time-armada-370-xp: " Daniel Lezcano
2016-06-17  7:21   ` Jon Hunter
2016-06-17  8:09     ` Daniel Lezcano
2016-06-17  9:06     ` [PATCH V3] clocksource/drivers/tegra20: " Daniel Lezcano
2016-06-16 21:26 ` Daniel Lezcano [this message]
2016-06-16 21:26 ` [PATCH V2 35/63] clocksource/drivers/time-lpc32xx: " Daniel Lezcano
2016-06-17  6:52   ` Uwe Kleine-König
2016-06-17  8:44     ` [PATCH V3] clocksource/drivers/time-efm32: " Daniel Lezcano
2016-06-17  9:46       ` Uwe Kleine-König
2016-06-16 21:26 ` [PATCH V2 36/63] clocksource/drivers/time-orion: " Daniel Lezcano
2016-06-20 17:08   ` Sylvain Lemieux
2016-06-16 21:26 ` [PATCH V2 37/63] clocksource/drivers/time-pistachio: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 38/63] " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 39/63] clocksource/drivers/timer-atlas7: " Daniel Lezcano
2016-06-16 21:26 ` [PATCH V2 40/63] clocksource/drivers/timer-atmel-pit: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 41/63] clocksource/drivers/timer-atmel-st: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 42/63] clocksource/drivers/prima2: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 43/63] clocksource/drivers/timer-imx-gpt: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 44/63] clocksource/drivers/timer-integrator-ap: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 45/63] clocksource/drivers/timer-keystone: " Daniel Lezcano
2016-06-17 16:03   ` Santosh Shilimkar
2016-06-16 21:27 ` [PATCH V2 46/63] clocksource/drivers/timer-sp804: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 47/63] clocksource/drivers/timer-stm32: " Daniel Lezcano
2016-06-20 11:32   ` Maxime Coquelin
2016-06-16 21:27 ` [PATCH V2 48/63] clocksource/drivers/timer-sun5i: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 49/63] clocksource/drivers/timer-ti-32k: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 50/63] clocksource/drivers/timer-u300: " Daniel Lezcano
2016-06-17 16:11   ` Linus Walleij
2016-06-16 21:27 ` [PATCH V2 51/63] clocksource/drivers/versatile: " Daniel Lezcano
2016-06-20  9:13   ` Liviu Dudau
2016-06-16 21:27 ` [PATCH V2 52/63] clocksource/drivers/vf_pit_timer: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 53/63] clocksource/drivers/vt8500_timer: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 54/63] clocksource/drivers/zevio-timer: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 55/63] clocksource/drivers/timer-sp804: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 56/63] clocksource/drivers/microblaze: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 57/63] clocksource/drivers/ralink: " Daniel Lezcano
2016-06-17  8:54   ` John Crispin
2016-06-16 21:27 ` [PATCH V2 58/63] clocksource/drivers/nios2: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 59/63] clocksource/drivers/smp_twd: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 60/63] clocksource/drivers/nps: " Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 61/63] clocksource/drivers/arc: " Daniel Lezcano
2016-06-17  8:59   ` Vineet Gupta
2016-06-17 10:09     ` [PATCH V3] " Daniel Lezcano
2016-06-17 14:30       ` Vineet Gupta
2016-06-24  4:06       ` Vineet Gupta
2016-06-24  6:41         ` Daniel Lezcano
2016-06-24  7:52           ` Vineet Gupta
2016-06-24  7:55             ` Daniel Lezcano
2016-06-16 21:27 ` [PATCH V2 62/63] clocksource/drivers/oxnas-rps: " Daniel Lezcano
2016-06-17  6:58   ` Neil Armstrong
     [not found] ` <1466112442-31105-64-git-send-email-daniel.lezcano@linaro.org>
2016-06-17 14:33   ` [PATCH V2 63/63] clocksources: Switch back to the clksrc table Vineet Gupta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1466112442-31105-35-git-send-email-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).