linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: daniel.lezcano@linaro.org (Daniel Lezcano)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 23/92] clocksource/drivers/bcm2835_timer: Convert init function to return error
Date: Tue, 28 Jun 2016 12:30:42 +0200	[thread overview]
Message-ID: <1467109911-11060-23-git-send-email-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <1467109911-11060-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>
Acked-by: Eric Anholt <eric@anholt.net>
---
 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-28 10:30 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <577251A4.7030508@linaro.org>
     [not found] ` <1467109911-11060-1-git-send-email-daniel.lezcano@linaro.org>
2016-06-28 10:30   ` [PATCH 02/92] clocksource/drivers/digicolor: Fix warning of non-static function Daniel Lezcano
2016-06-28 10:30   ` [PATCH 05/92] dt-bindings: Document rk3399 rk-timer bindings Daniel Lezcano
2016-06-28 10:30   ` [PATCH 06/92] clocksource/drivers/rockchip: Add the dynamic irq flag to the timer Daniel Lezcano
2016-06-28 10:30   ` [PATCH 07/92] clocksource/drivers/rockchip: Add support for the rk3399 SoC Daniel Lezcano
2016-06-28 10:30   ` [PATCH 08/92] arm64: dts: rockchip: Add rktimer device node for rk3399 Daniel Lezcano
2016-06-28 10:30   ` [PATCH 09/92] clocksource/drivers/oxnas-rps: Add Oxford Semiconductor RPS Dual Timer Daniel Lezcano
2016-06-28 10:30   ` [PATCH 13/92] clocksource/drivers/rockchip_timer: Convert init function to return error Daniel Lezcano
2016-06-28 10:30   ` [PATCH 14/92] clocksource/drivers/mtk_timer: " Daniel Lezcano
2016-06-28 10:30   ` [PATCH 15/92] clocksource/drivers/exynos_mct: " Daniel Lezcano
2016-06-28 10:30   ` [PATCH 17/92] clocksource/drivers/cadence_ttc: " Daniel Lezcano
2016-06-28 10:30   ` [PATCH 18/92] clocksource/drivers/st_lpc: " Daniel Lezcano
2016-06-28 10:30   ` [PATCH 20/92] clocksource/drivers/clps711x: " Daniel Lezcano
2016-06-28 10:30   ` [PATCH 21/92] clocksource/drivers/digicolor: " Daniel Lezcano
2016-06-28 10:30   ` [PATCH 22/92] clocksource/drivers/armv7m_systick: " Daniel Lezcano
2016-06-28 10:30   ` Daniel Lezcano [this message]
2016-06-28 10:30   ` [PATCH 25/92] clocksource/drivers/clksrc-dbx500: " Daniel Lezcano
2016-06-28 10:30   ` [PATCH 28/92] clocksource/drivers/arm_global_timer: " Daniel Lezcano
2016-06-28 10:30   ` [PATCH 32/92] clocksource/drivers/meson6_timer.c: " Daniel Lezcano
2016-06-28 10:30   ` [PATCH 35/92] clocksource/drivers/mps2-timer: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 41/92] clocksource/drivers/sun4i: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 45/92] clocksource/drivers/time-efm32: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 46/92] clocksource/drivers/time-lpc32xx: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 49/92] clocksource/drivers/atlas7: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 52/92] clocksource/drivers/prima2: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 55/92] clocksource/drivers/keystone: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 57/92] clocksource/drivers/stm32: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 58/92] clocksource/drivers/sun5i: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 60/92] clocksource/drivers/u300: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 61/92] clocksource/drivers/versatile: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 63/92] clocksource/drivers/vt8500: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 68/92] clocksource/drivers/smp_twd: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 71/92] clocksource/drivers/oxnas-rps: " Daniel Lezcano
2016-06-28 10:31   ` [PATCH 72/92] clocksources: Switch back to the clksrc table Daniel Lezcano
2016-06-28 10:31   ` [PATCH 75/92] clocksource/drivers/bcm2835: Add the COMPILE_TEST option Daniel Lezcano
2016-06-28 10:51 ` [PATCH 76/92] clocksource/drivers/armv7m_systick: " Daniel Lezcano
2016-06-28 10:51   ` [PATCH 77/92] clocksource/drivers/bcm_kona: " Daniel Lezcano
2016-06-28 10:51   ` [PATCH 78/92] clocksource/drivers/clps_711x: " Daniel Lezcano
2016-06-28 10:51   ` [PATCH 79/92] clocksource/drivers/atlas7: " Daniel Lezcano
2016-06-28 10:51   ` [PATCH 80/92] clocksource/drivers/moxart: " Daniel Lezcano
2016-06-28 10:51   ` [PATCH 82/92] clocksource/drivers/mxs: " Daniel Lezcano
2016-06-28 10:51   ` [PATCH 83/92] clocksource/drivers/prima2: Remove useless header <asm/mach/time.h> Daniel Lezcano
2016-06-28 10:51   ` [PATCH 84/92] clocksource/drivers/prima2: Add the COMPILE_TEST option Daniel Lezcano
2016-06-28 10:51   ` [PATCH 85/92] clocksource/drivers/u300: " Daniel Lezcano
2016-06-28 10:51   ` [PATCH 86/92] clocksource/drivers/nspire: " Daniel Lezcano
2016-06-28 10:51   ` [PATCH 87/92] clocksource/drivers/keystone: " Daniel Lezcano
2016-06-28 10:51   ` [PATCH 88/92] clocksource/drivers/integrator-ap: " Daniel Lezcano

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=1467109911-11060-23-git-send-email-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).