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,
	Stephen Warren <swarren@wwwdotorg.org>,
	Lee Jones <lee@kernel.org>, Eric Anholt <eric@anholt.net>,
	linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM
	BCM2835...),
	linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM
	BCM2835...)
Subject: [PATCH V2 13/63] clocksource/drivers/bcm2835_timer: Convert init function to return error
Date: Thu, 16 Jun 2016 23:26:32 +0200	[thread overview]
Message-ID: <1466112442-31105-14-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/bcm2835_timer.c | 40 +++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/drivers/clocksource/bcm2835_timer.c b/drivers/clocksource/bcm2835_timer.c
index 6f28229..2dcf896 100644
--- a/drivers/clocksource/bcm2835_timer.c
+++ b/drivers/clocksource/bcm2835_timer.c
@@ -80,19 +80,24 @@ static irqreturn_t bcm2835_time_interrupt(int irq, void *dev_id)
 	}
 }
 
-static void __init bcm2835_timer_init(struct device_node *node)
+static int __init bcm2835_timer_init(struct device_node *node)
 {
 	void __iomem *base;
 	u32 freq;
-	int irq;
+	int irq, ret;
 	struct bcm2835_timer *timer;
 
 	base = of_iomap(node, 0);
-	if (!base)
-		panic("Can't remap registers");
+	if (!base) {
+		pr_err("Can't remap registers");
+		return -ENXIO;
+	}
 
-	if (of_property_read_u32(node, "clock-frequency", &freq))
-		panic("Can't read clock-frequency");
+	ret = of_property_read_u32(node, "clock-frequency", &freq);
+	if (ret) {
+		pr_err("Can't read clock-frequency");
+		return ret;
+	}
 
 	system_clock = base + REG_COUNTER_LO;
 	sched_clock_register(bcm2835_sched_read, 32, freq);
@@ -101,12 +106,16 @@ static void __init bcm2835_timer_init(struct device_node *node)
 		freq, 300, 32, clocksource_mmio_readl_up);
 
 	irq = irq_of_parse_and_map(node, DEFAULT_TIMER);
-	if (irq <= 0)
-		panic("Can't parse IRQ");
+	if (irq <= 0) {
+		pr_err("Can't parse IRQ");
+		return -EINVAL;
+	}
 
 	timer = kzalloc(sizeof(*timer), GFP_KERNEL);
-	if (!timer)
-		panic("Can't allocate timer struct\n");
+	if (!timer) {
+		pr_err("Can't allocate timer struct\n");
+		return -ENOMEM;
+	}
 
 	timer->control = base + REG_CONTROL;
 	timer->compare = base + REG_COMPARE(DEFAULT_TIMER);
@@ -121,12 +130,17 @@ static void __init bcm2835_timer_init(struct device_node *node)
 	timer->act.dev_id = timer;
 	timer->act.handler = bcm2835_time_interrupt;
 
-	if (setup_irq(irq, &timer->act))
-		panic("Can't set up timer IRQ\n");
+	ret = setup_irq(irq, &timer->act);
+	if (ret) {
+		pr_err("Can't set up timer IRQ\n");
+		return ret;
+	}
 
 	clockevents_config_and_register(&timer->evt, freq, 0xf, 0xffffffff);
 
 	pr_info("bcm2835: system timer (irq = %d)\n", irq);
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(bcm2835, "brcm,bcm2835-system-timer",
+CLOCKSOURCE_OF_DECLARE_RET(bcm2835, "brcm,bcm2835-system-timer",
 			bcm2835_timer_init);
-- 
1.9.1

  parent reply	other threads:[~2016-06-16 21:28 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 ` Daniel Lezcano [this message]
2016-06-26  3:10   ` [PATCH V2 13/63] clocksource/drivers/bcm2835_timer: " 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 ` [PATCH V2 34/63] clocksource/drivers/time-efm32: " Daniel Lezcano
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-14-git-send-email-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=eric@anholt.net \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=swarren@wwwdotorg.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).