linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling
@ 2016-06-16 21:26 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
                   ` (62 more replies)
  0 siblings, 63 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

First of all, I apologize for the size of this series. The changes are always
going on the same direction and apply for the same init function in the
different drivers.

The macro CLOCKSOURCE_OF_DECLARE is widely used in the timer drivers.

Basically, this macro is defined to insert in a table a tuple name,function.
This function is an init function called when the name matches the DT node and
its signature is:

        typedef void (*of_init_fn_1)(struct device_node *);

It does not return an error code.

That results in the clocksource-probe not being able to figure out if the driver
was correctly initialized or not, the different drivers to act as they were the
only ones on the system (panic, instead of failing gracefully), and duplicated
code for error reporting.

This series initiates the logic change and centralize the error handling in the
clocksource probe code.

In order to do the changes little by little, a new macro was introduced:

 CLOCKSOURCE_OF_DECLARE_RET()

It expects an init function signature:

        typedef int (*of_init_ret_fn_1)(struct device_node *);

When all drivers have their init functions signature changed to return a value,
CLOCKSOURCE_OF_DECLARE_RET changes its name back to CLOCKSOURCE_OF_DECLARE, so
the entire patchset is git-bisect safe.

Changelog:

  V2:
    - Added Reviewed-by tags
    - Added all the clocksource drivers changes, so the series
      contains the entire conversion of the init function returning
      an error code
    - Some fixes reported by the automated compilation bots
  V1:
    - initial post

Daniel Lezcano (63):
  of: Add a new macro to declare_of for one parameter function returning
    a value
  clocksource/drivers/clksrc-probe: Introduce init functions with return
    code
  clocksource/drivers/rockchip_timer: Convert init function to return
    error
  clocksource/drivers/mkt_timer: Convert init function to return error
  clocksource/drivers/exynos_mct: Convert init function to return error
  clocksource/drivers/asm9260: Convert init function to return error
  clocksource/drivers/cadence_ttc: Convert init function to return error
  clocksource/drivers/st_lpc: Convert init function to return error
  clocksource/drivers/dw_apb_timer: Convert init function to return
    error
  clocksource/drivers/clps711x: Convert init function to return error
  clocksource/drivers/digitcolor: Convert init function to return error
  clocksource/drivers/armv7m_systick: Convert init function to return
    error
  clocksource/drivers/bcm2835_timer: Convert init function to return
    error
  clocksource/drivers/bcm_kona: Convert init function to return error
  clocksource/drivers/clksrc-dbx500: Convert init function to return
    error
  clocksource/drivers/fsl_ftm_timer: Convert init function to return
    error
  clocksource/drivers/arm_arch_timer: Convert init function to return
    error
  clocksource/drivers/arm_global_timer: Convert init function to return
    error
  clocksource/drivers/h8300_timer16: Convert init function to return
    error
  clocksource/drivers/h8300_tpu: Convert init function to return error
  clocksource/drivers/h8300_tpu: Convert init function to return error
  clocksource/drivers/mips-gic-timer: Convert init function to return
    error
  clocksource/drivers/moxart_timer: Convert init function to return
    error
  clocksource/drivers/mps2-timer: Convert init function to return error
  clocksource/drivers/mxs_timer: Convert init function to return error
  clocksource/drivers/nomadik-mtu: Convert init function to return error
  clocksource/drivers/pxa_timer: Convert init function to return error
  clocksource/drivers/qcom-timer: Convert init function to return error
  clocksource/drivers/samsung_pwm_timer: Convert init function to return
    error
  clocksource/drivers/sun4i_time: Convert init function to return error
  clocksource/drivers/tango_xtal: Convert init function to return error
  clocksource/drivers/tegra20_timer: Convert init function to return
    error
  clocksource/drivers/time-armada-370-xp: Convert init function to
    return error
  clocksource/drivers/time-efm32: Convert init function to return error
  clocksource/drivers/time-lpc32xx: Convert init function to return
    error
  clocksource/drivers/time-orion: Convert init function to return error
  clocksource/drivers/time-pistachio: Convert init function to return
    error
  clocksource/drivers/time-pistachio: Convert init function to return
    error
  clocksource/drivers/timer-atlas7: Convert init function to return
    error
  clocksource/drivers/timer-atmel-pit: Convert init function to return
    error
  clocksource/drivers/timer-atmel-st: Convert init function to return
    error
  clocksource/drivers/prima2: Convert init function to return error
  clocksource/drivers/timer-imx-gpt: Convert init function to return
    error
  clocksource/drivers/timer-integrator-ap: Convert init function to
    return error
  clocksource/drivers/timer-keystone: Convert init function to return
    error
  clocksource/drivers/timer-sp804: Convert init function to return error
  clocksource/drivers/timer-stm32: Convert init function to return error
  clocksource/drivers/timer-sun5i: Convert init function to return error
  clocksource/drivers/timer-ti-32k: Convert init function to return
    error
  clocksource/drivers/timer-u300: Convert init function to return error
  clocksource/drivers/versatile: Convert init function to return error
  clocksource/drivers/vf_pit_timer: Convert init function to return
    error
  clocksource/drivers/vt8500_timer: Convert init function to return
    error
  clocksource/drivers/zevio-timer: Convert init function to return error
  clocksource/drivers/timer-sp804: Convert init function to return error
  clocksource/drivers/microblaze: Convert init function to return error
  clocksource/drivers/ralink: Convert init function to return error
  clocksource/drivers/nios2: Convert init function to return error
  clocksource/drivers/smp_twd: Convert init function to return error
  clocksource/drivers/nps: Convert init function to return error
  clocksource/drivers/arc: Convert init function to return error
  clocksource/drivers/oxnas-rps: Convert init function to return error
  clocksources: Switch back to the clksrc table

 arch/arc/kernel/time.c                    | 63 ++++++++++++--------
 arch/arm/kernel/smp_twd.c                 |  3 +-
 arch/microblaze/kernel/timer.c            | 49 ++++++++++++----
 arch/mips/ralink/cevt-rt3352.c            | 17 ++++--
 arch/nios2/kernel/time.c                  | 67 ++++++++++++++-------
 drivers/clocksource/arm_arch_timer.c      | 46 +++++++++------
 drivers/clocksource/arm_global_timer.c    | 26 ++++++---
 drivers/clocksource/armv7m_systick.c      | 16 ++++--
 drivers/clocksource/asm9260_timer.c       | 22 ++++---
 drivers/clocksource/bcm2835_timer.c       | 38 ++++++++----
 drivers/clocksource/bcm_kona_timer.c      |  8 ++-
 drivers/clocksource/cadence_ttc_timer.c   | 74 +++++++++++++++---------
 drivers/clocksource/clksrc-dbx500-prcmu.c |  4 +-
 drivers/clocksource/clksrc-probe.c        | 14 ++++-
 drivers/clocksource/clksrc_st_lpc.c       | 20 ++++---
 drivers/clocksource/clps711x-timer.c      | 10 ++--
 drivers/clocksource/dw_apb_timer_of.c     |  4 +-
 drivers/clocksource/exynos_mct.c          | 32 +++++++----
 drivers/clocksource/fsl_ftm_timer.c       | 20 ++++---
 drivers/clocksource/h8300_timer16.c       | 12 ++--
 drivers/clocksource/h8300_timer8.c        | 11 ++--
 drivers/clocksource/h8300_tpu.c           | 10 ++--
 drivers/clocksource/meson6_timer.c        | 19 ++++--
 drivers/clocksource/mips-gic-timer.c      | 24 +++++---
 drivers/clocksource/moxart_timer.c        | 39 ++++++++-----
 drivers/clocksource/mps2-timer.c          |  8 ++-
 drivers/clocksource/mtk_timer.c           |  8 ++-
 drivers/clocksource/mxs_timer.c           | 24 +++++---
 drivers/clocksource/nomadik-mtu.c         | 43 +++++++++-----
 drivers/clocksource/pxa_timer.c           | 44 ++++++++++----
 drivers/clocksource/qcom-timer.c          | 23 ++++----
 drivers/clocksource/rockchip_timer.c      | 18 +++---
 drivers/clocksource/samsung_pwm_timer.c   | 54 +++++++++--------
 drivers/clocksource/sun4i_timer.c         | 43 ++++++++++----
 drivers/clocksource/tango_xtal.c          | 10 ++--
 drivers/clocksource/tegra20_timer.c       | 24 ++++----
 drivers/clocksource/time-armada-370-xp.c  | 96 +++++++++++++++++++++++--------
 drivers/clocksource/time-efm32.c          | 16 ++++--
 drivers/clocksource/time-lpc32xx.c        | 10 ++--
 drivers/clocksource/time-orion.c          | 50 +++++++++++-----
 drivers/clocksource/time-pistachio.c      | 18 +++---
 drivers/clocksource/timer-atlas7.c        | 30 ++++++----
 drivers/clocksource/timer-atmel-pit.c     | 41 ++++++++-----
 drivers/clocksource/timer-atmel-st.c      | 42 +++++++++-----
 drivers/clocksource/timer-digicolor.c     | 14 +++--
 drivers/clocksource/timer-imx-gpt.c       | 51 ++++++++++------
 drivers/clocksource/timer-integrator-ap.c | 57 +++++++++++-------
 drivers/clocksource/timer-keystone.c      | 13 +++--
 drivers/clocksource/timer-nps.c           | 14 +++--
 drivers/clocksource/timer-oxnas-rps.c     | 29 ++++++----
 drivers/clocksource/timer-prima2.c        | 41 +++++++++----
 drivers/clocksource/timer-sp804.c         | 87 ++++++++++++++++++----------
 drivers/clocksource/timer-stm32.c         |  8 ++-
 drivers/clocksource/timer-sun5i.c         | 33 +++++++----
 drivers/clocksource/timer-ti-32k.c        |  8 ++-
 drivers/clocksource/timer-u300.c          | 36 ++++++++----
 drivers/clocksource/versatile.c           |  6 +-
 drivers/clocksource/vf_pit_timer.c        | 25 +++++---
 drivers/clocksource/vt8500_timer.c        | 24 +++++---
 drivers/clocksource/zevio-timer.c         |  4 +-
 include/clocksource/timer-sp804.h         |  8 +--
 include/linux/clocksource.h               |  2 +-
 include/linux/of.h                        |  3 +
 63 files changed, 1133 insertions(+), 580 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH V2 01/63] of: Add a new macro to declare_of for one parameter function returning a value
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
@ 2016-06-16 21:26 ` 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
                   ` (61 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Rob Herring, Frank Rowand, Grant Likely,
	open list:OPEN FIRMWARE AND...

The macro OF_DECLARE_1 expect a void (*func)(struct device_node *) while the
OF_DECLARE_2 expect a int (*func)(struct device_node *, struct device_node *).

The second one allows to pass an init function returning a value, which make
possible to call the functions in the table and check the return value in order
to catch at a higher level the errors and handle them from there instead of
doing a panic in each driver (well at least this is the case for the clkevt).

Unfortunately the OF_DECLARE_1 does not allow that and that lead to some code
duplication and crappyness in the drivers.

The OF_DECLARE_1 is used by all the clk drivers and the clocksource/clockevent
drivers. It is not possible to do the change in one shot as we have to change
all the init functions.

The OF_DECLARE_2 specifies an init function prototype with two parameters with
the node and its parent. The latter won't be used, ever, in the timer drivers.

Introduce a OF_DECLARE_1_RET macro to be used, and hopefully we can smoothly
and iteratively change the users of OF_DECLARE_1 to use the new macro instead.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 include/linux/of.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/of.h b/include/linux/of.h
index c7292e8..552943d 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1009,10 +1009,13 @@ static inline int of_get_available_child_count(const struct device_node *np)
 #endif
 
 typedef int (*of_init_fn_2)(struct device_node *, struct device_node *);
+typedef int (*of_init_fn_1_ret)(struct device_node *);
 typedef void (*of_init_fn_1)(struct device_node *);
 
 #define OF_DECLARE_1(table, name, compat, fn) \
 		_OF_DECLARE(table, name, compat, fn, of_init_fn_1)
+#define OF_DECLARE_1_RET(table, name, compat, fn) \
+		_OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret)
 #define OF_DECLARE_2(table, name, compat, fn) \
 		_OF_DECLARE(table, name, compat, fn, of_init_fn_2)
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 02/63] clocksource/drivers/clksrc-probe: Introduce init functions with return code
  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-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 03/63] clocksource/drivers/rockchip_timer: Convert init function to return error Daniel Lezcano
                   ` (60 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Arnd Bergmann, John Stultz, open list:GENERIC INCLUDE/A...

Currently, the clksrc-probe is not able to handle any error from the init
functions. There are different issues with the current code:
 - the code is duplicated in the init functions by writing error
 - every driver tends to panic in its own init function
 - counting the number of clocksources is not reliable

This patch adds another table to store the functions returning an error.
The table is temporary while we convert all the drivers to return an error
and will disappear.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/clocksource/clksrc-probe.c | 22 ++++++++++++++++++++++
 include/asm-generic/vmlinux.lds.h  |  2 ++
 include/linux/clocksource.h        |  3 +++
 3 files changed, 27 insertions(+)

diff --git a/drivers/clocksource/clksrc-probe.c b/drivers/clocksource/clksrc-probe.c
index 7cb6c92..5fa6a55 100644
--- a/drivers/clocksource/clksrc-probe.c
+++ b/drivers/clocksource/clksrc-probe.c
@@ -20,16 +20,22 @@
 #include <linux/clocksource.h>
 
 extern struct of_device_id __clksrc_of_table[];
+extern struct of_device_id __clksrc_ret_of_table[];
 
 static const struct of_device_id __clksrc_of_table_sentinel
 	__used __section(__clksrc_of_table_end);
 
+static const struct of_device_id __clksrc_ret_of_table_sentinel
+	__used __section(__clksrc_ret_of_table_end);
+
 void __init clocksource_probe(void)
 {
 	struct device_node *np;
 	const struct of_device_id *match;
 	of_init_fn_1 init_func;
+	of_init_fn_1_ret init_func_ret;
 	unsigned clocksources = 0;
+	int ret;
 
 	for_each_matching_node_and_match(np, __clksrc_of_table, &match) {
 		if (!of_device_is_available(np))
@@ -40,6 +46,22 @@ void __init clocksource_probe(void)
 		clocksources++;
 	}
 
+	for_each_matching_node_and_match(np, __clksrc_ret_of_table, &match) {
+		if (!of_device_is_available(np))
+			continue;
+
+		init_func_ret = match->data;
+
+		ret = init_func_ret(np);
+		if (ret) {
+			pr_err("Failed to initialize '%s': %d",
+			       of_node_full_name(np), ret);
+			continue;
+		}
+
+		clocksources++;
+	}
+
 	clocksources += acpi_probe_device_table(clksrc);
 
 	if (!clocksources)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 6a67ab9..8c6c626 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -173,6 +173,7 @@
 	*(__##name##_of_table_end)
 
 #define CLKSRC_OF_TABLES()	OF_TABLE(CONFIG_CLKSRC_OF, clksrc)
+#define CLKSRC_RET_OF_TABLES()	OF_TABLE(CONFIG_CLKSRC_OF, clksrc_ret)
 #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)
 #define CLK_OF_TABLES()		OF_TABLE(CONFIG_COMMON_CLK, clk)
 #define IOMMU_OF_TABLES()	OF_TABLE(CONFIG_OF_IOMMU, iommu)
@@ -531,6 +532,7 @@
 	CLK_OF_TABLES()							\
 	RESERVEDMEM_OF_TABLES()						\
 	CLKSRC_OF_TABLES()						\
+	CLKSRC_RET_OF_TABLES()						\
 	IOMMU_OF_TABLES()						\
 	CPU_METHOD_OF_TABLES()						\
 	CPUIDLE_METHOD_OF_TABLES()					\
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 44a1aff..15c3839 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -246,6 +246,9 @@ extern int clocksource_i8253_init(void);
 #define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \
 	OF_DECLARE_1(clksrc, name, compat, fn)
 
+#define CLOCKSOURCE_OF_DECLARE_RET(name, compat, fn) \
+	OF_DECLARE_1_RET(clksrc_ret, name, compat, fn)
+
 #ifdef CONFIG_CLKSRC_PROBE
 extern void clocksource_probe(void);
 #else
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 03/63] clocksource/drivers/rockchip_timer: Convert init function to return error
  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-16 21:26 ` [PATCH V2 02/63] clocksource/drivers/clksrc-probe: Introduce init functions with return code Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-18 10:38   ` Heiko Stübner
  2016-06-16 21:26 ` [PATCH V2 04/63] clocksource/drivers/mkt_timer: " Daniel Lezcano
                   ` (59 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Heiko Stuebner, moderated list:ARM/Rockchip SoC...,
	open list:ARM/Rockchip SoC...

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/rockchip_timer.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/clocksource/rockchip_timer.c b/drivers/clocksource/rockchip_timer.c
index a3f22b0..d10bdee 100644
--- a/drivers/clocksource/rockchip_timer.c
+++ b/drivers/clocksource/rockchip_timer.c
@@ -113,17 +113,17 @@ static irqreturn_t rk_timer_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static void __init rk_timer_init(struct device_node *np, u32 ctrl_reg)
+static int __init rk_timer_init(struct device_node *np, u32 ctrl_reg)
 {
 	struct clock_event_device *ce = &bc_timer.ce;
 	struct clk *timer_clk;
 	struct clk *pclk;
-	int ret, irq;
+	int ret = -EINVAL, irq;
 
 	bc_timer.base = of_iomap(np, 0);
 	if (!bc_timer.base) {
 		pr_err("Failed to get base address for '%s'\n", TIMER_NAME);
-		return;
+		return -ENXIO;
 	}
 	bc_timer.ctrl = bc_timer.base + ctrl_reg;
 
@@ -178,7 +178,7 @@ static void __init rk_timer_init(struct device_node *np, u32 ctrl_reg)
 
 	clockevents_config_and_register(ce, bc_timer.freq, 1, UINT_MAX);
 
-	return;
+	return 0;
 
 out_irq:
 	clk_disable_unprepare(timer_clk);
@@ -186,19 +186,21 @@ out_timer_clk:
 	clk_disable_unprepare(pclk);
 out_unmap:
 	iounmap(bc_timer.base);
+
+	return ret;
 }
 
-static void __init rk3288_timer_init(struct device_node *np)
+static int __init rk3288_timer_init(struct device_node *np)
 {
-	rk_timer_init(np, TIMER_CONTROL_REG3288);
+	return rk_timer_init(np, TIMER_CONTROL_REG3288);
 }
 
-static void __init rk3399_timer_init(struct device_node *np)
+static int __init rk3399_timer_init(struct device_node *np)
 {
-	rk_timer_init(np, TIMER_CONTROL_REG3399);
+	return rk_timer_init(np, TIMER_CONTROL_REG3399);
 }
 
-CLOCKSOURCE_OF_DECLARE(rk3288_timer, "rockchip,rk3288-timer",
-		       rk3288_timer_init);
-CLOCKSOURCE_OF_DECLARE(rk3399_timer, "rockchip,rk3399-timer",
-		       rk3399_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(rk3288_timer, "rockchip,rk3288-timer",
+			   rk3288_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(rk3399_timer, "rockchip,rk3399-timer",
+			   rk3399_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 04/63] clocksource/drivers/mkt_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (2 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 03/63] clocksource/drivers/rockchip_timer: Convert init function to return error Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-17 16:16   ` Matthias Brugger
  2016-06-16 21:26 ` [PATCH V2 05/63] clocksource/drivers/exynos_mct: " Daniel Lezcano
                   ` (58 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Matthias Brugger,
	moderated list:ARM/Mediatek SoC...,
	moderated list:ARM/Mediatek SoC...

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/mtk_timer.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clocksource/mtk_timer.c b/drivers/clocksource/mtk_timer.c
index 7e583f8..432a2c0 100644
--- a/drivers/clocksource/mtk_timer.c
+++ b/drivers/clocksource/mtk_timer.c
@@ -181,7 +181,7 @@ static void mtk_timer_enable_irq(struct mtk_clock_event_device *evt, u8 timer)
 			evt->gpt_base + GPT_IRQ_EN_REG);
 }
 
-static void __init mtk_timer_init(struct device_node *node)
+static int __init mtk_timer_init(struct device_node *node)
 {
 	struct mtk_clock_event_device *evt;
 	struct resource res;
@@ -190,7 +190,7 @@ static void __init mtk_timer_init(struct device_node *node)
 
 	evt = kzalloc(sizeof(*evt), GFP_KERNEL);
 	if (!evt)
-		return;
+		return -ENOMEM;
 
 	evt->dev.name = "mtk_tick";
 	evt->dev.rating = 300;
@@ -248,7 +248,7 @@ static void __init mtk_timer_init(struct device_node *node)
 
 	mtk_timer_enable_irq(evt, GPT_CLK_EVT);
 
-	return;
+	return 0;
 
 err_clk_disable:
 	clk_disable_unprepare(clk);
@@ -262,5 +262,7 @@ err_mem:
 	release_mem_region(res.start, resource_size(&res));
 err_kzalloc:
 	kfree(evt);
+
+	return -EINVAL;
 }
-CLOCKSOURCE_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(mtk_mt6577, "mediatek,mt6577-timer", mtk_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 05/63] clocksource/drivers/exynos_mct: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (3 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 04/63] clocksource/drivers/mkt_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 06/63] clocksource/drivers/asm9260: " Daniel Lezcano
                   ` (57 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Kukjin Kim, Krzysztof Kozlowski,
	moderated list:ARM/SAMSUNG EXYNO...,
	moderated list:ARM/SAMSUNG EXYNO...

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>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/clocksource/exynos_mct.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/clocksource/exynos_mct.c b/drivers/clocksource/exynos_mct.c
index be09bc0..f6caed0 100644
--- a/drivers/clocksource/exynos_mct.c
+++ b/drivers/clocksource/exynos_mct.c
@@ -232,7 +232,7 @@ static cycles_t exynos4_read_current_timer(void)
 	return exynos4_read_count_32();
 }
 
-static void __init exynos4_clocksource_init(void)
+static int __init exynos4_clocksource_init(void)
 {
 	exynos4_mct_frc_start();
 
@@ -244,6 +244,8 @@ static void __init exynos4_clocksource_init(void)
 		panic("%s: can't register clocksource\n", mct_frc.name);
 
 	sched_clock_register(exynos4_read_sched_clock, 32, clk_rate);
+
+	return 0;
 }
 
 static void exynos4_mct_comp0_stop(void)
@@ -335,12 +337,14 @@ static struct irqaction mct_comp_event_irq = {
 	.dev_id		= &mct_comp_device,
 };
 
-static void exynos4_clockevent_init(void)
+static int exynos4_clockevent_init(void)
 {
 	mct_comp_device.cpumask = cpumask_of(0);
 	clockevents_config_and_register(&mct_comp_device, clk_rate,
 					0xf, 0xffffffff);
 	setup_irq(mct_irqs[MCT_G0_IRQ], &mct_comp_event_irq);
+
+	return 0;
 }
 
 static DEFINE_PER_CPU(struct mct_clock_event_device, percpu_mct_tick);
@@ -516,7 +520,7 @@ static struct notifier_block exynos4_mct_cpu_nb = {
 	.notifier_call = exynos4_mct_cpu_notify,
 };
 
-static void __init exynos4_timer_resources(struct device_node *np, void __iomem *base)
+static int __init exynos4_timer_resources(struct device_node *np, void __iomem *base)
 {
 	int err, cpu;
 	struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick);
@@ -572,15 +576,17 @@ static void __init exynos4_timer_resources(struct device_node *np, void __iomem
 
 	/* Immediately configure the timer on the boot CPU */
 	exynos4_local_timer_setup(mevt);
-	return;
+	return 0;
 
 out_irq:
 	free_percpu_irq(mct_irqs[MCT_L0_IRQ], &percpu_mct_tick);
+	return err;
 }
 
-static void __init mct_init_dt(struct device_node *np, unsigned int int_type)
+static int __init mct_init_dt(struct device_node *np, unsigned int int_type)
 {
 	u32 nr_irqs, i;
+	int ret;
 
 	mct_int_type = int_type;
 
@@ -600,20 +606,26 @@ static void __init mct_init_dt(struct device_node *np, unsigned int int_type)
 	for (i = MCT_L0_IRQ; i < nr_irqs; i++)
 		mct_irqs[i] = irq_of_parse_and_map(np, i);
 
-	exynos4_timer_resources(np, of_iomap(np, 0));
-	exynos4_clocksource_init();
-	exynos4_clockevent_init();
+	ret = exynos4_timer_resources(np, of_iomap(np, 0));
+	if (ret)
+		return ret;
+
+	ret = exynos4_clocksource_init();
+	if (ret)
+		return ret;
+
+	return exynos4_clockevent_init();
 }
 
 
-static void __init mct_init_spi(struct device_node *np)
+static int __init mct_init_spi(struct device_node *np)
 {
 	return mct_init_dt(np, MCT_INT_SPI);
 }
 
-static void __init mct_init_ppi(struct device_node *np)
+static int __init mct_init_ppi(struct device_node *np)
 {
 	return mct_init_dt(np, MCT_INT_PPI);
 }
-CLOCKSOURCE_OF_DECLARE(exynos4210, "samsung,exynos4210-mct", mct_init_spi);
-CLOCKSOURCE_OF_DECLARE(exynos4412, "samsung,exynos4412-mct", mct_init_ppi);
+CLOCKSOURCE_OF_DECLARE_RET(exynos4210, "samsung,exynos4210-mct", mct_init_spi);
+CLOCKSOURCE_OF_DECLARE_RET(exynos4412, "samsung,exynos4412-mct", mct_init_ppi);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 06/63] clocksource/drivers/asm9260: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (4 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 05/63] clocksource/drivers/exynos_mct: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 07/63] clocksource/drivers/cadence_ttc: " Daniel Lezcano
                   ` (56 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/asm9260_timer.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/asm9260_timer.c b/drivers/clocksource/asm9260_timer.c
index 217438d..d113c02 100644
--- a/drivers/clocksource/asm9260_timer.c
+++ b/drivers/clocksource/asm9260_timer.c
@@ -184,7 +184,7 @@ static irqreturn_t asm9260_timer_interrupt(int irq, void *dev_id)
  * Timer initialization
  * ---------------------------------------------------------------------------
  */
-static void __init asm9260_timer_init(struct device_node *np)
+static int __init asm9260_timer_init(struct device_node *np)
 {
 	int irq;
 	struct clk *clk;
@@ -192,20 +192,26 @@ static void __init asm9260_timer_init(struct device_node *np)
 	unsigned long rate;
 
 	priv.base = of_io_request_and_map(np, 0, np->name);
-	if (IS_ERR(priv.base))
-		panic("%s: unable to map resource", np->name);
+	if (IS_ERR(priv.base)) {
+		pr_err("%s: unable to map resource", np->name);
+		return PTR_ERR(priv.base);
+	}
 
 	clk = of_clk_get(np, 0);
 
 	ret = clk_prepare_enable(clk);
-	if (ret)
-		panic("Failed to enable clk!\n");
+	if (ret) {
+		pr_err("Failed to enable clk!\n");
+		return ret;
+	}
 
 	irq = irq_of_parse_and_map(np, 0);
 	ret = request_irq(irq, asm9260_timer_interrupt, IRQF_TIMER,
 			DRIVER_NAME, &event_dev);
-	if (ret)
-		panic("Failed to setup irq!\n");
+	if (ret) {
+		pr_err("Failed to setup irq!\n");
+		return ret;
+	}
 
 	/* set all timers for count-up */
 	writel_relaxed(BM_DIR_DEFAULT, priv.base + HW_DIR);
@@ -229,6 +235,8 @@ static void __init asm9260_timer_init(struct device_node *np)
 	priv.ticks_per_jiffy = DIV_ROUND_CLOSEST(rate, HZ);
 	event_dev.cpumask = cpumask_of(0);
 	clockevents_config_and_register(&event_dev, rate, 0x2c00, 0xfffffffe);
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(asm9260_timer, "alphascale,asm9260-timer",
+CLOCKSOURCE_OF_DECLARE_RET(asm9260_timer, "alphascale,asm9260-timer",
 		asm9260_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 07/63] clocksource/drivers/cadence_ttc: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (5 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 06/63] clocksource/drivers/asm9260: " Daniel Lezcano
@ 2016-06-16 21:26 ` 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
                   ` (55 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Michal Simek, Sören Brinkmann,
	moderated list:ARM/ZYNQ ARCHITEC...

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/cadence_ttc_timer.c | 76 ++++++++++++++++++++-------------
 1 file changed, 47 insertions(+), 29 deletions(-)

diff --git a/drivers/clocksource/cadence_ttc_timer.c b/drivers/clocksource/cadence_ttc_timer.c
index 9be6018..e2e7631 100644
--- a/drivers/clocksource/cadence_ttc_timer.c
+++ b/drivers/clocksource/cadence_ttc_timer.c
@@ -322,22 +322,22 @@ static int ttc_rate_change_clocksource_cb(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
-static void __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
+static int __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
 					 u32 timer_width)
 {
 	struct ttc_timer_clocksource *ttccs;
 	int err;
 
 	ttccs = kzalloc(sizeof(*ttccs), GFP_KERNEL);
-	if (WARN_ON(!ttccs))
-		return;
+	if (!ttccs)
+		return -ENOMEM;
 
 	ttccs->ttc.clk = clk;
 
 	err = clk_prepare_enable(ttccs->ttc.clk);
-	if (WARN_ON(err)) {
+	if (err) {
 		kfree(ttccs);
-		return;
+		return err;
 	}
 
 	ttccs->ttc.freq = clk_get_rate(ttccs->ttc.clk);
@@ -345,8 +345,10 @@ static void __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
 	ttccs->ttc.clk_rate_change_nb.notifier_call =
 		ttc_rate_change_clocksource_cb;
 	ttccs->ttc.clk_rate_change_nb.next = NULL;
-	if (clk_notifier_register(ttccs->ttc.clk,
-				&ttccs->ttc.clk_rate_change_nb))
+
+	err = clk_notifier_register(ttccs->ttc.clk,
+				    &ttccs->ttc.clk_rate_change_nb);
+	if (err)
 		pr_warn("Unable to register clock notifier.\n");
 
 	ttccs->ttc.base_addr = base;
@@ -368,14 +370,16 @@ static void __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
 		     ttccs->ttc.base_addr + TTC_CNT_CNTRL_OFFSET);
 
 	err = clocksource_register_hz(&ttccs->cs, ttccs->ttc.freq / PRESCALE);
-	if (WARN_ON(err)) {
+	if (err) {
 		kfree(ttccs);
-		return;
+		return err;
 	}
 
 	ttc_sched_clock_val_reg = base + TTC_COUNT_VAL_OFFSET;
 	sched_clock_register(ttc_sched_clock_read, timer_width,
 			     ttccs->ttc.freq / PRESCALE);
+
+	return 0;
 }
 
 static int ttc_rate_change_clockevent_cb(struct notifier_block *nb,
@@ -401,30 +405,35 @@ static int ttc_rate_change_clockevent_cb(struct notifier_block *nb,
 	}
 }
 
-static void __init ttc_setup_clockevent(struct clk *clk,
-						void __iomem *base, u32 irq)
+static int __init ttc_setup_clockevent(struct clk *clk,
+				       void __iomem *base, u32 irq)
 {
 	struct ttc_timer_clockevent *ttcce;
 	int err;
 
 	ttcce = kzalloc(sizeof(*ttcce), GFP_KERNEL);
-	if (WARN_ON(!ttcce))
-		return;
+	if (!ttcce)
+		return -ENOMEM;
 
 	ttcce->ttc.clk = clk;
 
 	err = clk_prepare_enable(ttcce->ttc.clk);
-	if (WARN_ON(err)) {
+	if (err) {
 		kfree(ttcce);
-		return;
+		return err;
 	}
 
 	ttcce->ttc.clk_rate_change_nb.notifier_call =
 		ttc_rate_change_clockevent_cb;
 	ttcce->ttc.clk_rate_change_nb.next = NULL;
-	if (clk_notifier_register(ttcce->ttc.clk,
-				&ttcce->ttc.clk_rate_change_nb))
+
+	err = clk_notifier_register(ttcce->ttc.clk,
+				    &ttcce->ttc.clk_rate_change_nb);
+	if (err) {
 		pr_warn("Unable to register clock notifier.\n");
+		return err;
+	}
+
 	ttcce->ttc.freq = clk_get_rate(ttcce->ttc.clk);
 
 	ttcce->ttc.base_addr = base;
@@ -451,13 +460,15 @@ static void __init ttc_setup_clockevent(struct clk *clk,
 
 	err = request_irq(irq, ttc_clock_event_interrupt,
 			  IRQF_TIMER, ttcce->ce.name, ttcce);
-	if (WARN_ON(err)) {
+	if (err) {
 		kfree(ttcce);
-		return;
+		return err;
 	}
 
 	clockevents_config_and_register(&ttcce->ce,
 			ttcce->ttc.freq / PRESCALE, 1, 0xfffe);
+
+	return 0;
 }
 
 /**
@@ -466,17 +477,17 @@ static void __init ttc_setup_clockevent(struct clk *clk,
  * Initializes the timer hardware and register the clock source and clock event
  * timers with Linux kernal timer framework
  */
-static void __init ttc_timer_init(struct device_node *timer)
+static int __init ttc_timer_init(struct device_node *timer)
 {
 	unsigned int irq;
 	void __iomem *timer_baseaddr;
 	struct clk *clk_cs, *clk_ce;
 	static int initialized;
-	int clksel;
+	int clksel, ret;
 	u32 timer_width = 16;
 
 	if (initialized)
-		return;
+		return 0;
 
 	initialized = 1;
 
@@ -488,13 +499,13 @@ static void __init ttc_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;
 	}
 
 	irq = irq_of_parse_and_map(timer, 1);
 	if (irq <= 0) {
 		pr_err("ERROR: invalid interrupt number\n");
-		BUG();
+		return -EINVAL;
 	}
 
 	of_property_read_u32(timer, "timer-width", &timer_width);
@@ -504,7 +515,7 @@ static void __init ttc_timer_init(struct device_node *timer)
 	clk_cs = of_clk_get(timer, clksel);
 	if (IS_ERR(clk_cs)) {
 		pr_err("ERROR: timer input clock not found\n");
-		BUG();
+		return PTR_ERR(clk_cs);
 	}
 
 	clksel = readl_relaxed(timer_baseaddr + 4 + TTC_CLK_CNTRL_OFFSET);
@@ -512,13 +523,20 @@ static void __init ttc_timer_init(struct device_node *timer)
 	clk_ce = of_clk_get(timer, clksel);
 	if (IS_ERR(clk_ce)) {
 		pr_err("ERROR: timer input clock not found\n");
-		BUG();
+		return PTR_ERR(clk_cs);
 	}
 
-	ttc_setup_clocksource(clk_cs, timer_baseaddr, timer_width);
-	ttc_setup_clockevent(clk_ce, timer_baseaddr + 4, irq);
+	ret = ttc_setup_clocksource(clk_cs, timer_baseaddr, timer_width);
+	if (ret)
+		return ret;
+
+	ret = ttc_setup_clockevent(clk_ce, timer_baseaddr + 4, irq);
+	if (ret)
+		return ret;
 
 	pr_info("%s #0 at %p, irq=%d\n", timer->name, timer_baseaddr, irq);
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(ttc, "cdns,ttc", ttc_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(ttc, "cdns,ttc", ttc_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 08/63] clocksource/drivers/st_lpc: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (6 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 07/63] clocksource/drivers/cadence_ttc: " Daniel Lezcano
@ 2016-06-16 21:26 ` 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
                   ` (54 subsequent siblings)
  62 siblings, 2 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Srinivas Kandagatla, Maxime Coquelin,
	Patrice Chotard, moderated list:ARM/STI ARCHITECTURE,
	open list:ARM/STI ARCHITECTURE

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/clksrc_st_lpc.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/clocksource/clksrc_st_lpc.c b/drivers/clocksource/clksrc_st_lpc.c
index 65ec467..c9022a9 100644
--- a/drivers/clocksource/clksrc_st_lpc.c
+++ b/drivers/clocksource/clksrc_st_lpc.c
@@ -92,7 +92,7 @@ static int __init st_clksrc_setup_clk(struct device_node *np)
 	return 0;
 }
 
-static void __init st_clksrc_of_register(struct device_node *np)
+static int __init st_clksrc_of_register(struct device_node *np)
 {
 	int ret;
 	uint32_t mode;
@@ -100,32 +100,36 @@ static void __init st_clksrc_of_register(struct device_node *np)
 	ret = of_property_read_u32(np, "st,lpc-mode", &mode);
 	if (ret) {
 		pr_err("clksrc-st-lpc: An LPC mode must be provided\n");
-		return;
+		return ret;
 	}
 
 	/* LPC can either run as a Clocksource or in RTC or WDT mode */
 	if (mode != ST_LPC_MODE_CLKSRC)
-		return;
+		return 0;
 
 	ddata.base = of_iomap(np, 0);
 	if (!ddata.base) {
 		pr_err("clksrc-st-lpc: Unable to map iomem\n");
-		return;
+		return -ENXIO;
 	}
 
-	if (st_clksrc_setup_clk(np)) {
+	ret = st_clksrc_setup_clk(np);
+	if (ret) {
 		iounmap(ddata.base);
-		return;
+		return ret;
 	}
 
-	if (st_clksrc_init()) {
+	ret = st_clksrc_init();
+	if (ret) {
 		clk_disable_unprepare(ddata.clk);
 		clk_put(ddata.clk);
 		iounmap(ddata.base);
-		return;
+		return ret;
 	}
 
 	pr_info("clksrc-st-lpc: clocksource initialised - running @ %luHz\n",
 		clk_get_rate(ddata.clk));
+
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(ddata, "st,stih407-lpc", st_clksrc_of_register);
+CLOCKSOURCE_OF_DECLARE_RET(ddata, "st,stih407-lpc", st_clksrc_of_register);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 09/63] clocksource/drivers/dw_apb_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (7 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 08/63] clocksource/drivers/st_lpc: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 10/63] clocksource/drivers/clps711x: " Daniel Lezcano
                   ` (53 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/dw_apb_timer_of.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/dw_apb_timer_of.c b/drivers/clocksource/dw_apb_timer_of.c
index 860843c..4985a2c 100644
--- a/drivers/clocksource/dw_apb_timer_of.c
+++ b/drivers/clocksource/dw_apb_timer_of.c
@@ -143,7 +143,7 @@ static struct delay_timer dw_apb_delay_timer = {
 #endif
 
 static int num_called;
-static void __init dw_apb_timer_init(struct device_node *timer)
+static int __init dw_apb_timer_init(struct device_node *timer)
 {
 	switch (num_called) {
 	case 0:
@@ -164,8 +164,10 @@ static void __init dw_apb_timer_init(struct device_node *timer)
 	}
 
 	num_called++;
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(pc3x2_timer, "picochip,pc3x2-timer", dw_apb_timer_init);
-CLOCKSOURCE_OF_DECLARE(apb_timer_osc, "snps,dw-apb-timer-osc", dw_apb_timer_init);
-CLOCKSOURCE_OF_DECLARE(apb_timer_sp, "snps,dw-apb-timer-sp", dw_apb_timer_init);
-CLOCKSOURCE_OF_DECLARE(apb_timer, "snps,dw-apb-timer", dw_apb_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(pc3x2_timer, "picochip,pc3x2-timer", dw_apb_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(apb_timer_osc, "snps,dw-apb-timer-osc", dw_apb_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(apb_timer_sp, "snps,dw-apb-timer-sp", dw_apb_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(apb_timer, "snps,dw-apb-timer", dw_apb_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 10/63] clocksource/drivers/clps711x: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (8 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 09/63] clocksource/drivers/dw_apb_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 11/63] clocksource/drivers/digitcolor: " Daniel Lezcano
                   ` (52 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Alexander Shiyan, moderated list:ARM/CIRRUS LOGIC...

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/clps711x-timer.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/clocksource/clps711x-timer.c b/drivers/clocksource/clps711x-timer.c
index cdd86e3..3b66198 100644
--- a/drivers/clocksource/clps711x-timer.c
+++ b/drivers/clocksource/clps711x-timer.c
@@ -104,7 +104,7 @@ void __init clps711x_clksrc_init(void __iomem *tc1_base, void __iomem *tc2_base,
 }
 
 #ifdef CONFIG_CLKSRC_OF
-static void __init clps711x_timer_init(struct device_node *np)
+static int __init clps711x_timer_init(struct device_node *np)
 {
 	unsigned int irq = irq_of_parse_and_map(np, 0);
 	struct clk *clock = of_clk_get(np, 0);
@@ -112,14 +112,12 @@ static void __init clps711x_timer_init(struct device_node *np)
 
 	switch (of_alias_get_id(np, "timer")) {
 	case CLPS711X_CLKSRC_CLOCKSOURCE:
-		BUG_ON(_clps711x_clksrc_init(clock, base));
-		break;
+		return _clps711x_clksrc_init(clock, base);
 	case CLPS711X_CLKSRC_CLOCKEVENT:
-		BUG_ON(_clps711x_clkevt_init(clock, base, irq));
-		break;
+		return _clps711x_clkevt_init(clock, base, irq);
 	default:
-		break;
+		return -EINVAL;
 	}
 }
-CLOCKSOURCE_OF_DECLARE(clps711x, "cirrus,clps711x-timer", clps711x_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(clps711x, "cirrus,clps711x-timer", clps711x_timer_init);
 #endif
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 11/63] clocksource/drivers/digitcolor: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (9 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 10/63] clocksource/drivers/clps711x: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-17  3:15   ` Baruch Siach
  2016-06-16 21:26 ` [PATCH V2 12/63] clocksource/drivers/armv7m_systick: " Daniel Lezcano
                   ` (51 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Baruch Siach, moderated list:ARM/CONEXANT DIGI...

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-digicolor.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/clocksource/timer-digicolor.c b/drivers/clocksource/timer-digicolor.c
index 96bb222..b929061 100644
--- a/drivers/clocksource/timer-digicolor.c
+++ b/drivers/clocksource/timer-digicolor.c
@@ -148,7 +148,7 @@ static u64 notrace digicolor_timer_sched_read(void)
 	return ~readl(dc_timer_dev.base + COUNT(TIMER_B));
 }
 
-static void __init digicolor_timer_init(struct device_node *node)
+static int __init digicolor_timer_init(struct device_node *node)
 {
 	unsigned long rate;
 	struct clk *clk;
@@ -161,19 +161,19 @@ static void __init digicolor_timer_init(struct device_node *node)
 	dc_timer_dev.base = of_iomap(node, 0);
 	if (!dc_timer_dev.base) {
 		pr_err("Can't map registers");
-		return;
+		return -ENXIO;
 	}
 
 	irq = irq_of_parse_and_map(node, dc_timer_dev.timer_id);
 	if (irq <= 0) {
 		pr_err("Can't parse IRQ");
-		return;
+		return -EINVAL;
 	}
 
 	clk = of_clk_get(node, 0);
 	if (IS_ERR(clk)) {
 		pr_err("Can't get timer clock");
-		return;
+		return PTR_ERR(clk);
 	}
 	clk_prepare_enable(clk);
 	rate = clk_get_rate(clk);
@@ -190,13 +190,17 @@ static void __init digicolor_timer_init(struct device_node *node)
 	ret = request_irq(irq, digicolor_timer_interrupt,
 			  IRQF_TIMER | IRQF_IRQPOLL, "digicolor_timerC",
 			  &dc_timer_dev.ce);
-	if (ret)
+	if (ret) {
 		pr_warn("request of timer irq %d failed (%d)\n", irq, ret);
+		return ret;
+	}
 
 	dc_timer_dev.ce.cpumask = cpu_possible_mask;
 	dc_timer_dev.ce.irq = irq;
 
 	clockevents_config_and_register(&dc_timer_dev.ce, rate, 0, 0xffffffff);
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(conexant_digicolor, "cnxt,cx92755-timer",
+CLOCKSOURCE_OF_DECLARE_RET(conexant_digicolor, "cnxt,cx92755-timer",
 		       digicolor_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 12/63] clocksource/drivers/armv7m_systick: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (10 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 11/63] clocksource/drivers/digitcolor: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-20 11:31   ` Maxime Coquelin
  2016-06-16 21:26 ` [PATCH V2 13/63] clocksource/drivers/bcm2835_timer: " Daniel Lezcano
                   ` (50 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Maxime Coquelin, moderated list:ARM/STM32 ARCHITE...

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/armv7m_systick.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/clocksource/armv7m_systick.c b/drivers/clocksource/armv7m_systick.c
index addfd2c..2b55410 100644
--- a/drivers/clocksource/armv7m_systick.c
+++ b/drivers/clocksource/armv7m_systick.c
@@ -21,7 +21,7 @@
 
 #define SYSTICK_LOAD_RELOAD_MASK 0x00FFFFFF
 
-static void __init system_timer_of_register(struct device_node *np)
+static int __init system_timer_of_register(struct device_node *np)
 {
 	struct clk *clk = NULL;
 	void __iomem *base;
@@ -31,22 +31,26 @@ static void __init system_timer_of_register(struct device_node *np)
 	base = of_iomap(np, 0);
 	if (!base) {
 		pr_warn("system-timer: invalid base address\n");
-		return;
+		return -ENXIO;
 	}
 
 	ret = of_property_read_u32(np, "clock-frequency", &rate);
 	if (ret) {
 		clk = of_clk_get(np, 0);
-		if (IS_ERR(clk))
+		if (IS_ERR(clk)) {
+			ret = PTR_ERR(clk);
 			goto out_unmap;
+		}
 
 		ret = clk_prepare_enable(clk);
 		if (ret)
 			goto out_clk_put;
 
 		rate = clk_get_rate(clk);
-		if (!rate)
+		if (!rate) {
+			ret = -EINVAL;
 			goto out_clk_disable;
+		}
 	}
 
 	writel_relaxed(SYSTICK_LOAD_RELOAD_MASK, base + SYST_RVR);
@@ -64,7 +68,7 @@ static void __init system_timer_of_register(struct device_node *np)
 
 	pr_info("ARM System timer initialized as clocksource\n");
 
-	return;
+	return 0;
 
 out_clk_disable:
 	clk_disable_unprepare(clk);
@@ -73,7 +77,9 @@ out_clk_put:
 out_unmap:
 	iounmap(base);
 	pr_warn("ARM System timer register failed (%d)\n", ret);
+
+	return ret;
 }
 
-CLOCKSOURCE_OF_DECLARE(arm_systick, "arm,armv7m-systick",
+CLOCKSOURCE_OF_DECLARE_RET(arm_systick, "arm,armv7m-systick",
 			system_timer_of_register);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 13/63] clocksource/drivers/bcm2835_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (11 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 12/63] clocksource/drivers/armv7m_systick: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-26  3:10   ` Eric Anholt
  2016-06-16 21:26 ` [PATCH V2 14/63] clocksource/drivers/bcm_kona: " Daniel Lezcano
                   ` (49 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Stephen Warren, Lee Jones, Eric Anholt,
	moderated list:BROADCOM BCM2835...,
	moderated list:BROADCOM BCM2835...

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

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 14/63] clocksource/drivers/bcm_kona: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (12 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 13/63] clocksource/drivers/bcm2835_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-20 17:22   ` Ray Jui
  2016-06-16 21:26 ` [PATCH V2 15/63] clocksource/drivers/clksrc-dbx500: " Daniel Lezcano
                   ` (48 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Florian Fainelli, Ray Jui, Scott Branden,
	open list:BROADCOM BCM281XX...

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/bcm_kona_timer.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c
index e717e87..98bc2a2 100644
--- a/drivers/clocksource/bcm_kona_timer.c
+++ b/drivers/clocksource/bcm_kona_timer.c
@@ -163,14 +163,14 @@ static struct irqaction kona_timer_irq = {
 	.handler = kona_timer_interrupt,
 };
 
-static void __init kona_timer_init(struct device_node *node)
+static int __init kona_timer_init(struct device_node *node)
 {
 	u32 freq;
 	struct clk *external_clk;
 
 	if (!of_device_is_available(node)) {
 		pr_info("Kona Timer v1 marked as disabled in device tree\n");
-		return;
+		return 0;
 	}
 
 	external_clk = of_clk_get_by_name(node, NULL);
@@ -182,7 +182,7 @@ static void __init kona_timer_init(struct device_node *node)
 		arch_timer_rate = freq;
 	} else {
 		pr_err("Kona Timer v1 unable to determine clock-frequency");
-		return;
+		return -EINVAL;
 	}
 
 	/* Setup IRQ numbers */
@@ -196,11 +196,13 @@ static void __init kona_timer_init(struct device_node *node)
 	kona_timer_clockevents_init();
 	setup_irq(timers.tmr_irq, &kona_timer_irq);
 	kona_timer_set_next_event((arch_timer_rate / HZ), NULL);
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(brcm_kona, "brcm,kona-timer", kona_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(brcm_kona, "brcm,kona-timer", kona_timer_init);
 /*
  * bcm,kona-timer is deprecated by brcm,kona-timer
  * being kept here for driver compatibility
  */
-CLOCKSOURCE_OF_DECLARE(bcm_kona, "bcm,kona-timer", kona_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(bcm_kona, "bcm,kona-timer", kona_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 15/63] clocksource/drivers/clksrc-dbx500: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (13 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 14/63] clocksource/drivers/bcm_kona: " Daniel Lezcano
@ 2016-06-16 21:26 ` 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
                   ` (47 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Linus Walleij, moderated list:ARM/Ux500 ARM ARC...

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/clksrc-dbx500-prcmu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clocksource/clksrc-dbx500-prcmu.c b/drivers/clocksource/clksrc-dbx500-prcmu.c
index dfad6eb..5a59d29 100644
--- a/drivers/clocksource/clksrc-dbx500-prcmu.c
+++ b/drivers/clocksource/clksrc-dbx500-prcmu.c
@@ -64,7 +64,7 @@ static u64 notrace dbx500_prcmu_sched_clock_read(void)
 
 #endif
 
-static void __init clksrc_dbx500_prcmu_init(struct device_node *node)
+static int __init clksrc_dbx500_prcmu_init(struct device_node *node)
 {
 	clksrc_dbx500_timer_base = of_iomap(node, 0);
 
@@ -84,7 +84,7 @@ static void __init clksrc_dbx500_prcmu_init(struct device_node *node)
 #ifdef CONFIG_CLKSRC_DBX500_PRCMU_SCHED_CLOCK
 	sched_clock_register(dbx500_prcmu_sched_clock_read, 32, RATE_32K);
 #endif
-	clocksource_register_hz(&clocksource_dbx500_prcmu, RATE_32K);
+	return clocksource_register_hz(&clocksource_dbx500_prcmu, RATE_32K);
 }
-CLOCKSOURCE_OF_DECLARE(dbx500_prcmu, "stericsson,db8500-prcmu-timer-4",
+CLOCKSOURCE_OF_DECLARE_RET(dbx500_prcmu, "stericsson,db8500-prcmu-timer-4",
 		       clksrc_dbx500_prcmu_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 16/63] clocksource/drivers/fsl_ftm_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (14 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 15/63] clocksource/drivers/clksrc-dbx500: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 17/63] clocksource/drivers/arm_arch_timer: " Daniel Lezcano
                   ` (46 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/fsl_ftm_timer.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/fsl_ftm_timer.c b/drivers/clocksource/fsl_ftm_timer.c
index 517e1c7..9ad4ca3 100644
--- a/drivers/clocksource/fsl_ftm_timer.c
+++ b/drivers/clocksource/fsl_ftm_timer.c
@@ -316,15 +316,16 @@ static int __init ftm_calc_closest_round_cyc(unsigned long freq)
 	return 0;
 }
 
-static void __init ftm_timer_init(struct device_node *np)
+static int __init ftm_timer_init(struct device_node *np)
 {
 	unsigned long freq;
-	int irq;
+	int ret, irq;
 
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
 	if (!priv)
-		return;
+		return -ENOMEM;
 
+	ret = -ENXIO;
 	priv->clkevt_base = of_iomap(np, 0);
 	if (!priv->clkevt_base) {
 		pr_err("ftm: unable to map event timer registers\n");
@@ -337,6 +338,7 @@ static void __init ftm_timer_init(struct device_node *np)
 		goto err;
 	}
 
+	ret = -EINVAL;
 	irq = irq_of_parse_and_map(np, 0);
 	if (irq <= 0) {
 		pr_err("ftm: unable to get IRQ from DT, %d\n", irq);
@@ -349,18 +351,22 @@ static void __init ftm_timer_init(struct device_node *np)
 	if (!freq)
 		goto err;
 
-	if (ftm_calc_closest_round_cyc(freq))
+	ret = ftm_calc_closest_round_cyc(freq);
+	if (ret)
 		goto err;
 
-	if (ftm_clocksource_init(freq))
+	ret = ftm_clocksource_init(freq);
+	if (ret)
 		goto err;
 
-	if (ftm_clockevent_init(freq, irq))
+	ret = ftm_clockevent_init(freq, irq);
+	if (ret)
 		goto err;
 
-	return;
+	return 0;
 
 err:
 	kfree(priv);
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(flextimer, "fsl,ftm-timer", ftm_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(flextimer, "fsl,ftm-timer", ftm_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 17/63] clocksource/drivers/arm_arch_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (15 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 16/63] clocksource/drivers/fsl_ftm_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 18/63] clocksource/drivers/arm_global_timer: " Daniel Lezcano
                   ` (45 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/arm_arch_timer.c | 52 +++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 19 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 4814446..d0cda68 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -693,25 +693,26 @@ arch_timer_needs_probing(int type, const struct of_device_id *matches)
 	return needs_probing;
 }
 
-static void __init arch_timer_common_init(void)
+static int __init arch_timer_common_init(void)
 {
 	unsigned mask = ARCH_CP15_TIMER | ARCH_MEM_TIMER;
 
 	/* Wait until both nodes are probed if we have two timers */
 	if ((arch_timers_present & mask) != mask) {
 		if (arch_timer_needs_probing(ARCH_MEM_TIMER, arch_timer_mem_of_match))
-			return;
+			return 0;
 		if (arch_timer_needs_probing(ARCH_CP15_TIMER, arch_timer_of_match))
-			return;
+			return 0;
 	}
 
 	arch_timer_banner(arch_timers_present);
 	arch_counter_register(arch_timers_present);
-	arch_timer_arch_init();
+	return arch_timer_arch_init();
 }
 
-static void __init arch_timer_init(void)
+static int __init arch_timer_init(void)
 {
+	int ret;
 	/*
 	 * If HYP mode is available, we know that the physical timer
 	 * has been configured to be accessible from PL1. Use it, so
@@ -739,23 +740,30 @@ static void __init arch_timer_init(void)
 
 		if (!has_ppi) {
 			pr_warn("arch_timer: No interrupt available, giving up\n");
-			return;
+			return -EINVAL;
 		}
 	}
 
-	arch_timer_register();
-	arch_timer_common_init();
+	ret = arch_timer_register();
+	if (ret)
+		return ret;
+
+	ret = arch_timer_common_init();
+	if (ret)
+		return ret;
 
 	arch_timer_kvm_info.virtual_irq = arch_timer_ppi[VIRT_PPI];
+	
+	return 0;
 }
 
-static void __init arch_timer_of_init(struct device_node *np)
+static int __init arch_timer_of_init(struct device_node *np)
 {
 	int i;
 
 	if (arch_timers_present & ARCH_CP15_TIMER) {
 		pr_warn("arch_timer: multiple nodes in dt, skipping\n");
-		return;
+		return 0;
 	}
 
 	arch_timers_present |= ARCH_CP15_TIMER;
@@ -774,23 +782,23 @@ static void __init arch_timer_of_init(struct device_node *np)
 	    of_property_read_bool(np, "arm,cpu-registers-not-fw-configured"))
 		arch_timer_uses_ppi = PHYS_SECURE_PPI;
 
-	arch_timer_init();
+	return arch_timer_init();
 }
-CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init);
-CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init);
+CLOCKSOURCE_OF_DECLARE_RET(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init);
+CLOCKSOURCE_OF_DECLARE_RET(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init);
 
-static void __init arch_timer_mem_init(struct device_node *np)
+static int __init arch_timer_mem_init(struct device_node *np)
 {
 	struct device_node *frame, *best_frame = NULL;
 	void __iomem *cntctlbase, *base;
-	unsigned int irq;
+	unsigned int irq, ret = -EINVAL;
 	u32 cnttidr;
 
 	arch_timers_present |= ARCH_MEM_TIMER;
 	cntctlbase = of_iomap(np, 0);
 	if (!cntctlbase) {
 		pr_err("arch_timer: Can't find CNTCTLBase\n");
-		return;
+		return -ENXIO;
 	}
 
 	cnttidr = readl_relaxed(cntctlbase + CNTTIDR);
@@ -830,6 +838,7 @@ static void __init arch_timer_mem_init(struct device_node *np)
 		best_frame = of_node_get(frame);
 	}
 
+	ret= -ENXIO;
 	base = arch_counter_base = of_iomap(best_frame, 0);
 	if (!base) {
 		pr_err("arch_timer: Can't map frame's registers\n");
@@ -841,6 +850,7 @@ static void __init arch_timer_mem_init(struct device_node *np)
 	else
 		irq = irq_of_parse_and_map(best_frame, 0);
 
+	ret = -EINVAL;
 	if (!irq) {
 		pr_err("arch_timer: Frame missing %s irq",
 		       arch_timer_mem_use_virtual ? "virt" : "phys");
@@ -848,13 +858,17 @@ static void __init arch_timer_mem_init(struct device_node *np)
 	}
 
 	arch_timer_detect_rate(base, np);
-	arch_timer_mem_register(base, irq);
-	arch_timer_common_init();
+	ret = arch_timer_mem_register(base, irq);
+	if (ret)
+		goto out;
+
+	return arch_timer_common_init();
 out:
 	iounmap(cntctlbase);
 	of_node_put(best_frame);
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
+CLOCKSOURCE_OF_DECLARE_RET(armv7_arch_timer_mem, "arm,armv7-timer-mem",
 		       arch_timer_mem_init);
 
 #ifdef CONFIG_ACPI
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 18/63] clocksource/drivers/arm_global_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (16 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 17/63] clocksource/drivers/arm_arch_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-20 11:32   ` Maxime Coquelin
  2016-06-16 21:26 ` [PATCH V2 19/63] clocksource/drivers/h8300_timer16: " Daniel Lezcano
                   ` (44 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Srinivas Kandagatla, Maxime Coquelin,
	Patrice Chotard, moderated list:ARM/STI ARCHITECTURE,
	open list:ARM/STI ARCHITECTURE

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/arm_global_timer.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/clocksource/arm_global_timer.c b/drivers/clocksource/arm_global_timer.c
index 9df0d16..40104fc 100644
--- a/drivers/clocksource/arm_global_timer.c
+++ b/drivers/clocksource/arm_global_timer.c
@@ -238,7 +238,7 @@ static void __init gt_delay_timer_init(void)
 	register_current_timer_delay(&gt_delay_timer);
 }
 
-static void __init gt_clocksource_init(void)
+static int __init gt_clocksource_init(void)
 {
 	writel(0, gt_base + GT_CONTROL);
 	writel(0, gt_base + GT_COUNTER0);
@@ -249,7 +249,7 @@ static void __init gt_clocksource_init(void)
 #ifdef CONFIG_CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK
 	sched_clock_register(gt_sched_clock_read, 64, gt_clk_rate);
 #endif
-	clocksource_register_hz(&gt_clocksource, gt_clk_rate);
+	return clocksource_register_hz(&gt_clocksource, gt_clk_rate);
 }
 
 static int gt_cpu_notify(struct notifier_block *self, unsigned long action,
@@ -270,7 +270,7 @@ static struct notifier_block gt_cpu_nb = {
 	.notifier_call = gt_cpu_notify,
 };
 
-static void __init global_timer_of_register(struct device_node *np)
+static int __init global_timer_of_register(struct device_node *np)
 {
 	struct clk *gt_clk;
 	int err = 0;
@@ -283,19 +283,19 @@ static void __init global_timer_of_register(struct device_node *np)
 	if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9
 	    && (read_cpuid_id() & 0xf0000f) < 0x200000) {
 		pr_warn("global-timer: non support for this cpu version.\n");
-		return;
+		return -ENOSYS;
 	}
 
 	gt_ppi = irq_of_parse_and_map(np, 0);
 	if (!gt_ppi) {
 		pr_warn("global-timer: unable to parse irq\n");
-		return;
+		return -EINVAL;
 	}
 
 	gt_base = of_iomap(np, 0);
 	if (!gt_base) {
 		pr_warn("global-timer: invalid base address\n");
-		return;
+		return -ENXIO;
 	}
 
 	gt_clk = of_clk_get(np, 0);
@@ -332,11 +332,17 @@ static void __init global_timer_of_register(struct device_node *np)
 	}
 
 	/* Immediately configure the timer on the boot CPU */
-	gt_clocksource_init();
-	gt_clockevents_init(this_cpu_ptr(gt_evt));
+	err = gt_clocksource_init();
+	if (err)
+		goto out_irq;
+	
+	err = gt_clockevents_init(this_cpu_ptr(gt_evt));
+	if (err)
+		goto out_irq;
+
 	gt_delay_timer_init();
 
-	return;
+	return 0;
 
 out_irq:
 	free_percpu_irq(gt_ppi, gt_evt);
@@ -347,8 +353,10 @@ out_clk:
 out_unmap:
 	iounmap(gt_base);
 	WARN(err, "ARM Global timer register failed (%d)\n", err);
+
+	return err;
 }
 
 /* Only tested on r2p2 and r3p0  */
-CLOCKSOURCE_OF_DECLARE(arm_gt, "arm,cortex-a9-global-timer",
+CLOCKSOURCE_OF_DECLARE_RET(arm_gt, "arm,cortex-a9-global-timer",
 			global_timer_of_register);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 19/63] clocksource/drivers/h8300_timer16: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (17 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 18/63] clocksource/drivers/arm_global_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 20/63] clocksource/drivers/h8300_tpu: " Daniel Lezcano
                   ` (43 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Yoshinori Sato, moderated list:H8/300 ARCHITECTURE

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/h8300_timer16.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/clocksource/h8300_timer16.c b/drivers/clocksource/h8300_timer16.c
index 75c4407..9d99fc8 100644
--- a/drivers/clocksource/h8300_timer16.c
+++ b/drivers/clocksource/h8300_timer16.c
@@ -126,7 +126,7 @@ static struct timer16_priv timer16_priv = {
 #define REG_CH   0
 #define REG_COMM 1
 
-static void __init h8300_16timer_init(struct device_node *node)
+static int __init h8300_16timer_init(struct device_node *node)
 {
 	void __iomem *base[2];
 	int ret, irq;
@@ -136,9 +136,10 @@ static void __init h8300_16timer_init(struct device_node *node)
 	clk = of_clk_get(node, 0);
 	if (IS_ERR(clk)) {
 		pr_err("failed to get clock for clocksource\n");
-		return;
+		return PTR_ERR(clk);
 	}
 
+	ret = -ENXIO;
 	base[REG_CH] = of_iomap(node, 0);
 	if (!base[REG_CH]) {
 		pr_err("failed to map registers for clocksource\n");
@@ -151,6 +152,7 @@ static void __init h8300_16timer_init(struct device_node *node)
 		goto unmap_ch;
 	}
 
+	ret = -EINVAL;
 	irq = irq_of_parse_and_map(node, 0);
 	if (!irq) {
 		pr_err("failed to get irq for clockevent\n");
@@ -174,7 +176,7 @@ static void __init h8300_16timer_init(struct device_node *node)
 
 	clocksource_register_hz(&timer16_priv.cs,
 				clk_get_rate(clk) / 8);
-	return;
+	return 0;
 
 unmap_comm:
 	iounmap(base[REG_COMM]);
@@ -182,6 +184,8 @@ unmap_ch:
 	iounmap(base[REG_CH]);
 free_clk:
 	clk_put(clk);
+	return ret;
 }
 
-CLOCKSOURCE_OF_DECLARE(h8300_16bit, "renesas,16bit-timer", h8300_16timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(h8300_16bit, "renesas,16bit-timer",
+			   h8300_16timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 20/63] clocksource/drivers/h8300_tpu: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (18 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 19/63] clocksource/drivers/h8300_timer16: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 21/63] " Daniel Lezcano
                   ` (42 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Yoshinori Sato, moderated list:H8/300 ARCHITECTURE

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/h8300_timer8.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/h8300_timer8.c b/drivers/clocksource/h8300_timer8.c
index c151941..0292a19 100644
--- a/drivers/clocksource/h8300_timer8.c
+++ b/drivers/clocksource/h8300_timer8.c
@@ -164,24 +164,26 @@ static struct timer8_priv timer8_priv = {
 	},
 };
 
-static void __init h8300_8timer_init(struct device_node *node)
+static int __init h8300_8timer_init(struct device_node *node)
 {
 	void __iomem *base;
-	int irq;
+	int irq, ret;
 	struct clk *clk;
 
 	clk = of_clk_get(node, 0);
 	if (IS_ERR(clk)) {
 		pr_err("failed to get clock for clockevent\n");
-		return;
+		return PTR_ERR(clk);
 	}
 
+	ret = ENXIO;
 	base = of_iomap(node, 0);
 	if (!base) {
 		pr_err("failed to map registers for clockevent\n");
 		goto free_clk;
 	}
 
+	ret = -EINVAL;
 	irq = irq_of_parse_and_map(node, 0);
 	if (!irq) {
 		pr_err("failed to get irq for clockevent\n");
@@ -205,11 +207,12 @@ static void __init h8300_8timer_init(struct device_node *node)
 	clockevents_config_and_register(&timer8_priv.ced,
 					timer8_priv.rate, 1, 0x0000ffff);
 
-	return;
+	return 0;
 unmap_reg:
 	iounmap(base);
 free_clk:
 	clk_put(clk);
+	return ret;
 }
 
-CLOCKSOURCE_OF_DECLARE(h8300_8bit, "renesas,8bit-timer", h8300_8timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(h8300_8bit, "renesas,8bit-timer", h8300_8timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 21/63] clocksource/drivers/h8300_tpu: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (19 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 20/63] clocksource/drivers/h8300_tpu: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 22/63] clocksource/drivers/mips-gic-timer: " Daniel Lezcano
                   ` (41 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Yoshinori Sato, moderated list:H8/300 ARCHITECTURE

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/h8300_tpu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/clocksource/h8300_tpu.c b/drivers/clocksource/h8300_tpu.c
index d4c1a28..4faf718 100644
--- a/drivers/clocksource/h8300_tpu.c
+++ b/drivers/clocksource/h8300_tpu.c
@@ -119,15 +119,16 @@ static struct tpu_priv tpu_priv = {
 #define CH_L 0
 #define CH_H 1
 
-static void __init h8300_tpu_init(struct device_node *node)
+static int __init h8300_tpu_init(struct device_node *node)
 {
 	void __iomem *base[2];
 	struct clk *clk;
+	int ret = -ENXIO;
 
 	clk = of_clk_get(node, 0);
 	if (IS_ERR(clk)) {
 		pr_err("failed to get clock for clocksource\n");
-		return;
+		return PTR_ERR(clk);
 	}
 
 	base[CH_L] = of_iomap(node, CH_L);
@@ -144,14 +145,13 @@ static void __init h8300_tpu_init(struct device_node *node)
 	tpu_priv.mapbase1 = base[CH_L];
 	tpu_priv.mapbase2 = base[CH_H];
 
-	clocksource_register_hz(&tpu_priv.cs, clk_get_rate(clk) / 64);
-
-	return;
+	return clocksource_register_hz(&tpu_priv.cs, clk_get_rate(clk) / 64);
 
 unmap_L:
 	iounmap(base[CH_H]);
 free_clk:
 	clk_put(clk);
+	return ret;
 }
 
-CLOCKSOURCE_OF_DECLARE(h8300_tpu, "renesas,tpu", h8300_tpu_init);
+CLOCKSOURCE_OF_DECLARE_RET(h8300_tpu, "renesas,tpu", h8300_tpu_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 22/63] clocksource/drivers/mips-gic-timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (20 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 21/63] " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 23/63] clocksource/drivers/moxart_timer: " Daniel Lezcano
                   ` (40 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Carlo Caione, Kevin Hilman,
	moderated list:ARM/Amlogic Meson...,
	open list:ARM/Amlogic Meson...

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/meson6_timer.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/clocksource/meson6_timer.c b/drivers/clocksource/meson6_timer.c
index 1fa22c4..3a6e78f 100644
--- a/drivers/clocksource/meson6_timer.c
+++ b/drivers/clocksource/meson6_timer.c
@@ -126,18 +126,22 @@ static struct irqaction meson6_timer_irq = {
 	.dev_id		= &meson6_clockevent,
 };
 
-static void __init meson6_timer_init(struct device_node *node)
+static int __init meson6_timer_init(struct device_node *node)
 {
 	u32 val;
 	int ret, irq;
 
 	timer_base = of_io_request_and_map(node, 0, "meson6-timer");
-	if (IS_ERR(timer_base))
-		panic("Can't map registers");
+	if (IS_ERR(timer_base)) {
+		pr_err("Can't map registers");
+		return -ENXIO;
+	}
 
 	irq = irq_of_parse_and_map(node, 0);
-	if (irq <= 0)
-		panic("Can't parse IRQ");
+	if (irq <= 0) {
+		pr_err("Can't parse IRQ");
+		return -EINVAL;
+	}
 
 	/* Set 1us for timer E */
 	val = readl(timer_base + TIMER_ISA_MUX);
@@ -158,14 +162,17 @@ static void __init meson6_timer_init(struct device_node *node)
 	meson6_clkevt_time_stop(CED_ID);
 
 	ret = setup_irq(irq, &meson6_timer_irq);
-	if (ret)
+	if (ret) {
 		pr_warn("failed to setup irq %d\n", irq);
+		return ret;
+	}
 
 	meson6_clockevent.cpumask = cpu_possible_mask;
 	meson6_clockevent.irq = irq;
 
 	clockevents_config_and_register(&meson6_clockevent, USEC_PER_SEC,
 					1, 0xfffe);
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(meson6, "amlogic,meson6-timer",
+CLOCKSOURCE_OF_DECLARE_RET(meson6, "amlogic,meson6-timer",
 		       meson6_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 23/63] clocksource/drivers/moxart_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (21 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 22/63] clocksource/drivers/mips-gic-timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 24/63] clocksource/drivers/mps2-timer: " Daniel Lezcano
                   ` (39 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/mips-gic-timer.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/clocksource/mips-gic-timer.c b/drivers/clocksource/mips-gic-timer.c
index 89d3e4d..b164b87 100644
--- a/drivers/clocksource/mips-gic-timer.c
+++ b/drivers/clocksource/mips-gic-timer.c
@@ -146,7 +146,7 @@ static struct clocksource gic_clocksource = {
 	.archdata	= { .vdso_clock_mode = VDSO_CLOCK_GIC },
 };
 
-static void __init __gic_clocksource_init(void)
+static int __init __gic_clocksource_init(void)
 {
 	int ret;
 
@@ -159,6 +159,8 @@ static void __init __gic_clocksource_init(void)
 	ret = clocksource_register_hz(&gic_clocksource, gic_frequency);
 	if (ret < 0)
 		pr_warn("GIC: Unable to register clocksource\n");
+
+	return ret;
 }
 
 void __init gic_clocksource_init(unsigned int frequency)
@@ -179,31 +181,35 @@ static void __init gic_clocksource_of_init(struct device_node *node)
 	struct clk *clk;
 	int ret;
 
-	if (WARN_ON(!gic_present || !node->parent ||
-		    !of_device_is_compatible(node->parent, "mti,gic")))
-		return;
+	if (!gic_present || !node->parent ||
+	    !of_device_is_compatible(node->parent, "mti,gic")) {
+		pr_warn("No DT definition for the mips gic driver");
+		return -ENXIO;
+	}
 
 	clk = of_clk_get(node, 0);
 	if (!IS_ERR(clk)) {
 		if (clk_prepare_enable(clk) < 0) {
 			pr_err("GIC failed to enable clock\n");
 			clk_put(clk);
-			return;
+			return PTR_ERR(clk);
 		}
 
 		gic_frequency = clk_get_rate(clk);
 	} else if (of_property_read_u32(node, "clock-frequency",
 					&gic_frequency)) {
 		pr_err("GIC frequency not specified.\n");
-		return;
+		return -EINVAL;;
 	}
 	gic_timer_irq = irq_of_parse_and_map(node, 0);
 	if (!gic_timer_irq) {
 		pr_err("GIC timer IRQ not specified.\n");
-		return;
+		return -EINVAL;;
 	}
 
-	__gic_clocksource_init();
+	ret = __gic_clocksource_init();
+	if (ret)
+		return ret;
 
 	ret = gic_clockevent_init();
 	if (!ret && !IS_ERR(clk)) {
@@ -213,6 +219,8 @@ static void __init gic_clocksource_of_init(struct device_node *node)
 
 	/* And finally start the counter */
 	gic_start_count();
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(mips_gic_timer, "mti,gic-timer",
+CLOCKSOURCE_OF_DECLARE_RET(mips_gic_timer, "mti,gic-timer",
 		       gic_clocksource_of_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 24/63] clocksource/drivers/mps2-timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (22 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 23/63] clocksource/drivers/moxart_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 25/63] clocksource/drivers/mxs_timer: " Daniel Lezcano
                   ` (38 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/moxart_timer.c | 41 +++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/drivers/clocksource/moxart_timer.c b/drivers/clocksource/moxart_timer.c
index 19857af..b9c30cd 100644
--- a/drivers/clocksource/moxart_timer.c
+++ b/drivers/clocksource/moxart_timer.c
@@ -119,34 +119,45 @@ static struct irqaction moxart_timer_irq = {
 	.dev_id		= &moxart_clockevent,
 };
 
-static void __init moxart_timer_init(struct device_node *node)
+static int __init moxart_timer_init(struct device_node *node)
 {
 	int ret, irq;
 	unsigned long pclk;
 	struct clk *clk;
 
 	base = of_iomap(node, 0);
-	if (!base)
-		panic("%s: of_iomap failed\n", node->full_name);
+	if (!base) {
+		pr_err("%s: of_iomap failed\n", node->full_name);
+		return -ENXIO;
+	}
 
 	irq = irq_of_parse_and_map(node, 0);
-	if (irq <= 0)
-		panic("%s: irq_of_parse_and_map failed\n", node->full_name);
+	if (irq <= 0) {
+		pr_err("%s: irq_of_parse_and_map failed\n", node->full_name);
+		return -EINVAL;
+	}
 
 	ret = setup_irq(irq, &moxart_timer_irq);
-	if (ret)
-		panic("%s: setup_irq failed\n", node->full_name);
+	if (ret) {
+		pr_err("%s: setup_irq failed\n", node->full_name);
+		return ret;
+	}
 
 	clk = of_clk_get(node, 0);
-	if (IS_ERR(clk))
-		panic("%s: of_clk_get failed\n", node->full_name);
+	if (IS_ERR(clk))  {
+		pr_err("%s: of_clk_get failed\n", node->full_name);
+		return PTR_ERR(clk);
+	}
 
 	pclk = clk_get_rate(clk);
 
-	if (clocksource_mmio_init(base + TIMER2_BASE + REG_COUNT,
-				  "moxart_timer", pclk, 200, 32,
-				  clocksource_mmio_readl_down))
-		panic("%s: clocksource_mmio_init failed\n", node->full_name);
+	ret = clocksource_mmio_init(base + TIMER2_BASE + REG_COUNT,
+				    "moxart_timer", pclk, 200, 32,
+				    clocksource_mmio_readl_down);
+	if (ret) {
+		pr_err("%s: clocksource_mmio_init failed\n", node->full_name);
+		return ret;
+	}
 
 	clock_count_per_tick = DIV_ROUND_CLOSEST(pclk, HZ);
 
@@ -164,5 +175,7 @@ static void __init moxart_timer_init(struct device_node *node)
 	 */
 	clockevents_config_and_register(&moxart_clockevent, pclk,
 					0x4, 0xfffffffe);
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(moxart, "moxa,moxart-timer", moxart_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(moxart, "moxa,moxart-timer", moxart_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 25/63] clocksource/drivers/mxs_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (23 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 24/63] clocksource/drivers/mps2-timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-17  6:33   ` Uwe Kleine-König
  2016-06-20  9:15   ` [PATCH V2 25/63] clocksource/drivers/mxs_timer: " Liviu Dudau
  2016-06-16 21:26 ` [PATCH V2 26/63] clocksource/drivers/nomadik-mtu: " Daniel Lezcano
                   ` (37 subsequent siblings)
  62 siblings, 2 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Liviu Dudau, Sudeep Holla, Lorenzo Pieralisi,
	moderated list:ARM/VERSATILE EXP...

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/mps2-timer.c | 10 ++++++----
 drivers/clocksource/mxs_timer.c  |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/mps2-timer.c b/drivers/clocksource/mps2-timer.c
index 3d33a5e..c303fa9 100644
--- a/drivers/clocksource/mps2-timer.c
+++ b/drivers/clocksource/mps2-timer.c
@@ -250,7 +250,7 @@ out:
 	return ret;
 }
 
-static void __init mps2_timer_init(struct device_node *np)
+static int __init mps2_timer_init(struct device_node *np)
 {
 	static int has_clocksource, has_clockevent;
 	int ret;
@@ -259,7 +259,7 @@ static void __init mps2_timer_init(struct device_node *np)
 		ret = mps2_clocksource_init(np);
 		if (!ret) {
 			has_clocksource = 1;
-			return;
+			return 0;
 		}
 	}
 
@@ -267,9 +267,11 @@ static void __init mps2_timer_init(struct device_node *np)
 		ret = mps2_clockevent_init(np);
 		if (!ret) {
 			has_clockevent = 1;
-			return;
+			return 0;
 		}
 	}
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(mps2_timer, "arm,mps2-timer", mps2_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(mps2_timer, "arm,mps2-timer", mps2_timer_init);
diff --git a/drivers/clocksource/mxs_timer.c b/drivers/clocksource/mxs_timer.c
index f5ce296..16cf53b 100644
--- a/drivers/clocksource/mxs_timer.c
+++ b/drivers/clocksource/mxs_timer.c
@@ -226,7 +226,7 @@ static int __init mxs_clocksource_init(struct clk *timer_clk)
 	return 0;
 }
 
-static void __init mxs_timer_init(struct device_node *np)
+static int __init mxs_timer_init(struct device_node *np)
 {
 	struct clk *timer_clk;
 	int irq;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 26/63] clocksource/drivers/nomadik-mtu: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (24 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 25/63] clocksource/drivers/mxs_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 27/63] clocksource/drivers/pxa_timer: " Daniel Lezcano
                   ` (36 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/mxs_timer.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/clocksource/mxs_timer.c b/drivers/clocksource/mxs_timer.c
index 16cf53b..17b9d19 100644
--- a/drivers/clocksource/mxs_timer.c
+++ b/drivers/clocksource/mxs_timer.c
@@ -229,7 +229,7 @@ static int __init mxs_clocksource_init(struct clk *timer_clk)
 static int __init mxs_timer_init(struct device_node *np)
 {
 	struct clk *timer_clk;
-	int irq;
+	int irq, ret;
 
 	mxs_timrot_base = of_iomap(np, 0);
 	WARN_ON(!mxs_timrot_base);
@@ -237,10 +237,12 @@ static int __init mxs_timer_init(struct device_node *np)
 	timer_clk = of_clk_get(np, 0);
 	if (IS_ERR(timer_clk)) {
 		pr_err("%s: failed to get clk\n", __func__);
-		return;
+		return PTR_ERR(timer_clk);
 	}
 
-	clk_prepare_enable(timer_clk);
+	ret = clk_prepare_enable(timer_clk);
+	if (ret)
+		return ret;
 
 	/*
 	 * Initialize timers to a known state
@@ -278,11 +280,19 @@ static int __init mxs_timer_init(struct device_node *np)
 			mxs_timrot_base + HW_TIMROT_FIXED_COUNTn(1));
 
 	/* init and register the timer to the framework */
-	mxs_clocksource_init(timer_clk);
-	mxs_clockevent_init(timer_clk);
+	ret = mxs_clocksource_init(timer_clk);
+	if (ret)
+		return ret;
+
+	ret = mxs_clockevent_init(timer_clk);
+	if (ret)
+		return ret;
 
 	/* Make irqs happen */
 	irq = irq_of_parse_and_map(np, 0);
-	setup_irq(irq, &mxs_timer_irq);
+	if (irq <= 0)
+		return -EINVAL;
+
+	return setup_irq(irq, &mxs_timer_irq);
 }
-CLOCKSOURCE_OF_DECLARE(mxs, "fsl,timrot", mxs_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(mxs, "fsl,timrot", mxs_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 27/63] clocksource/drivers/pxa_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (25 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 26/63] clocksource/drivers/nomadik-mtu: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 28/63] clocksource/drivers/qcom-timer: " Daniel Lezcano
                   ` (35 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/nomadik-mtu.c | 45 +++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/drivers/clocksource/nomadik-mtu.c b/drivers/clocksource/nomadik-mtu.c
index bc8dd44..d2be5b3 100644
--- a/drivers/clocksource/nomadik-mtu.c
+++ b/drivers/clocksource/nomadik-mtu.c
@@ -193,10 +193,11 @@ static struct irqaction nmdk_timer_irq = {
 	.dev_id		= &nmdk_clkevt,
 };
 
-static void __init nmdk_timer_init(void __iomem *base, int irq,
+static int __init nmdk_timer_init(void __iomem *base, int irq,
 				   struct clk *pclk, struct clk *clk)
 {
 	unsigned long rate;
+	int ret;
 
 	mtu_base = base;
 
@@ -226,10 +227,12 @@ static void __init nmdk_timer_init(void __iomem *base, int irq,
 	/* Timer 0 is the free running clocksource */
 	nmdk_clksrc_reset();
 
-	if (clocksource_mmio_init(mtu_base + MTU_VAL(0), "mtu_0",
-			rate, 200, 32, clocksource_mmio_readl_down))
-		pr_err("timer: failed to initialize clock source %s\n",
-		       "mtu_0");
+	ret = clocksource_mmio_init(mtu_base + MTU_VAL(0), "mtu_0",
+				    rate, 200, 32, clocksource_mmio_readl_down);
+	if (ret) {
+		pr_err("timer: failed to initialize clock source %s\n", "mtu_0");
+		return ret;
+	}
 
 #ifdef CONFIG_CLKSRC_NOMADIK_MTU_SCHED_CLOCK
 	sched_clock_register(nomadik_read_sched_clock, 32, rate);
@@ -244,9 +247,11 @@ static void __init nmdk_timer_init(void __iomem *base, int irq,
 	mtu_delay_timer.read_current_timer = &nmdk_timer_read_current_timer;
 	mtu_delay_timer.freq = rate;
 	register_current_timer_delay(&mtu_delay_timer);
+
+	return 0;
 }
 
-static void __init nmdk_timer_of_init(struct device_node *node)
+static int __init nmdk_timer_of_init(struct device_node *node)
 {
 	struct clk *pclk;
 	struct clk *clk;
@@ -254,22 +259,30 @@ static void __init nmdk_timer_of_init(struct device_node *node)
 	int irq;
 
 	base = of_iomap(node, 0);
-	if (!base)
-		panic("Can't remap registers");
+	if (!base) {
+		pr_err("Can't remap registers");
+		return -ENXIO;
+	}
 
 	pclk = of_clk_get_by_name(node, "apb_pclk");
-	if (IS_ERR(pclk))
-		panic("could not get apb_pclk");
+	if (IS_ERR(pclk)) {
+		pr_err("could not get apb_pclk");
+		return PTR_ERR(pclk);
+	}
 
 	clk = of_clk_get_by_name(node, "timclk");
-	if (IS_ERR(clk))
-		panic("could not get timclk");
+	if (IS_ERR(clk)) {
+		pr_err("could not get timclk");
+		return PTR_ERR(clk);
+	}
 
 	irq = irq_of_parse_and_map(node, 0);
-	if (irq <= 0)
-		panic("Can't parse IRQ");
+	if (irq <= 0) {
+		pr_err("Can't parse IRQ");
+		return -EINVAL;
+	}
 
-	nmdk_timer_init(base, irq, pclk, clk);
+	return nmdk_timer_init(base, irq, pclk, clk);
 }
-CLOCKSOURCE_OF_DECLARE(nomadik_mtu, "st,nomadik-mtu",
+CLOCKSOURCE_OF_DECLARE_RET(nomadik_mtu, "st,nomadik-mtu",
 		       nmdk_timer_of_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 28/63] clocksource/drivers/qcom-timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (26 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 27/63] clocksource/drivers/pxa_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 29/63] clocksource/drivers/samsung_pwm_timer: " Daniel Lezcano
                   ` (34 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/pxa_timer.c | 46 +++++++++++++++++++++++++++++------------
 1 file changed, 33 insertions(+), 13 deletions(-)

diff --git a/drivers/clocksource/pxa_timer.c b/drivers/clocksource/pxa_timer.c
index 45b6a49..59af75c 100644
--- a/drivers/clocksource/pxa_timer.c
+++ b/drivers/clocksource/pxa_timer.c
@@ -150,8 +150,10 @@ static struct irqaction pxa_ost0_irq = {
 	.dev_id		= &ckevt_pxa_osmr0,
 };
 
-static void __init pxa_timer_common_init(int irq, unsigned long clock_tick_rate)
+static int __init pxa_timer_common_init(int irq, unsigned long clock_tick_rate)
 {
+	int ret;
+
 	timer_writel(0, OIER);
 	timer_writel(OSSR_M0 | OSSR_M1 | OSSR_M2 | OSSR_M3, OSSR);
 
@@ -159,41 +161,59 @@ static void __init pxa_timer_common_init(int irq, unsigned long clock_tick_rate)
 
 	ckevt_pxa_osmr0.cpumask = cpumask_of(0);
 
-	setup_irq(irq, &pxa_ost0_irq);
+	ret = setup_irq(irq, &pxa_ost0_irq);
+	if (ret) {
+		pr_err("Failed to setup irq");
+		return ret;
+	}
+
+	ret = clocksource_mmio_init(timer_base + OSCR, "oscr0", clock_tick_rate, 200,
+				    32, clocksource_mmio_readl_up);
+	if (ret) {
+		pr_err("Failed to init clocksource");
+		return ret;
+	}
 
-	clocksource_mmio_init(timer_base + OSCR, "oscr0", clock_tick_rate, 200,
-			      32, clocksource_mmio_readl_up);
 	clockevents_config_and_register(&ckevt_pxa_osmr0, clock_tick_rate,
 					MIN_OSCR_DELTA * 2, 0x7fffffff);
+
+	return 0;
 }
 
-static void __init pxa_timer_dt_init(struct device_node *np)
+static int __init pxa_timer_dt_init(struct device_node *np)
 {
 	struct clk *clk;
-	int irq;
+	int irq, ret;
 
 	/* timer registers are shared with watchdog timer */
 	timer_base = of_iomap(np, 0);
-	if (!timer_base)
-		panic("%s: unable to map resource\n", np->name);
+	if (!timer_base) {
+		pr_err("%s: unable to map resource\n", np->name);
+		return -ENXIO;
+	}
 
 	clk = of_clk_get(np, 0);
 	if (IS_ERR(clk)) {
 		pr_crit("%s: unable to get clk\n", np->name);
-		return;
+		return PTR_ERR(clk);
+	}
+
+	ret = clk_prepare_enable(clk);
+	if (ret) {
+		pr_crit("Failed to prepare clock");
+		return ret;
 	}
-	clk_prepare_enable(clk);
 
 	/* we are only interested in OS-timer0 irq */
 	irq = irq_of_parse_and_map(np, 0);
 	if (irq <= 0) {
 		pr_crit("%s: unable to parse OS-timer0 irq\n", np->name);
-		return;
+		return -EINVAL;
 	}
 
-	pxa_timer_common_init(irq, clk_get_rate(clk));
+	return pxa_timer_common_init(irq, clk_get_rate(clk));
 }
-CLOCKSOURCE_OF_DECLARE(pxa_timer, "marvell,pxa-timer", pxa_timer_dt_init);
+CLOCKSOURCE_OF_DECLARE_RET(pxa_timer, "marvell,pxa-timer", pxa_timer_dt_init);
 
 /*
  * Legacy timer init for non device-tree boards.
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 29/63] clocksource/drivers/samsung_pwm_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (27 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 28/63] clocksource/drivers/qcom-timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 30/63] clocksource/drivers/sun4i_time: " Daniel Lezcano
                   ` (33 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/qcom-timer.c        | 27 +++++++++++++++------------
 drivers/clocksource/samsung_pwm_timer.c |  2 +-
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/clocksource/qcom-timer.c b/drivers/clocksource/qcom-timer.c
index f8e09f9..79f73bd 100644
--- a/drivers/clocksource/qcom-timer.c
+++ b/drivers/clocksource/qcom-timer.c
@@ -178,7 +178,7 @@ static struct delay_timer msm_delay_timer = {
 	.read_current_timer = msm_read_current_timer,
 };
 
-static void __init msm_timer_init(u32 dgt_hz, int sched_bits, int irq,
+static int __init msm_timer_init(u32 dgt_hz, int sched_bits, int irq,
 				  bool percpu)
 {
 	struct clocksource *cs = &msm_clocksource;
@@ -218,12 +218,14 @@ err:
 	sched_clock_register(msm_sched_clock_read, sched_bits, dgt_hz);
 	msm_delay_timer.freq = dgt_hz;
 	register_current_timer_delay(&msm_delay_timer);
+
+	return res;
 }
 
-static void __init msm_dt_timer_init(struct device_node *np)
+static int __init msm_dt_timer_init(struct device_node *np)
 {
 	u32 freq;
-	int irq;
+	int irq, ret;
 	struct resource res;
 	u32 percpu_offset;
 	void __iomem *base;
@@ -232,34 +234,35 @@ static void __init msm_dt_timer_init(struct device_node *np)
 	base = of_iomap(np, 0);
 	if (!base) {
 		pr_err("Failed to map event base\n");
-		return;
+		return -ENXIO;
 	}
 
 	/* We use GPT0 for the clockevent */
 	irq = irq_of_parse_and_map(np, 1);
 	if (irq <= 0) {
 		pr_err("Can't get irq\n");
-		return;
+		return -EINVAL;
 	}
 
 	/* We use CPU0's DGT for the clocksource */
 	if (of_property_read_u32(np, "cpu-offset", &percpu_offset))
 		percpu_offset = 0;
 
-	if (of_address_to_resource(np, 0, &res)) {
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret) {
 		pr_err("Failed to parse DGT resource\n");
-		return;
+		return ret;
 	}
 
 	cpu0_base = ioremap(res.start + percpu_offset, resource_size(&res));
 	if (!cpu0_base) {
 		pr_err("Failed to map source base\n");
-		return;
+		return -EINVAL;
 	}
 
 	if (of_property_read_u32(np, "clock-frequency", &freq)) {
 		pr_err("Unknown frequency\n");
-		return;
+		return -EINVAL;
 	}
 
 	event_base = base + 0x4;
@@ -268,7 +271,7 @@ static void __init msm_dt_timer_init(struct device_node *np)
 	freq /= 4;
 	writel_relaxed(DGT_CLK_CTL_DIV_4, source_base + DGT_CLK_CTL);
 
-	msm_timer_init(freq, 32, irq, !!percpu_offset);
+	return msm_timer_init(freq, 32, irq, !!percpu_offset);
 }
-CLOCKSOURCE_OF_DECLARE(kpss_timer, "qcom,kpss-timer", msm_dt_timer_init);
-CLOCKSOURCE_OF_DECLARE(scss_timer, "qcom,scss-timer", msm_dt_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(kpss_timer, "qcom,kpss-timer", msm_dt_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(scss_timer, "qcom,scss-timer", msm_dt_timer_init);
diff --git a/drivers/clocksource/samsung_pwm_timer.c b/drivers/clocksource/samsung_pwm_timer.c
index 47e0515..503a2f7 100644
--- a/drivers/clocksource/samsung_pwm_timer.c
+++ b/drivers/clocksource/samsung_pwm_timer.c
@@ -499,7 +499,7 @@ static const struct samsung_pwm_variant s5p_variant = {
 
 static void __init s5p_pwm_clocksource_init(struct device_node *np)
 {
-	samsung_pwm_alloc(np, &s5p_variant);
+	return samsung_pwm_alloc(np, &s5p_variant);
 }
 CLOCKSOURCE_OF_DECLARE(s5pc100_pwm, "samsung,s5pc100-pwm", s5p_pwm_clocksource_init);
 #endif
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 30/63] clocksource/drivers/sun4i_time: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (28 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 29/63] clocksource/drivers/samsung_pwm_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 31/63] clocksource/drivers/tango_xtal: " Daniel Lezcano
                   ` (32 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/samsung_pwm_timer.c | 60 ++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/drivers/clocksource/samsung_pwm_timer.c b/drivers/clocksource/samsung_pwm_timer.c
index 503a2f7..27a9797 100644
--- a/drivers/clocksource/samsung_pwm_timer.c
+++ b/drivers/clocksource/samsung_pwm_timer.c
@@ -333,11 +333,10 @@ static u64 notrace samsung_read_sched_clock(void)
 	return samsung_clocksource_read(NULL);
 }
 
-static void __init samsung_clocksource_init(void)
+static int __init samsung_clocksource_init(void)
 {
 	unsigned long pclk;
 	unsigned long clock_rate;
-	int ret;
 
 	pclk = clk_get_rate(pwm.timerclk);
 
@@ -358,9 +357,7 @@ static void __init samsung_clocksource_init(void)
 						pwm.variant.bits, clock_rate);
 
 	samsung_clocksource.mask = CLOCKSOURCE_MASK(pwm.variant.bits);
-	ret = clocksource_register_hz(&samsung_clocksource, clock_rate);
-	if (ret)
-		panic("samsung_clocksource_timer: can't register clocksource\n");
+	return clocksource_register_hz(&samsung_clocksource, clock_rate);
 }
 
 static void __init samsung_timer_resources(void)
@@ -380,26 +377,31 @@ static void __init samsung_timer_resources(void)
 /*
  * PWM master driver
  */
-static void __init _samsung_pwm_clocksource_init(void)
+static int __init _samsung_pwm_clocksource_init(void)
 {
 	u8 mask;
 	int channel;
 
 	mask = ~pwm.variant.output_mask & ((1 << SAMSUNG_PWM_NUM) - 1);
 	channel = fls(mask) - 1;
-	if (channel < 0)
-		panic("failed to find PWM channel for clocksource");
+	if (channel < 0) {
+		pr_crit("failed to find PWM channel for clocksource");
+		return -EINVAL;
+	}
 	pwm.source_id = channel;
 
 	mask &= ~(1 << channel);
 	channel = fls(mask) - 1;
-	if (channel < 0)
-		panic("failed to find PWM channel for clock event");
+	if (channel < 0) {
+		pr_crit("failed to find PWM channel for clock event");
+		return -EINVAL;
+	}
 	pwm.event_id = channel;
 
 	samsung_timer_resources();
 	samsung_clockevent_init();
-	samsung_clocksource_init();
+
+	return samsung_clocksource_init();
 }
 
 void __init samsung_pwm_clocksource_init(void __iomem *base,
@@ -417,8 +419,8 @@ void __init samsung_pwm_clocksource_init(void __iomem *base,
 }
 
 #ifdef CONFIG_CLKSRC_OF
-static void __init samsung_pwm_alloc(struct device_node *np,
-				     const struct samsung_pwm_variant *variant)
+static int __init samsung_pwm_alloc(struct device_node *np,
+				    const struct samsung_pwm_variant *variant)
 {
 	struct property *prop;
 	const __be32 *cur;
@@ -441,14 +443,16 @@ static void __init samsung_pwm_alloc(struct device_node *np,
 	pwm.base = of_iomap(np, 0);
 	if (!pwm.base) {
 		pr_err("%s: failed to map PWM registers\n", __func__);
-		return;
+		return -ENXIO;
 	}
 
 	pwm.timerclk = of_clk_get_by_name(np, "timers");
-	if (IS_ERR(pwm.timerclk))
-		panic("failed to get timers clock for timer");
+	if (IS_ERR(pwm.timerclk)) {
+		pr_crit("failed to get timers clock for timer");
+		return PTR_ERR(pwm.timerclk);
+	}
 
-	_samsung_pwm_clocksource_init();
+	return _samsung_pwm_clocksource_init();
 }
 
 static const struct samsung_pwm_variant s3c24xx_variant = {
@@ -458,11 +462,11 @@ static const struct samsung_pwm_variant s3c24xx_variant = {
 	.tclk_mask	= (1 << 4),
 };
 
-static void __init s3c2410_pwm_clocksource_init(struct device_node *np)
+static int __init s3c2410_pwm_clocksource_init(struct device_node *np)
 {
-	samsung_pwm_alloc(np, &s3c24xx_variant);
+	return samsung_pwm_alloc(np, &s3c24xx_variant);
 }
-CLOCKSOURCE_OF_DECLARE(s3c2410_pwm, "samsung,s3c2410-pwm", s3c2410_pwm_clocksource_init);
+CLOCKSOURCE_OF_DECLARE_RET(s3c2410_pwm, "samsung,s3c2410-pwm", s3c2410_pwm_clocksource_init);
 
 static const struct samsung_pwm_variant s3c64xx_variant = {
 	.bits		= 32,
@@ -471,11 +475,11 @@ static const struct samsung_pwm_variant s3c64xx_variant = {
 	.tclk_mask	= (1 << 7) | (1 << 6) | (1 << 5),
 };
 
-static void __init s3c64xx_pwm_clocksource_init(struct device_node *np)
+static int __init s3c64xx_pwm_clocksource_init(struct device_node *np)
 {
-	samsung_pwm_alloc(np, &s3c64xx_variant);
+	return samsung_pwm_alloc(np, &s3c64xx_variant);
 }
-CLOCKSOURCE_OF_DECLARE(s3c6400_pwm, "samsung,s3c6400-pwm", s3c64xx_pwm_clocksource_init);
+CLOCKSOURCE_OF_DECLARE_RET(s3c6400_pwm, "samsung,s3c6400-pwm", s3c64xx_pwm_clocksource_init);
 
 static const struct samsung_pwm_variant s5p64x0_variant = {
 	.bits		= 32,
@@ -484,11 +488,11 @@ static const struct samsung_pwm_variant s5p64x0_variant = {
 	.tclk_mask	= 0,
 };
 
-static void __init s5p64x0_pwm_clocksource_init(struct device_node *np)
+static int __init s5p64x0_pwm_clocksource_init(struct device_node *np)
 {
-	samsung_pwm_alloc(np, &s5p64x0_variant);
+	return samsung_pwm_alloc(np, &s5p64x0_variant);
 }
-CLOCKSOURCE_OF_DECLARE(s5p6440_pwm, "samsung,s5p6440-pwm", s5p64x0_pwm_clocksource_init);
+CLOCKSOURCE_OF_DECLARE_RET(s5p6440_pwm, "samsung,s5p6440-pwm", s5p64x0_pwm_clocksource_init);
 
 static const struct samsung_pwm_variant s5p_variant = {
 	.bits		= 32,
@@ -497,9 +501,9 @@ static const struct samsung_pwm_variant s5p_variant = {
 	.tclk_mask	= (1 << 5),
 };
 
-static void __init s5p_pwm_clocksource_init(struct device_node *np)
+static int __init s5p_pwm_clocksource_init(struct device_node *np)
 {
 	return samsung_pwm_alloc(np, &s5p_variant);
 }
-CLOCKSOURCE_OF_DECLARE(s5pc100_pwm, "samsung,s5pc100-pwm", s5p_pwm_clocksource_init);
+CLOCKSOURCE_OF_DECLARE_RET(s5pc100_pwm, "samsung,s5pc100-pwm", s5p_pwm_clocksource_init);
 #endif
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 31/63] clocksource/drivers/tango_xtal: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (29 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 30/63] clocksource/drivers/sun4i_time: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-17  9:19   ` Mason
  2016-06-16 21:26 ` [PATCH V2 32/63] clocksource/drivers/tegra20_timer: " Daniel Lezcano
                   ` (31 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Maxime Ripard, Chen-Yu Tsai,
	moderated list:ARM/Allwinner sun...

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/sun4i_timer.c | 45 ++++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/drivers/clocksource/sun4i_timer.c b/drivers/clocksource/sun4i_timer.c
index 6f3719d..4453730 100644
--- a/drivers/clocksource/sun4i_timer.c
+++ b/drivers/clocksource/sun4i_timer.c
@@ -146,7 +146,7 @@ static u64 notrace sun4i_timer_sched_read(void)
 	return ~readl(timer_base + TIMER_CNTVAL_REG(1));
 }
 
-static void __init sun4i_timer_init(struct device_node *node)
+static int __init sun4i_timer_init(struct device_node *node)
 {
 	unsigned long rate = 0;
 	struct clk *clk;
@@ -154,17 +154,28 @@ static void __init sun4i_timer_init(struct device_node *node)
 	u32 val;
 
 	timer_base = of_iomap(node, 0);
-	if (!timer_base)
-		panic("Can't map registers");
+	if (!timer_base) {
+		pr_crit("Can't map registers");
+		return -ENXIO;
+	}
 
 	irq = irq_of_parse_and_map(node, 0);
-	if (irq <= 0)
-		panic("Can't parse IRQ");
+	if (irq <= 0) {
+		pr_crit("Can't parse IRQ");
+		return -EINVAL;
+	}
 
 	clk = of_clk_get(node, 0);
-	if (IS_ERR(clk))
-		panic("Can't get timer clock");
-	clk_prepare_enable(clk);
+	if (IS_ERR(clk)) {
+		pr_crit("Can't get timer clock");
+		return PTR_ERR(clk);
+	}
+
+	ret = clk_prepare_enable(clk);
+	if (ret) {
+		pr_err("Failed to prepare clock");
+		return ret;
+	}
 
 	rate = clk_get_rate(clk);
 
@@ -182,8 +193,12 @@ static void __init sun4i_timer_init(struct device_node *node)
 	    of_machine_is_compatible("allwinner,sun5i-a10s"))
 		sched_clock_register(sun4i_timer_sched_read, 32, rate);
 
-	clocksource_mmio_init(timer_base + TIMER_CNTVAL_REG(1), node->name,
-			      rate, 350, 32, clocksource_mmio_readl_down);
+	ret = clocksource_mmio_init(timer_base + TIMER_CNTVAL_REG(1), node->name,
+				    rate, 350, 32, clocksource_mmio_readl_down);
+	if (ret) {
+		pr_err("Failed to register clocksource");
+		return ret;
+	}
 
 	ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
 
@@ -200,12 +215,16 @@ static void __init sun4i_timer_init(struct device_node *node)
 					TIMER_SYNC_TICKS, 0xffffffff);
 
 	ret = setup_irq(irq, &sun4i_timer_irq);
-	if (ret)
-		pr_warn("failed to setup irq %d\n", irq);
+	if (ret) {
+		pr_err("failed to setup irq %d\n", irq);
+		return ret;
+	}
 
 	/* Enable timer0 interrupt */
 	val = readl(timer_base + TIMER_IRQ_EN_REG);
 	writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG);
+
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer",
+CLOCKSOURCE_OF_DECLARE_RET(sun4i, "allwinner,sun4i-a10-timer",
 		       sun4i_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 32/63] clocksource/drivers/tegra20_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (30 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 31/63] clocksource/drivers/tango_xtal: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 33/63] clocksource/drivers/time-armada-370-xp: " Daniel Lezcano
                   ` (30 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/tango_xtal.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/tango_xtal.c b/drivers/clocksource/tango_xtal.c
index c407c47..7dc716c 100644
--- a/drivers/clocksource/tango_xtal.c
+++ b/drivers/clocksource/tango_xtal.c
@@ -19,7 +19,7 @@ static u64 notrace read_sched_clock(void)
 	return read_xtal_counter();
 }
 
-static void __init tango_clocksource_init(struct device_node *np)
+static int __init tango_clocksource_init(struct device_node *np)
 {
 	struct clk *clk;
 	int xtal_freq, ret;
@@ -27,13 +27,13 @@ static void __init tango_clocksource_init(struct device_node *np)
 	xtal_in_cnt = of_iomap(np, 0);
 	if (xtal_in_cnt == NULL) {
 		pr_err("%s: invalid address\n", np->full_name);
-		return;
+		return -ENXIO;
 	}
 
 	clk = of_clk_get(np, 0);
 	if (IS_ERR(clk)) {
 		pr_err("%s: invalid clock\n", np->full_name);
-		return;
+		return PTR_ERR(clk);
 	}
 
 	xtal_freq = clk_get_rate(clk);
@@ -44,11 +44,13 @@ static void __init tango_clocksource_init(struct device_node *np)
 				    32, clocksource_mmio_readl_up);
 	if (ret) {
 		pr_err("%s: registration failed\n", np->full_name);
-		return;
+		return ret;
 	}
 
 	sched_clock_register(read_sched_clock, 32, xtal_freq);
 	register_current_timer_delay(&delay_timer);
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init);
+CLOCKSOURCE_OF_DECLARE_RET(tango, "sigma,tick-counter", tango_clocksource_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 33/63] clocksource/drivers/time-armada-370-xp: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (31 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 32/63] clocksource/drivers/tegra20_timer: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-17  7:21   ` Jon Hunter
  2016-06-16 21:26 ` [PATCH V2 34/63] clocksource/drivers/time-efm32: " Daniel Lezcano
                   ` (29 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Stephen Warren, Thierry Reding, Alexandre Courbot,
	open list:TEGRA ARCHITECTUR...

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/tegra20_timer.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/clocksource/tegra20_timer.c b/drivers/clocksource/tegra20_timer.c
index 7b94ad2..543c37e 100644
--- a/drivers/clocksource/tegra20_timer.c
+++ b/drivers/clocksource/tegra20_timer.c
@@ -165,7 +165,7 @@ static struct irqaction tegra_timer_irq = {
 	.dev_id		= &tegra_clockevent,
 };
 
-static void __init tegra20_init_timer(struct device_node *np)
+static int __init tegra20_init_timer(struct device_node *np)
 {
 	struct clk *clk;
 	unsigned long rate;
@@ -174,13 +174,13 @@ static void __init tegra20_init_timer(struct device_node *np)
 	timer_reg_base = of_iomap(np, 0);
 	if (!timer_reg_base) {
 		pr_err("Can't map timer registers\n");
-		BUG();
+		return -ENXIO;
 	}
 
 	tegra_timer_irq.irq = irq_of_parse_and_map(np, 2);
 	if (tegra_timer_irq.irq <= 0) {
 		pr_err("Failed to map timer IRQ\n");
-		BUG();
+		return -EINVAL;
 	}
 
 	clk = of_clk_get(np, 0);
@@ -211,10 +211,12 @@ static void __init tegra20_init_timer(struct device_node *np)
 
 	sched_clock_register(tegra_read_sched_clock, 32, 1000000);
 
-	if (clocksource_mmio_init(timer_reg_base + TIMERUS_CNTR_1US,
-		"timer_us", 1000000, 300, 32, clocksource_mmio_readl_up)) {
+	ret = clocksource_mmio_init(timer_reg_base + TIMERUS_CNTR_1US,
+				    "timer_us", 1000000, 300, 32,
+				    clocksource_mmio_readl_up);
+	if (ret) {
 		pr_err("Failed to register clocksource\n");
-		BUG();
+		return ret;
 	}
 
 	tegra_delay_timer.read_current_timer =
@@ -225,24 +227,26 @@ static void __init tegra20_init_timer(struct device_node *np)
 	ret = setup_irq(tegra_timer_irq.irq, &tegra_timer_irq);
 	if (ret) {
 		pr_err("Failed to register timer IRQ: %d\n", ret);
-		BUG();
+		return ret;
 	}
 
 	tegra_clockevent.cpumask = cpu_all_mask;
 	tegra_clockevent.irq = tegra_timer_irq.irq;
 	clockevents_config_and_register(&tegra_clockevent, 1000000,
 					0x1, 0x1fffffff);
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer);
+CLOCKSOURCE_OF_DECLARE_RET(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer);
 
-static void __init tegra20_init_rtc(struct device_node *np)
+static int __init tegra20_init_rtc(struct device_node *np)
 {
 	struct clk *clk;
 
 	rtc_base = of_iomap(np, 0);
 	if (!rtc_base) {
 		pr_err("Can't map RTC registers");
-		BUG();
+		return -ENXIO;
 	}
 
 	/*
@@ -255,6 +259,6 @@ static void __init tegra20_init_rtc(struct device_node *np)
 	else
 		clk_prepare_enable(clk);
 
-	register_persistent_clock(NULL, tegra_read_persistent_clock64);
+	return register_persistent_clock(NULL, tegra_read_persistent_clock64);
 }
-CLOCKSOURCE_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc);
+CLOCKSOURCE_OF_DECLARE_RET(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 34/63] clocksource/drivers/time-efm32: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (32 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 33/63] clocksource/drivers/time-armada-370-xp: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 35/63] clocksource/drivers/time-lpc32xx: " Daniel Lezcano
                   ` (28 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 35/63] clocksource/drivers/time-lpc32xx: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (33 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 34/63] clocksource/drivers/time-efm32: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-17  6:52   ` Uwe Kleine-König
  2016-06-16 21:26 ` [PATCH V2 36/63] clocksource/drivers/time-orion: " Daniel Lezcano
                   ` (27 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Uwe Kleine-König, moderated list:ARM/ENERGY MICRO...

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-efm32.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/clocksource/time-efm32.c b/drivers/clocksource/time-efm32.c
index b06e4c2..b71ffc6 100644
--- a/drivers/clocksource/time-efm32.c
+++ b/drivers/clocksource/time-efm32.c
@@ -233,7 +233,11 @@ static int __init efm32_clockevent_init(struct device_node *np)
 					DIV_ROUND_CLOSEST(rate, 1024),
 					0xf, 0xffff);
 
-	setup_irq(irq, &efm32_clock_event_irq);
+	ret = setup_irq(irq, &efm32_clock_event_irq);
+	if (ret) {
+		pr_err("Failed setup irq");
+		goto err_get_irq;
+	}
 
 	return 0;
 
@@ -255,16 +259,16 @@ err_clk_get:
  * This function asserts that we have exactly one clocksource and one
  * clock_event_device in the end.
  */
-static void __init efm32_timer_init(struct device_node *np)
+static int __init efm32_timer_init(struct device_node *np)
 {
 	static int has_clocksource, has_clockevent;
-	int ret;
+	int ret = 0;
 
 	if (!has_clocksource) {
 		ret = efm32_clocksource_init(np);
 		if (!ret) {
 			has_clocksource = 1;
-			return;
+			return 0;
 		}
 	}
 
@@ -272,9 +276,11 @@ static void __init efm32_timer_init(struct device_node *np)
 		ret = efm32_clockevent_init(np);
 		if (!ret) {
 			has_clockevent = 1;
-			return;
+			return 0;
 		}
 	}
+
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(efm32compat, "efm32,timer", efm32_timer_init);
-CLOCKSOURCE_OF_DECLARE(efm32, "energymicro,efm32-timer", efm32_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(efm32compat, "efm32,timer", efm32_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(efm32, "energymicro,efm32-timer", efm32_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 36/63] clocksource/drivers/time-orion: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (34 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 35/63] clocksource/drivers/time-lpc32xx: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-20 17:08   ` Sylvain Lemieux
  2016-06-16 21:26 ` [PATCH V2 37/63] clocksource/drivers/time-pistachio: " Daniel Lezcano
                   ` (26 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Joachim Eastwood, Vladimir Zapolskiy,
	Sylvain Lemieux, moderated list:ARM/LPC18XX ARCHI...

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-lpc32xx.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/time-lpc32xx.c b/drivers/clocksource/time-lpc32xx.c
index daae61e..cb5b866 100644
--- a/drivers/clocksource/time-lpc32xx.c
+++ b/drivers/clocksource/time-lpc32xx.c
@@ -288,16 +288,16 @@ err_clk_enable:
  * This function asserts that we have exactly one clocksource and one
  * clock_event_device in the end.
  */
-static void __init lpc32xx_timer_init(struct device_node *np)
+static int __init lpc32xx_timer_init(struct device_node *np)
 {
 	static int has_clocksource, has_clockevent;
-	int ret;
+	int ret = 0;
 
 	if (!has_clocksource) {
 		ret = lpc32xx_clocksource_init(np);
 		if (!ret) {
 			has_clocksource = 1;
-			return;
+			return 0;
 		}
 	}
 
@@ -305,8 +305,10 @@ static void __init lpc32xx_timer_init(struct device_node *np)
 		ret = lpc32xx_clockevent_init(np);
 		if (!ret) {
 			has_clockevent = 1;
-			return;
+			return 0;
 		}
 	}
+
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(lpc32xx_timer, "nxp,lpc3220-timer", lpc32xx_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(lpc32xx_timer, "nxp,lpc3220-timer", lpc32xx_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 37/63] clocksource/drivers/time-pistachio: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (35 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 36/63] clocksource/drivers/time-orion: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 38/63] " Daniel Lezcano
                   ` (25 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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-orion.c | 52 ++++++++++++++++++++++++++++------------
 1 file changed, 37 insertions(+), 15 deletions(-)

diff --git a/drivers/clocksource/time-orion.c b/drivers/clocksource/time-orion.c
index 0ece742..5fdeb5d 100644
--- a/drivers/clocksource/time-orion.c
+++ b/drivers/clocksource/time-orion.c
@@ -104,25 +104,36 @@ static struct irqaction orion_clkevt_irq = {
 	.handler	= orion_clkevt_irq_handler,
 };
 
-static void __init orion_timer_init(struct device_node *np)
+static int __init orion_timer_init(struct device_node *np)
 {
 	struct clk *clk;
-	int irq;
+	int irq, ret;
 
 	/* timer registers are shared with watchdog timer */
 	timer_base = of_iomap(np, 0);
-	if (!timer_base)
-		panic("%s: unable to map resource\n", np->name);
+	if (!timer_base) {
+		pr_err("%s: unable to map resource\n", np->name);
+		return -ENXIO;
+	}
 
 	clk = of_clk_get(np, 0);
-	if (IS_ERR(clk))
-		panic("%s: unable to get clk\n", np->name);
-	clk_prepare_enable(clk);
+	if (IS_ERR(clk)) {
+		pr_err("%s: unable to get clk\n", np->name);
+		return PTR_ERR(clk);
+	}
+
+	ret = clk_prepare_enable(clk);
+	if (ret) {
+		pr_err("Failed to prepare clock");
+		return ret;
+	}
 
 	/* we are only interested in timer1 irq */
 	irq = irq_of_parse_and_map(np, 1);
-	if (irq <= 0)
-		panic("%s: unable to parse timer1 irq\n", np->name);
+	if (irq <= 0) {
+		pr_err("%s: unable to parse timer1 irq\n", np->name);
+		return -EINVAL;
+	}
 
 	/* setup timer0 as free-running clocksource */
 	writel(~0, timer_base + TIMER0_VAL);
@@ -130,19 +141,30 @@ static void __init orion_timer_init(struct device_node *np)
 	atomic_io_modify(timer_base + TIMER_CTRL,
 		TIMER0_RELOAD_EN | TIMER0_EN,
 		TIMER0_RELOAD_EN | TIMER0_EN);
-	clocksource_mmio_init(timer_base + TIMER0_VAL, "orion_clocksource",
-			      clk_get_rate(clk), 300, 32,
-			      clocksource_mmio_readl_down);
+
+	ret = clocksource_mmio_init(timer_base + TIMER0_VAL, "orion_clocksource",
+				    clk_get_rate(clk), 300, 32,
+				    clocksource_mmio_readl_down);
+	if (ret) {
+		pr_err("Failed to initialize mmio timer");
+		return ret;
+	}
+
 	sched_clock_register(orion_read_sched_clock, 32, clk_get_rate(clk));
 
 	/* setup timer1 as clockevent timer */
-	if (setup_irq(irq, &orion_clkevt_irq))
-		panic("%s: unable to setup irq\n", np->name);
+	ret = setup_irq(irq, &orion_clkevt_irq);
+	if (ret) {
+		pr_err("%s: unable to setup irq\n", np->name);
+		return ret;
+	}
 
 	ticks_per_jiffy = (clk_get_rate(clk) + HZ/2) / HZ;
 	orion_clkevt.cpumask = cpumask_of(0);
 	orion_clkevt.irq = irq;
 	clockevents_config_and_register(&orion_clkevt, clk_get_rate(clk),
 					ORION_ONESHOT_MIN, ORION_ONESHOT_MAX);
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(orion_timer, "marvell,orion-timer", orion_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(orion_timer, "marvell,orion-timer", orion_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 38/63] clocksource/drivers/time-pistachio: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (36 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 37/63] clocksource/drivers/time-pistachio: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 39/63] clocksource/drivers/timer-atlas7: " Daniel Lezcano
                   ` (24 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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-pistachio.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/clocksource/time-pistachio.c b/drivers/clocksource/time-pistachio.c
index 376e59b..adaaec5 100644
--- a/drivers/clocksource/time-pistachio.c
+++ b/drivers/clocksource/time-pistachio.c
@@ -148,7 +148,7 @@ static struct pistachio_clocksource pcs_gpt = {
 		},
 };
 
-static void __init pistachio_clksrc_of_init(struct device_node *node)
+static int __init pistachio_clksrc_of_init(struct device_node *node)
 {
 	struct clk *sys_clk, *fast_clk;
 	struct regmap *periph_regs;
@@ -158,45 +158,45 @@ static void __init pistachio_clksrc_of_init(struct device_node *node)
 	pcs_gpt.base = of_iomap(node, 0);
 	if (!pcs_gpt.base) {
 		pr_err("cannot iomap\n");
-		return;
+		return -ENXIO;
 	}
 
 	periph_regs = syscon_regmap_lookup_by_phandle(node, "img,cr-periph");
 	if (IS_ERR(periph_regs)) {
 		pr_err("cannot get peripheral regmap (%ld)\n",
 		       PTR_ERR(periph_regs));
-		return;
+		return PTR_ERR(periph_regs);
 	}
 
 	/* Switch to using the fast counter clock */
 	ret = regmap_update_bits(periph_regs, PERIP_TIMER_CONTROL,
 				 0xf, 0x0);
 	if (ret)
-		return;
+		return ret;
 
 	sys_clk = of_clk_get_by_name(node, "sys");
 	if (IS_ERR(sys_clk)) {
 		pr_err("clock get failed (%ld)\n", PTR_ERR(sys_clk));
-		return;
+		return PTR_ERR(sys_clk);
 	}
 
 	fast_clk = of_clk_get_by_name(node, "fast");
 	if (IS_ERR(fast_clk)) {
 		pr_err("clock get failed (%lu)\n", PTR_ERR(fast_clk));
-		return;
+		return PTR_ERR(fast_clk);
 	}
 
 	ret = clk_prepare_enable(sys_clk);
 	if (ret < 0) {
 		pr_err("failed to enable clock (%d)\n", ret);
-		return;
+		return ret;
 	}
 
 	ret = clk_prepare_enable(fast_clk);
 	if (ret < 0) {
 		pr_err("failed to enable clock (%d)\n", ret);
 		clk_disable_unprepare(sys_clk);
-		return;
+		return ret;
 	}
 
 	rate = clk_get_rate(fast_clk);
@@ -212,7 +212,7 @@ static void __init pistachio_clksrc_of_init(struct device_node *node)
 
 	raw_spin_lock_init(&pcs_gpt.lock);
 	sched_clock_register(pistachio_read_sched_clock, 32, rate);
-	clocksource_register_hz(&pcs_gpt.cs, rate);
+	return clocksource_register_hz(&pcs_gpt.cs, rate);
 }
-CLOCKSOURCE_OF_DECLARE(pistachio_gptimer, "img,pistachio-gptimer",
+CLOCKSOURCE_OF_DECLARE_RET(pistachio_gptimer, "img,pistachio-gptimer",
 		       pistachio_clksrc_of_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 39/63] clocksource/drivers/timer-atlas7: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (37 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 38/63] " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:26 ` [PATCH V2 40/63] clocksource/drivers/timer-atmel-pit: " Daniel Lezcano
                   ` (23 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Barry Song, moderated list:ARM/CSR SIRFPRIMA...

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-atlas7.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/drivers/clocksource/timer-atlas7.c b/drivers/clocksource/timer-atlas7.c
index 27fa136..7b1a007 100644
--- a/drivers/clocksource/timer-atlas7.c
+++ b/drivers/clocksource/timer-atlas7.c
@@ -238,7 +238,7 @@ static struct notifier_block sirfsoc_cpu_nb = {
 	.notifier_call = sirfsoc_cpu_notify,
 };
 
-static void __init sirfsoc_clockevent_init(void)
+static int __init sirfsoc_clockevent_init(void)
 {
 	sirfsoc_clockevent = alloc_percpu(struct clock_event_device);
 	BUG_ON(!sirfsoc_clockevent);
@@ -246,11 +246,11 @@ static void __init sirfsoc_clockevent_init(void)
 	BUG_ON(register_cpu_notifier(&sirfsoc_cpu_nb));
 
 	/* Immediately configure the timer on the boot CPU */
-	sirfsoc_local_timer_setup(this_cpu_ptr(sirfsoc_clockevent));
+	return sirfsoc_local_timer_setup(this_cpu_ptr(sirfsoc_clockevent));
 }
 
 /* initialize the kernel jiffy timer source */
-static void __init sirfsoc_atlas7_timer_init(struct device_node *np)
+static int __init sirfsoc_atlas7_timer_init(struct device_node *np)
 {
 	struct clk *clk;
 
@@ -279,23 +279,29 @@ static void __init sirfsoc_atlas7_timer_init(struct device_node *np)
 
 	BUG_ON(clocksource_register_hz(&sirfsoc_clocksource, atlas7_timer_rate));
 
-	sirfsoc_clockevent_init();
+	return sirfsoc_clockevent_init();
 }
 
-static void __init sirfsoc_of_timer_init(struct device_node *np)
+static int __init sirfsoc_of_timer_init(struct device_node *np)
 {
 	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);
-	if (!sirfsoc_timer_irq.irq)
-		panic("No irq passed for timer0 via DT\n");
+	if (!sirfsoc_timer_irq.irq) {
+		pr_err("No irq passed for timer0 via DT\n");
+		return -EINVAL;
+	}
 
 	sirfsoc_timer1_irq.irq = irq_of_parse_and_map(np, 1);
-	if (!sirfsoc_timer1_irq.irq)
-		panic("No irq passed for timer1 via DT\n");
+	if (!sirfsoc_timer1_irq.irq) {
+		pr_err("No irq passed for timer1 via DT\n");
+		return -EINVAL;
+	}
 
-	sirfsoc_atlas7_timer_init(np);
+	return sirfsoc_atlas7_timer_init(np);
 }
-CLOCKSOURCE_OF_DECLARE(sirfsoc_atlas7_timer, "sirf,atlas7-tick", sirfsoc_of_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(sirfsoc_atlas7_timer, "sirf,atlas7-tick", sirfsoc_of_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 40/63] clocksource/drivers/timer-atmel-pit: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (38 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 39/63] clocksource/drivers/timer-atlas7: " Daniel Lezcano
@ 2016-06-16 21:26 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 41/63] clocksource/drivers/timer-atmel-st: " Daniel Lezcano
                   ` (22 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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-atmel-pit.c | 43 +++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
index d911c5d..ffaca7c 100644
--- a/drivers/clocksource/timer-atmel-pit.c
+++ b/drivers/clocksource/timer-atmel-pit.c
@@ -177,7 +177,7 @@ static irqreturn_t at91sam926x_pit_interrupt(int irq, void *dev_id)
 /*
  * Set up both clocksource and clockevent support.
  */
-static void __init at91sam926x_pit_common_init(struct pit_data *data)
+static int __init at91sam926x_pit_common_init(struct pit_data *data)
 {
 	unsigned long	pit_rate;
 	unsigned	bits;
@@ -204,14 +204,21 @@ static void __init at91sam926x_pit_common_init(struct pit_data *data)
 	data->clksrc.rating = 175;
 	data->clksrc.read = read_pit_clk;
 	data->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
-	clocksource_register_hz(&data->clksrc, pit_rate);
+	
+	ret = clocksource_register_hz(&data->clksrc, pit_rate);
+	if (ret) {
+		pr_err("Failed to register clocksource");
+		return ret;
+	}
 
 	/* Set up irq handler */
 	ret = request_irq(data->irq, at91sam926x_pit_interrupt,
 			  IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
 			  "at91_tick", data);
-	if (ret)
-		panic(pr_fmt("Unable to setup IRQ\n"));
+	if (ret) {
+		pr_err("Unable to setup IRQ\n");
+		return ret;
+	}
 
 	/* Set up and register clockevents */
 	data->clkevt.name = "pit";
@@ -226,34 +233,42 @@ static void __init at91sam926x_pit_common_init(struct pit_data *data)
 	data->clkevt.resume = at91sam926x_pit_resume;
 	data->clkevt.suspend = at91sam926x_pit_suspend;
 	clockevents_register_device(&data->clkevt);
+
+	return 0;
 }
 
-static void __init at91sam926x_pit_dt_init(struct device_node *node)
+static int __init at91sam926x_pit_dt_init(struct device_node *node)
 {
 	struct pit_data *data;
 
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
-		panic(pr_fmt("Unable to allocate memory\n"));
+		return -ENOMEM;
 
 	data->base = of_iomap(node, 0);
-	if (!data->base)
-		panic(pr_fmt("Could not map PIT address\n"));
+	if (!data->base) {
+		pr_err("Could not map PIT address\n");
+		return -ENXIO;
+	}
 
 	data->mck = of_clk_get(node, 0);
 	if (IS_ERR(data->mck))
 		/* Fallback on clkdev for !CCF-based boards */
 		data->mck = clk_get(NULL, "mck");
 
-	if (IS_ERR(data->mck))
-		panic(pr_fmt("Unable to get mck clk\n"));
+	if (IS_ERR(data->mck)) {
+		pr_err("Unable to get mck clk\n");
+		return PTR_ERR(data->mck);
+	}
 
 	/* Get the interrupts property */
 	data->irq = irq_of_parse_and_map(node, 0);
-	if (!data->irq)
-		panic(pr_fmt("Unable to get IRQ from DT\n"));
+	if (!data->irq) {
+		pr_err("Unable to get IRQ from DT\n");
+		return -EINVAL;
+	}
 
-	at91sam926x_pit_common_init(data);
+	return at91sam926x_pit_common_init(data);
 }
-CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit",
+CLOCKSOURCE_OF_DECLARE_RET(at91sam926x_pit, "atmel,at91sam9260-pit",
 		       at91sam926x_pit_dt_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 41/63] clocksource/drivers/timer-atmel-st: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (39 preceding siblings ...)
  2016-06-16 21:26 ` [PATCH V2 40/63] clocksource/drivers/timer-atmel-pit: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 42/63] clocksource/drivers/prima2: " Daniel Lezcano
                   ` (21 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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-atmel-st.c | 44 +++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/drivers/clocksource/timer-atmel-st.c b/drivers/clocksource/timer-atmel-st.c
index 29d21d6..e9331d3 100644
--- a/drivers/clocksource/timer-atmel-st.c
+++ b/drivers/clocksource/timer-atmel-st.c
@@ -194,15 +194,17 @@ static struct clock_event_device clkevt = {
 /*
  * ST (system timer) module supports both clockevents and clocksource.
  */
-static void __init atmel_st_timer_init(struct device_node *node)
+static int __init atmel_st_timer_init(struct device_node *node)
 {
 	struct clk *sclk;
 	unsigned int sclk_rate, val;
 	int irq, ret;
 
 	regmap_st = syscon_node_to_regmap(node);
-	if (IS_ERR(regmap_st))
-		panic(pr_fmt("Unable to get regmap\n"));
+	if (IS_ERR(regmap_st)) {
+		pr_err("Unable to get regmap\n");
+		return PTR_ERR(regmap_st);
+	}
 
 	/* Disable all timer interrupts, and clear any pending ones */
 	regmap_write(regmap_st, AT91_ST_IDR,
@@ -211,27 +213,37 @@ static void __init atmel_st_timer_init(struct device_node *node)
 
 	/* Get the interrupts property */
 	irq  = irq_of_parse_and_map(node, 0);
-	if (!irq)
-		panic(pr_fmt("Unable to get IRQ from DT\n"));
+	if (!irq) {
+		pr_err("Unable to get IRQ from DT\n");
+		return -EINVAL;
+	}
 
 	/* Make IRQs happen for the system timer */
 	ret = request_irq(irq, at91rm9200_timer_interrupt,
 			  IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
 			  "at91_tick", regmap_st);
-	if (ret)
-		panic(pr_fmt("Unable to setup IRQ\n"));
+	if (ret) {
+		pr_err("Unable to setup IRQ\n");
+		return ret;
+	}
 
 	sclk = of_clk_get(node, 0);
-	if (IS_ERR(sclk))
-		panic(pr_fmt("Unable to get slow clock\n"));
+	if (IS_ERR(sclk)) {
+		pr_err("Unable to get slow clock\n");
+		return PTR_ERR(sclk);
+	}
 
-	clk_prepare_enable(sclk);
-	if (ret)
-		panic(pr_fmt("Could not enable slow clock\n"));
+	ret = clk_prepare_enable(sclk);
+	if (ret) {
+		pr_err("Could not enable slow clock\n");
+		return ret;
+	}
 
 	sclk_rate = clk_get_rate(sclk);
-	if (!sclk_rate)
-		panic(pr_fmt("Invalid slow clock rate\n"));
+	if (!sclk_rate) {
+		pr_err("Invalid slow clock rate\n");
+		return -EINVAL;
+	}
 	timer_latch = (sclk_rate + HZ / 2) / HZ;
 
 	/* The 32KiHz "Slow Clock" (tick every 30517.58 nanoseconds) is used
@@ -246,7 +258,7 @@ static void __init atmel_st_timer_init(struct device_node *node)
 					2, AT91_ST_ALMV);
 
 	/* register clocksource */
-	clocksource_register_hz(&clk32k, sclk_rate);
+	return clocksource_register_hz(&clk32k, sclk_rate);
 }
-CLOCKSOURCE_OF_DECLARE(atmel_st_timer, "atmel,at91rm9200-st",
+CLOCKSOURCE_OF_DECLARE_RET(atmel_st_timer, "atmel,at91rm9200-st",
 		       atmel_st_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 42/63] clocksource/drivers/prima2: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (40 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 41/63] clocksource/drivers/timer-atmel-st: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 43/63] clocksource/drivers/timer-imx-gpt: " Daniel Lezcano
                   ` (20 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Barry Song, moderated list:ARM/CSR SIRFPRIMA...

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

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 43/63] clocksource/drivers/timer-imx-gpt: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (41 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 42/63] clocksource/drivers/prima2: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 44/63] clocksource/drivers/timer-integrator-ap: " Daniel Lezcano
                   ` (19 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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-imx-gpt.c | 75 ++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 30 deletions(-)

diff --git a/drivers/clocksource/timer-imx-gpt.c b/drivers/clocksource/timer-imx-gpt.c
index 99ec967..d5640a74 100644
--- a/drivers/clocksource/timer-imx-gpt.c
+++ b/drivers/clocksource/timer-imx-gpt.c
@@ -407,8 +407,10 @@ static const struct imx_gpt_data imx6dl_gpt_data = {
 	.set_next_event = v2_set_next_event,
 };
 
-static void __init _mxc_timer_init(struct imx_timer *imxtm)
+static int __init _mxc_timer_init(struct imx_timer *imxtm)
 {
+	int ret;
+
 	switch (imxtm->type) {
 	case GPT_TYPE_IMX1:
 		imxtm->gpt = &imx1_gpt_data;
@@ -423,12 +425,12 @@ static void __init _mxc_timer_init(struct imx_timer *imxtm)
 		imxtm->gpt = &imx6dl_gpt_data;
 		break;
 	default:
-		BUG();
+		return -EINVAL;
 	}
 
 	if (IS_ERR(imxtm->clk_per)) {
 		pr_err("i.MX timer: unable to get clk\n");
-		return;
+		return PTR_ERR(imxtm->clk_per);
 	}
 
 	if (!IS_ERR(imxtm->clk_ipg))
@@ -446,8 +448,11 @@ static void __init _mxc_timer_init(struct imx_timer *imxtm)
 	imxtm->gpt->gpt_setup_tctl(imxtm);
 
 	/* init and register the timer to the framework */
-	mxc_clocksource_init(imxtm);
-	mxc_clockevent_init(imxtm);
+	ret = mxc_clocksource_init(imxtm);
+	if (ret)
+		return ret;
+
+	return mxc_clockevent_init(imxtm);
 }
 
 void __init mxc_timer_init(unsigned long pbase, int irq, enum imx_gpt_type type)
@@ -469,21 +474,27 @@ void __init mxc_timer_init(unsigned long pbase, int irq, enum imx_gpt_type type)
 	_mxc_timer_init(imxtm);
 }
 
-static void __init mxc_timer_init_dt(struct device_node *np,  enum imx_gpt_type type)
+static int __init mxc_timer_init_dt(struct device_node *np,  enum imx_gpt_type type)
 {
 	struct imx_timer *imxtm;
 	static int initialized;
+	int ret;
 
 	/* Support one instance only */
 	if (initialized)
-		return;
+		return 0;
 
 	imxtm = kzalloc(sizeof(*imxtm), GFP_KERNEL);
-	BUG_ON(!imxtm);
+	if (!imxtm)
+		return -ENOMEM;
 
 	imxtm->base = of_iomap(np, 0);
-	WARN_ON(!imxtm->base);
+	if (!imxtm->base)
+		return -ENXIO;
+
 	imxtm->irq = irq_of_parse_and_map(np, 0);
+	if (imxtm->irq <= 0)
+		return -EINVAL;
 
 	imxtm->clk_ipg = of_clk_get_by_name(np, "ipg");
 
@@ -494,22 +505,26 @@ static void __init mxc_timer_init_dt(struct device_node *np,  enum imx_gpt_type
 
 	imxtm->type = type;
 
-	_mxc_timer_init(imxtm);
+	ret = _mxc_timer_init(imxtm);
+	if (ret)
+		return ret;
 
 	initialized = 1;
+
+	return 0;
 }
 
-static void __init imx1_timer_init_dt(struct device_node *np)
+static int __init imx1_timer_init_dt(struct device_node *np)
 {
-	mxc_timer_init_dt(np, GPT_TYPE_IMX1);
+	return mxc_timer_init_dt(np, GPT_TYPE_IMX1);
 }
 
-static void __init imx21_timer_init_dt(struct device_node *np)
+static int __init imx21_timer_init_dt(struct device_node *np)
 {
-	mxc_timer_init_dt(np, GPT_TYPE_IMX21);
+	return mxc_timer_init_dt(np, GPT_TYPE_IMX21);
 }
 
-static void __init imx31_timer_init_dt(struct device_node *np)
+static int __init imx31_timer_init_dt(struct device_node *np)
 {
 	enum imx_gpt_type type = GPT_TYPE_IMX31;
 
@@ -522,23 +537,23 @@ static void __init imx31_timer_init_dt(struct device_node *np)
 	if (of_machine_is_compatible("fsl,imx6dl"))
 		type = GPT_TYPE_IMX6DL;
 
-	mxc_timer_init_dt(np, type);
+	return mxc_timer_init_dt(np, type);
 }
 
-static void __init imx6dl_timer_init_dt(struct device_node *np)
+static int __init imx6dl_timer_init_dt(struct device_node *np)
 {
-	mxc_timer_init_dt(np, GPT_TYPE_IMX6DL);
+	return mxc_timer_init_dt(np, GPT_TYPE_IMX6DL);
 }
 
-CLOCKSOURCE_OF_DECLARE(imx1_timer, "fsl,imx1-gpt", imx1_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx21_timer, "fsl,imx21-gpt", imx21_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx27_timer, "fsl,imx27-gpt", imx21_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx31_timer, "fsl,imx31-gpt", imx31_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx25_timer, "fsl,imx25-gpt", imx31_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx50_timer, "fsl,imx50-gpt", imx31_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx51_timer, "fsl,imx51-gpt", imx31_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx53_timer, "fsl,imx53-gpt", imx31_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx6q_timer, "fsl,imx6q-gpt", imx31_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx6dl_timer, "fsl,imx6dl-gpt", imx6dl_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx6sl_timer, "fsl,imx6sl-gpt", imx6dl_timer_init_dt);
-CLOCKSOURCE_OF_DECLARE(imx6sx_timer, "fsl,imx6sx-gpt", imx6dl_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx1_timer, "fsl,imx1-gpt", imx1_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx21_timer, "fsl,imx21-gpt", imx21_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx27_timer, "fsl,imx27-gpt", imx21_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx31_timer, "fsl,imx31-gpt", imx31_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx25_timer, "fsl,imx25-gpt", imx31_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx50_timer, "fsl,imx50-gpt", imx31_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx51_timer, "fsl,imx51-gpt", imx31_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx53_timer, "fsl,imx53-gpt", imx31_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx6q_timer, "fsl,imx6q-gpt", imx31_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx6dl_timer, "fsl,imx6dl-gpt", imx6dl_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx6sl_timer, "fsl,imx6sl-gpt", imx6dl_timer_init_dt);
+CLOCKSOURCE_OF_DECLARE_RET(imx6sx_timer, "fsl,imx6sx-gpt", imx6dl_timer_init_dt);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 44/63] clocksource/drivers/timer-integrator-ap: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (42 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 43/63] clocksource/drivers/timer-imx-gpt: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 45/63] clocksource/drivers/timer-keystone: " Daniel Lezcano
                   ` (18 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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-integrator-ap.c | 59 ++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 21 deletions(-)

diff --git a/drivers/clocksource/timer-integrator-ap.c b/drivers/clocksource/timer-integrator-ap.c
index 3f59ac2..675face 100644
--- a/drivers/clocksource/timer-integrator-ap.c
+++ b/drivers/clocksource/timer-integrator-ap.c
@@ -36,11 +36,12 @@ static u64 notrace integrator_read_sched_clock(void)
 	return -readl(sched_clk_base + TIMER_VALUE);
 }
 
-static void integrator_clocksource_init(unsigned long inrate,
-					void __iomem *base)
+static int integrator_clocksource_init(unsigned long inrate,
+				       void __iomem *base)
 {
 	u32 ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
 	unsigned long rate = inrate;
+	int ret;
 
 	if (rate >= 1500000) {
 		rate /= 16;
@@ -50,11 +51,15 @@ static void integrator_clocksource_init(unsigned long inrate,
 	writel(0xffff, base + TIMER_LOAD);
 	writel(ctrl, base + TIMER_CTRL);
 
-	clocksource_mmio_init(base + TIMER_VALUE, "timer2",
-			rate, 200, 16, clocksource_mmio_readl_down);
+	ret = clocksource_mmio_init(base + TIMER_VALUE, "timer2",
+				    rate, 200, 16, clocksource_mmio_readl_down);
+	if (ret)
+		return ret;
 
 	sched_clk_base = base;
 	sched_clock_register(integrator_read_sched_clock, 16, rate);
+
+	return 0;
 }
 
 static unsigned long timer_reload;
@@ -138,11 +143,12 @@ static struct irqaction integrator_timer_irq = {
 	.dev_id		= &integrator_clockevent,
 };
 
-static void integrator_clockevent_init(unsigned long inrate,
-				void __iomem *base, int irq)
+static int integrator_clockevent_init(unsigned long inrate,
+				      void __iomem *base, int irq)
 {
 	unsigned long rate = inrate;
 	unsigned int ctrl = 0;
+	int ret;
 
 	clkevt_base = base;
 	/* Calculate and program a divisor */
@@ -156,14 +162,18 @@ static void integrator_clockevent_init(unsigned long inrate,
 	timer_reload = rate / HZ;
 	writel(ctrl, clkevt_base + TIMER_CTRL);
 
-	setup_irq(irq, &integrator_timer_irq);
+	ret = setup_irq(irq, &integrator_timer_irq);
+	if (ret)
+		return ret;
+
 	clockevents_config_and_register(&integrator_clockevent,
 					rate,
 					1,
 					0xffffU);
+	return 0;
 }
 
-static void __init integrator_ap_timer_init_of(struct device_node *node)
+static int __init integrator_ap_timer_init_of(struct device_node *node)
 {
 	const char *path;
 	void __iomem *base;
@@ -176,12 +186,12 @@ static void __init integrator_ap_timer_init_of(struct device_node *node)
 
 	base = of_io_request_and_map(node, 0, "integrator-timer");
 	if (IS_ERR(base))
-		return;
+		return PTR_ERR(base);
 
 	clk = of_clk_get(node, 0);
 	if (IS_ERR(clk)) {
 		pr_err("No clock for %s\n", node->name);
-		return;
+		return PTR_ERR(clk);
 	}
 	clk_prepare_enable(clk);
 	rate = clk_get_rate(clk);
@@ -189,31 +199,38 @@ static void __init integrator_ap_timer_init_of(struct device_node *node)
 
 	err = of_property_read_string(of_aliases,
 				"arm,timer-primary", &path);
-	if (WARN_ON(err))
-		return;
+	if (err) {
+		pr_warn("Failed to read property");
+		return err;
+	}
+
 	pri_node = of_find_node_by_path(path);
+
 	err = of_property_read_string(of_aliases,
 				"arm,timer-secondary", &path);
-	if (WARN_ON(err))
-		return;
+	if (err) {
+		pr_warn("Failed to read property");		
+		return err;
+	}
+
+
 	sec_node = of_find_node_by_path(path);
 
-	if (node == pri_node) {
+	if (node == pri_node)
 		/* The primary timer lacks IRQ, use as clocksource */
-		integrator_clocksource_init(rate, base);
-		return;
-	}
+		return integrator_clocksource_init(rate, base);
 
 	if (node == sec_node) {
 		/* The secondary timer will drive the clock event */
 		irq = irq_of_parse_and_map(node, 0);
-		integrator_clockevent_init(rate, base, irq);
-		return;
+		return integrator_clockevent_init(rate, base, irq);
 	}
 
 	pr_info("Timer @%p unused\n", base);
 	clk_disable_unprepare(clk);
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(integrator_ap_timer, "arm,integrator-timer",
+CLOCKSOURCE_OF_DECLARE_RET(integrator_ap_timer, "arm,integrator-timer",
 		       integrator_ap_timer_init_of);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 45/63] clocksource/drivers/timer-keystone: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (43 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 44/63] clocksource/drivers/timer-integrator-ap: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-17 16:03   ` Santosh Shilimkar
  2016-06-16 21:27 ` [PATCH V2 46/63] clocksource/drivers/timer-sp804: " Daniel Lezcano
                   ` (17 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Santosh Shilimkar, moderated list:ARM/TEXAS INSTRUM...

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-keystone.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/clocksource/timer-keystone.c b/drivers/clocksource/timer-keystone.c
index 1cea08c..4199823 100644
--- a/drivers/clocksource/timer-keystone.c
+++ b/drivers/clocksource/timer-keystone.c
@@ -144,7 +144,7 @@ static int keystone_set_periodic(struct clock_event_device *evt)
 	return 0;
 }
 
-static void __init keystone_timer_init(struct device_node *np)
+static int __init keystone_timer_init(struct device_node *np)
 {
 	struct clock_event_device *event_dev = &timer.event_dev;
 	unsigned long rate;
@@ -154,20 +154,20 @@ static void __init keystone_timer_init(struct device_node *np)
 	irq  = irq_of_parse_and_map(np, 0);
 	if (!irq) {
 		pr_err("%s: failed to map interrupts\n", __func__);
-		return;
+		return -EINVAL;
 	}
 
 	timer.base = of_iomap(np, 0);
 	if (!timer.base) {
 		pr_err("%s: failed to map registers\n", __func__);
-		return;
+		return -ENXIO;
 	}
 
 	clk = of_clk_get(np, 0);
 	if (IS_ERR(clk)) {
 		pr_err("%s: failed to get clock\n", __func__);
 		iounmap(timer.base);
-		return;
+		return PTR_ERR(clk);
 	}
 
 	error = clk_prepare_enable(clk);
@@ -219,11 +219,12 @@ static void __init keystone_timer_init(struct device_node *np)
 	clockevents_config_and_register(event_dev, rate, 1, ULONG_MAX);
 
 	pr_info("keystone timer clock @%lu Hz\n", rate);
-	return;
+	return 0;
 err:
 	clk_put(clk);
 	iounmap(timer.base);
+	return error;
 }
 
-CLOCKSOURCE_OF_DECLARE(keystone_timer, "ti,keystone-timer",
-					keystone_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(keystone_timer, "ti,keystone-timer",
+			   keystone_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 46/63] clocksource/drivers/timer-sp804: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (44 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 45/63] clocksource/drivers/timer-keystone: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 47/63] clocksource/drivers/timer-stm32: " Daniel Lezcano
                   ` (16 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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-sp804.c | 91 ++++++++++++++++++++++++++-------------
 1 file changed, 60 insertions(+), 31 deletions(-)

diff --git a/drivers/clocksource/timer-sp804.c b/drivers/clocksource/timer-sp804.c
index 5f45b9a..7c2944ad 100644
--- a/drivers/clocksource/timer-sp804.c
+++ b/drivers/clocksource/timer-sp804.c
@@ -77,7 +77,7 @@ void __init sp804_timer_disable(void __iomem *base)
 	writel(0, base + TIMER_CTRL);
 }
 
-void __init __sp804_clocksource_and_sched_clock_init(void __iomem *base,
+int  __init __sp804_clocksource_and_sched_clock_init(void __iomem *base,
 						     const char *name,
 						     struct clk *clk,
 						     int use_sched_clock)
@@ -89,14 +89,13 @@ void __init __sp804_clocksource_and_sched_clock_init(void __iomem *base,
 		if (IS_ERR(clk)) {
 			pr_err("sp804: clock not found: %d\n",
 			       (int)PTR_ERR(clk));
-			return;
+			return PTR_ERR(clk);
 		}
 	}
 
 	rate = sp804_get_clock_rate(clk);
-
 	if (rate < 0)
-		return;
+		return -EINVAL;
 
 	/* setup timer 0 as free-running clocksource */
 	writel(0, base + TIMER_CTRL);
@@ -112,6 +111,8 @@ void __init __sp804_clocksource_and_sched_clock_init(void __iomem *base,
 		sched_clock_base = base;
 		sched_clock_register(sp804_read, 32, rate);
 	}
+
+	return 0;
 }
 
 
@@ -186,7 +187,7 @@ static struct irqaction sp804_timer_irq = {
 	.dev_id		= &sp804_clockevent,
 };
 
-void __init __sp804_clockevents_init(void __iomem *base, unsigned int irq, struct clk *clk, const char *name)
+int __init __sp804_clockevents_init(void __iomem *base, unsigned int irq, struct clk *clk, const char *name)
 {
 	struct clock_event_device *evt = &sp804_clockevent;
 	long rate;
@@ -196,12 +197,12 @@ void __init __sp804_clockevents_init(void __iomem *base, unsigned int irq, struc
 	if (IS_ERR(clk)) {
 		pr_err("sp804: %s clock not found: %d\n", name,
 			(int)PTR_ERR(clk));
-		return;
+		return PTR_ERR(clk);
 	}
 
 	rate = sp804_get_clock_rate(clk);
 	if (rate < 0)
-		return;
+		return -EINVAL;
 
 	clkevt_base = base;
 	clkevt_reload = DIV_ROUND_CLOSEST(rate, HZ);
@@ -213,27 +214,31 @@ void __init __sp804_clockevents_init(void __iomem *base, unsigned int irq, struc
 
 	setup_irq(irq, &sp804_timer_irq);
 	clockevents_config_and_register(evt, rate, 0xf, 0xffffffff);
+
+	return 0;
 }
 
-static void __init sp804_of_init(struct device_node *np)
+static int __init sp804_of_init(struct device_node *np)
 {
 	static bool initialized = false;
 	void __iomem *base;
-	int irq;
+	int irq, ret = -EINVAL;
 	u32 irq_num = 0;
 	struct clk *clk1, *clk2;
 	const char *name = of_get_property(np, "compatible", NULL);
 
 	base = of_iomap(np, 0);
-	if (WARN_ON(!base))
-		return;
+	if (!base)
+		return -ENXIO;
 
 	/* Ensure timers are disabled */
 	writel(0, base + TIMER_CTRL);
 	writel(0, base + TIMER_2_BASE + TIMER_CTRL);
 
-	if (initialized || !of_device_is_available(np))
+	if (initialized || !of_device_is_available(np)) {
+		ret = -EINVAL;
 		goto err;
+	}
 
 	clk1 = of_clk_get(np, 0);
 	if (IS_ERR(clk1))
@@ -256,35 +261,53 @@ static void __init sp804_of_init(struct device_node *np)
 
 	of_property_read_u32(np, "arm,sp804-has-irq", &irq_num);
 	if (irq_num == 2) {
-		__sp804_clockevents_init(base + TIMER_2_BASE, irq, clk2, name);
-		__sp804_clocksource_and_sched_clock_init(base, name, clk1, 1);
+
+		ret = __sp804_clockevents_init(base + TIMER_2_BASE, irq, clk2, name);
+		if (ret)
+			goto err;
+
+		ret = __sp804_clocksource_and_sched_clock_init(base, name, clk1, 1);
+		if (ret)
+			goto err;
 	} else {
-		__sp804_clockevents_init(base, irq, clk1 , name);
-		__sp804_clocksource_and_sched_clock_init(base + TIMER_2_BASE,
-							 name, clk2, 1);
+
+		ret = __sp804_clockevents_init(base, irq, clk1 , name);
+		if (ret)
+			goto err;
+
+		ret =__sp804_clocksource_and_sched_clock_init(base + TIMER_2_BASE,
+							      name, clk2, 1);
+		if (ret)
+			goto err;
 	}
 	initialized = true;
 
-	return;
+	return 0;
 err:
 	iounmap(base);
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(sp804, "arm,sp804", sp804_of_init);
+CLOCKSOURCE_OF_DECLARE_RET(sp804, "arm,sp804", sp804_of_init);
 
-static void __init integrator_cp_of_init(struct device_node *np)
+static int __init integrator_cp_of_init(struct device_node *np)
 {
 	static int init_count = 0;
 	void __iomem *base;
-	int irq;
+	int irq, ret = -EINVAL;
 	const char *name = of_get_property(np, "compatible", NULL);
 	struct clk *clk;
 
 	base = of_iomap(np, 0);
-	if (WARN_ON(!base))
-		return;
+	if (!base) {
+		pr_err("Failed to iomap");
+		return -ENXIO;
+	}
+
 	clk = of_clk_get(np, 0);
-	if (WARN_ON(IS_ERR(clk)))
-		return;
+	if (IS_ERR(clk)) {
+		pr_err("Failed to get clock");
+		return PTR_ERR(clk);
+	}
 
 	/* Ensure timer is disabled */
 	writel(0, base + TIMER_CTRL);
@@ -292,19 +315,25 @@ static void __init integrator_cp_of_init(struct device_node *np)
 	if (init_count == 2 || !of_device_is_available(np))
 		goto err;
 
-	if (!init_count)
-		__sp804_clocksource_and_sched_clock_init(base, name, clk, 0);
-	else {
+	if (!init_count) {
+		ret = __sp804_clocksource_and_sched_clock_init(base, name, clk, 0);
+		if (ret)
+			goto err;
+			
+	} else {
 		irq = irq_of_parse_and_map(np, 0);
 		if (irq <= 0)
 			goto err;
 
-		__sp804_clockevents_init(base, irq, clk, name);
+		ret = __sp804_clockevents_init(base, irq, clk, name);
+		if (ret)
+			goto err;
 	}
 
 	init_count++;
-	return;
+	return 0;
 err:
 	iounmap(base);
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(intcp, "arm,integrator-cp-timer", integrator_cp_of_init);
+CLOCKSOURCE_OF_DECLARE_RET(intcp, "arm,integrator-cp-timer", integrator_cp_of_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 47/63] clocksource/drivers/timer-stm32: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (45 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 46/63] clocksource/drivers/timer-sp804: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-20 11:32   ` Maxime Coquelin
  2016-06-16 21:27 ` [PATCH V2 48/63] clocksource/drivers/timer-sun5i: " Daniel Lezcano
                   ` (15 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Maxime Coquelin, moderated list:ARM/STM32 ARCHITE...

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-stm32.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c
index f3dcb76..d5bf352 100644
--- a/drivers/clocksource/timer-stm32.c
+++ b/drivers/clocksource/timer-stm32.c
@@ -98,7 +98,7 @@ static struct stm32_clock_event_ddata clock_event_ddata = {
 	},
 };
 
-static void __init stm32_clockevent_init(struct device_node *np)
+static int __init stm32_clockevent_init(struct device_node *np)
 {
 	struct stm32_clock_event_ddata *data = &clock_event_ddata;
 	struct clk *clk;
@@ -130,12 +130,14 @@ static void __init stm32_clockevent_init(struct device_node *np)
 
 	data->base = of_iomap(np, 0);
 	if (!data->base) {
+		ret = -ENXIO;
 		pr_err("failed to map registers for clockevent\n");
 		goto err_iomap;
 	}
 
 	irq = irq_of_parse_and_map(np, 0);
 	if (!irq) {
+		ret = -EINVAL;
 		pr_err("%s: failed to get irq.\n", np->full_name);
 		goto err_get_irq;
 	}
@@ -173,7 +175,7 @@ static void __init stm32_clockevent_init(struct device_node *np)
 	pr_info("%s: STM32 clockevent driver initialized (%d bits)\n",
 			np->full_name, bits);
 
-	return;
+	return ret;
 
 err_get_irq:
 	iounmap(data->base);
@@ -182,7 +184,7 @@ err_iomap:
 err_clk_enable:
 	clk_put(clk);
 err_clk_get:
-	return;
+	return ret;
 }
 
-CLOCKSOURCE_OF_DECLARE(stm32, "st,stm32-timer", stm32_clockevent_init);
+CLOCKSOURCE_OF_DECLARE_RET(stm32, "st,stm32-timer", stm32_clockevent_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 48/63] clocksource/drivers/timer-sun5i: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (46 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 47/63] clocksource/drivers/timer-stm32: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 49/63] clocksource/drivers/timer-ti-32k: " Daniel Lezcano
                   ` (14 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Maxime Ripard, Chen-Yu Tsai,
	moderated list:ARM/Allwinner sun...

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-sun5i.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c
index 24c83f9..f0a3ffb 100644
--- a/drivers/clocksource/timer-sun5i.c
+++ b/drivers/clocksource/timer-sun5i.c
@@ -311,33 +311,42 @@ err_free:
 	return ret;
 }
 
-static void __init sun5i_timer_init(struct device_node *node)
+static int __init sun5i_timer_init(struct device_node *node)
 {
 	struct reset_control *rstc;
 	void __iomem *timer_base;
 	struct clk *clk;
-	int irq;
+	int irq, ret;
 
 	timer_base = of_io_request_and_map(node, 0, of_node_full_name(node));
-	if (IS_ERR(timer_base))
-		panic("Can't map registers");
+	if (IS_ERR(timer_base)) {
+		pr_err("Can't map registers");
+		return PTR_ERR(timer_base);;
+	}
 
 	irq = irq_of_parse_and_map(node, 0);
-	if (irq <= 0)
-		panic("Can't parse IRQ");
+	if (irq <= 0) {
+		pr_err("Can't parse IRQ");
+		return -EINVAL;
+	}
 
 	clk = of_clk_get(node, 0);
-	if (IS_ERR(clk))
-		panic("Can't get timer clock");
+	if (IS_ERR(clk)) {
+		pr_err("Can't get timer clock");
+		return PTR_ERR(clk);
+	}
 
 	rstc = of_reset_control_get(node, NULL);
 	if (!IS_ERR(rstc))
 		reset_control_deassert(rstc);
 
-	sun5i_setup_clocksource(node, timer_base, clk, irq);
-	sun5i_setup_clockevent(node, timer_base, clk, irq);
+	ret = sun5i_setup_clocksource(node, timer_base, clk, irq);
+	if (ret)
+		return ret;
+
+	return sun5i_setup_clockevent(node, timer_base, clk, irq);
 }
-CLOCKSOURCE_OF_DECLARE(sun5i_a13, "allwinner,sun5i-a13-hstimer",
-		       sun5i_timer_init);
-CLOCKSOURCE_OF_DECLARE(sun7i_a20, "allwinner,sun7i-a20-hstimer",
-		       sun5i_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(sun5i_a13, "allwinner,sun5i-a13-hstimer",
+			   sun5i_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(sun7i_a20, "allwinner,sun7i-a20-hstimer",
+			   sun5i_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 49/63] clocksource/drivers/timer-ti-32k: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (47 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 48/63] clocksource/drivers/timer-sun5i: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 50/63] clocksource/drivers/timer-u300: " Daniel Lezcano
                   ` (13 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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-ti-32k.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clocksource/timer-ti-32k.c b/drivers/clocksource/timer-ti-32k.c
index 8518d9d..e4ad3c6e 100644
--- a/drivers/clocksource/timer-ti-32k.c
+++ b/drivers/clocksource/timer-ti-32k.c
@@ -88,14 +88,14 @@ static u64 notrace omap_32k_read_sched_clock(void)
 	return ti_32k_read_cycles(&ti_32k_timer.cs);
 }
 
-static void __init ti_32k_timer_init(struct device_node *np)
+static int __init ti_32k_timer_init(struct device_node *np)
 {
 	int ret;
 
 	ti_32k_timer.base = of_iomap(np, 0);
 	if (!ti_32k_timer.base) {
 		pr_err("Can't ioremap 32k timer base\n");
-		return;
+		return -ENXIO;
 	}
 
 	ti_32k_timer.counter = ti_32k_timer.base;
@@ -116,11 +116,13 @@ static void __init ti_32k_timer_init(struct device_node *np)
 	ret = clocksource_register_hz(&ti_32k_timer.cs, 32768);
 	if (ret) {
 		pr_err("32k_counter: can't register clocksource\n");
-		return;
+		return ret;
 	}
 
 	sched_clock_register(omap_32k_read_sched_clock, 32, 32768);
 	pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n");
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(ti_32k_timer, "ti,omap-counter32k",
+CLOCKSOURCE_OF_DECLARE_RET(ti_32k_timer, "ti,omap-counter32k",
 		ti_32k_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 50/63] clocksource/drivers/timer-u300: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (48 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 49/63] clocksource/drivers/timer-ti-32k: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-17 16:11   ` Linus Walleij
  2016-06-16 21:27 ` [PATCH V2 51/63] clocksource/drivers/versatile: " Daniel Lezcano
                   ` (12 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Linus Walleij, moderated list:ARM/U300 MACHINE...

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-u300.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/drivers/clocksource/timer-u300.c b/drivers/clocksource/timer-u300.c
index 1744b24..a6a0dec 100644
--- a/drivers/clocksource/timer-u300.c
+++ b/drivers/clocksource/timer-u300.c
@@ -359,27 +359,37 @@ static struct delay_timer u300_delay_timer;
 /*
  * This sets up the system timers, clock source and clock event.
  */
-static void __init u300_timer_init_of(struct device_node *np)
+static int __init u300_timer_init_of(struct device_node *np)
 {
 	unsigned int irq;
 	struct clk *clk;
 	unsigned long rate;
+	int ret;
 
 	u300_timer_base = of_iomap(np, 0);
-	if (!u300_timer_base)
-		panic("could not ioremap system timer\n");
+	if (!u300_timer_base) {
+		pr_err("could not ioremap system timer\n");
+		return -ENXIO;
+	}
 
 	/* Get the IRQ for the GP1 timer */
 	irq = irq_of_parse_and_map(np, 2);
-	if (!irq)
-		panic("no IRQ for system timer\n");
+	if (!irq) {
+		pr_err("no IRQ for system timer\n");
+		return -EINVAL;
+	}
 
 	pr_info("U300 GP1 timer @ base: %p, IRQ: %u\n", u300_timer_base, irq);
 
 	/* Clock the interrupt controller */
 	clk = of_clk_get(np, 0);
-	BUG_ON(IS_ERR(clk));
-	clk_prepare_enable(clk);
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		return ret;
+
 	rate = clk_get_rate(clk);
 
 	u300_clockevent_data.ticks_per_jiffy = DIV_ROUND_CLOSEST(rate, HZ);
@@ -410,7 +420,9 @@ static void __init u300_timer_init_of(struct device_node *np)
 		u300_timer_base + U300_TIMER_APP_RGPT1);
 
 	/* Set up the IRQ handler */
-	setup_irq(irq, &u300_timer_irq);
+	ret = setup_irq(irq, &u300_timer_irq);
+	if (ret)
+		return ret;
 
 	/* Reset the General Purpose timer 2 */
 	writel(U300_TIMER_APP_RGPT2_TIMER_RESET,
@@ -428,9 +440,12 @@ static void __init u300_timer_init_of(struct device_node *np)
 		u300_timer_base + U300_TIMER_APP_EGPT2);
 
 	/* Use general purpose timer 2 as clock source */
-	if (clocksource_mmio_init(u300_timer_base + U300_TIMER_APP_GPT2CC,
-			"GPT2", rate, 300, 32, clocksource_mmio_readl_up))
+	ret = clocksource_mmio_init(u300_timer_base + U300_TIMER_APP_GPT2CC,
+				    "GPT2", rate, 300, 32, clocksource_mmio_readl_up);
+	if (ret) {
 		pr_err("timer: failed to initialize U300 clock source\n");
+		return ret;
+	}
 
 	/* Configure and register the clockevent */
 	clockevents_config_and_register(&u300_clockevent_data.cevd, rate,
@@ -440,7 +455,8 @@ static void __init u300_timer_init_of(struct device_node *np)
 	 * TODO: init and register the rest of the timers too, they can be
 	 * used by hrtimers!
 	 */
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(u300_timer, "stericsson,u300-apptimer",
+CLOCKSOURCE_OF_DECLARE_RET(u300_timer, "stericsson,u300-apptimer",
 		       u300_timer_init_of);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 51/63] clocksource/drivers/versatile: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (49 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 50/63] clocksource/drivers/timer-u300: " Daniel Lezcano
@ 2016-06-16 21:27 ` 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
                   ` (11 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Liviu Dudau, Sudeep Holla, Lorenzo Pieralisi,
	moderated list:ARM/VERSATILE EXP...

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/versatile.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clocksource/versatile.c b/drivers/clocksource/versatile.c
index 0a26d3d..8daeffa 100644
--- a/drivers/clocksource/versatile.c
+++ b/drivers/clocksource/versatile.c
@@ -25,18 +25,20 @@ static u64 notrace versatile_sys_24mhz_read(void)
 	return readl(versatile_sys_24mhz);
 }
 
-static void __init versatile_sched_clock_init(struct device_node *node)
+static int __init versatile_sched_clock_init(struct device_node *node)
 {
 	void __iomem *base = of_iomap(node, 0);
 
 	if (!base)
-		return;
+		return -ENXIO;
 
 	versatile_sys_24mhz = base + SYS_24MHZ;
 
 	sched_clock_register(versatile_sys_24mhz_read, 32, 24000000);
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(vexpress, "arm,vexpress-sysreg",
+CLOCKSOURCE_OF_DECLARE_RET(vexpress, "arm,vexpress-sysreg",
 		       versatile_sched_clock_init);
-CLOCKSOURCE_OF_DECLARE(versatile, "arm,versatile-sysreg",
+CLOCKSOURCE_OF_DECLARE_RET(versatile, "arm,versatile-sysreg",
 		       versatile_sched_clock_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 52/63] clocksource/drivers/vf_pit_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (50 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 51/63] clocksource/drivers/versatile: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 53/63] clocksource/drivers/vt8500_timer: " Daniel Lezcano
                   ` (10 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/vf_pit_timer.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/clocksource/vf_pit_timer.c b/drivers/clocksource/vf_pit_timer.c
index a0e6c68..ca4dff4 100644
--- a/drivers/clocksource/vf_pit_timer.c
+++ b/drivers/clocksource/vf_pit_timer.c
@@ -156,15 +156,18 @@ static int __init pit_clockevent_init(unsigned long rate, int irq)
 	return 0;
 }
 
-static void __init pit_timer_init(struct device_node *np)
+static int __init pit_timer_init(struct device_node *np)
 {
 	struct clk *pit_clk;
 	void __iomem *timer_base;
 	unsigned long clk_rate;
-	int irq;
+	int irq, ret;
 
 	timer_base = of_iomap(np, 0);
-	BUG_ON(!timer_base);
+	if (!timer_base) {
+		pr_err("Failed to iomap");
+		return -ENXIO;
+	}
 
 	/*
 	 * PIT0 and PIT1 can be chained to build a 64-bit timer,
@@ -175,12 +178,16 @@ static void __init pit_timer_init(struct device_node *np)
 	clkevt_base = timer_base + PITn_OFFSET(3);
 
 	irq = irq_of_parse_and_map(np, 0);
-	BUG_ON(irq <= 0);
+	if (irq <= 0)
+		return -EINVAL;
 
 	pit_clk = of_clk_get(np, 0);
-	BUG_ON(IS_ERR(pit_clk));
+	if (IS_ERR(pit_clk))
+		return PTR_ERR(pit_clk);
 
-	BUG_ON(clk_prepare_enable(pit_clk));
+	ret = clk_prepare_enable(pit_clk);
+	if (ret)
+		return ret;
 
 	clk_rate = clk_get_rate(pit_clk);
 	cycle_per_jiffy = clk_rate / (HZ);
@@ -188,8 +195,10 @@ static void __init pit_timer_init(struct device_node *np)
 	/* enable the pit module */
 	__raw_writel(~PITMCR_MDIS, timer_base + PITMCR);
 
-	BUG_ON(pit_clocksource_init(clk_rate));
+	ret = pit_clocksource_init(clk_rate);
+	if (ret)
+		return ret;
 
-	pit_clockevent_init(clk_rate, irq);
+	return pit_clockevent_init(clk_rate, irq);
 }
-CLOCKSOURCE_OF_DECLARE(vf610, "fsl,vf610-pit", pit_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(vf610, "fsl,vf610-pit", pit_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 53/63] clocksource/drivers/vt8500_timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (51 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 52/63] clocksource/drivers/vf_pit_timer: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 54/63] clocksource/drivers/zevio-timer: " Daniel Lezcano
                   ` (9 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Tony Prisk, moderated list:ARM/VT8500 ARM AR...

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/vt8500_timer.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/vt8500_timer.c b/drivers/clocksource/vt8500_timer.c
index ddb4092..1bc8707 100644
--- a/drivers/clocksource/vt8500_timer.c
+++ b/drivers/clocksource/vt8500_timer.c
@@ -121,38 +121,48 @@ static struct irqaction irq = {
 	.dev_id  = &clockevent,
 };
 
-static void __init vt8500_timer_init(struct device_node *np)
+static int __init vt8500_timer_init(struct device_node *np)
 {
-	int timer_irq;
+	int timer_irq, ret;
 
 	regbase = of_iomap(np, 0);
 	if (!regbase) {
 		pr_err("%s: Missing iobase description in Device Tree\n",
 								__func__);
-		return;
+		return -ENXIO;
 	}
+
 	timer_irq = irq_of_parse_and_map(np, 0);
 	if (!timer_irq) {
 		pr_err("%s: Missing irq description in Device Tree\n",
 								__func__);
-		return;
+		return -EINVAL;
 	}
 
 	writel(1, regbase + TIMER_CTRL_VAL);
 	writel(0xf, regbase + TIMER_STATUS_VAL);
 	writel(~0, regbase + TIMER_MATCH_VAL);
 
-	if (clocksource_register_hz(&clocksource, VT8500_TIMER_HZ))
+	ret = clocksource_register_hz(&clocksource, VT8500_TIMER_HZ);
+	if (ret) {
 		pr_err("%s: vt8500_timer_init: clocksource_register failed for %s\n",
-					__func__, clocksource.name);
+		       __func__, clocksource.name);
+		return ret;
+	}
 
 	clockevent.cpumask = cpumask_of(0);
 
-	if (setup_irq(timer_irq, &irq))
+	ret = setup_irq(timer_irq, &irq);
+	if (ret) {
 		pr_err("%s: setup_irq failed for %s\n", __func__,
 							clockevent.name);
+		return ret;
+	}
+
 	clockevents_config_and_register(&clockevent, VT8500_TIMER_HZ,
 					MIN_OSCR_DELTA * 2, 0xf0000000);
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(vt8500, "via,vt8500-timer", vt8500_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(vt8500, "via,vt8500-timer", vt8500_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 54/63] clocksource/drivers/zevio-timer: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (52 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 53/63] clocksource/drivers/vt8500_timer: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 55/63] clocksource/drivers/timer-sp804: " Daniel Lezcano
                   ` (8 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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/zevio-timer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clocksource/zevio-timer.c b/drivers/clocksource/zevio-timer.c
index ceaa613..cb4cf056 100644
--- a/drivers/clocksource/zevio-timer.c
+++ b/drivers/clocksource/zevio-timer.c
@@ -210,9 +210,9 @@ error_free:
 	return ret;
 }
 
-static void __init zevio_timer_init(struct device_node *node)
+static int __init zevio_timer_init(struct device_node *node)
 {
-	BUG_ON(zevio_timer_add(node));
+	return zevio_timer_add(node);
 }
 
-CLOCKSOURCE_OF_DECLARE(zevio_timer, "lsi,zevio-timer", zevio_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(zevio_timer, "lsi,zevio-timer", zevio_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 55/63] clocksource/drivers/timer-sp804: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (53 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 54/63] clocksource/drivers/zevio-timer: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 56/63] clocksource/drivers/microblaze: " Daniel Lezcano
                   ` (7 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel

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>
---
 include/clocksource/timer-sp804.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/clocksource/timer-sp804.h b/include/clocksource/timer-sp804.h
index 1f8a1ca..7654d71 100644
--- a/include/clocksource/timer-sp804.h
+++ b/include/clocksource/timer-sp804.h
@@ -3,10 +3,10 @@
 
 struct clk;
 
-void __sp804_clocksource_and_sched_clock_init(void __iomem *,
-					      const char *, struct clk *, int);
-void __sp804_clockevents_init(void __iomem *, unsigned int,
-			      struct clk *, const char *);
+int __sp804_clocksource_and_sched_clock_init(void __iomem *,
+					     const char *, struct clk *, int);
+int __sp804_clockevents_init(void __iomem *, unsigned int,
+			     struct clk *, const char *);
 void sp804_timer_disable(void __iomem *);
 
 static inline void sp804_clocksource_init(void __iomem *base, const char *name)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 56/63] clocksource/drivers/microblaze: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (54 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 55/63] clocksource/drivers/timer-sp804: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 57/63] clocksource/drivers/ralink: " Daniel Lezcano
                   ` (6 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel, Michal Simek, Viresh Kumar

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

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 57/63] clocksource/drivers/ralink: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (55 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 56/63] clocksource/drivers/microblaze: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-17  8:54   ` John Crispin
  2016-06-16 21:27 ` [PATCH V2 58/63] clocksource/drivers/nios2: " Daniel Lezcano
                   ` (5 subsequent siblings)
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, John Crispin, Ralf Baechle, open list:RALINK MIPS ARCHI...

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/mips/ralink/cevt-rt3352.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/arch/mips/ralink/cevt-rt3352.c b/arch/mips/ralink/cevt-rt3352.c
index 3ad0b07..f2d3c79 100644
--- a/arch/mips/ralink/cevt-rt3352.c
+++ b/arch/mips/ralink/cevt-rt3352.c
@@ -117,11 +117,13 @@ static int systick_set_oneshot(struct clock_event_device *evt)
 	return 0;
 }
 
-static void __init ralink_systick_init(struct device_node *np)
+static int __init ralink_systick_init(struct device_node *np)
 {
+	int ret;
+
 	systick.membase = of_iomap(np, 0);
 	if (!systick.membase)
-		return;
+		return -ENXIO;
 
 	systick_irqaction.name = np->name;
 	systick.dev.name = np->name;
@@ -131,16 +133,21 @@ static void __init ralink_systick_init(struct device_node *np)
 	systick.dev.irq = irq_of_parse_and_map(np, 0);
 	if (!systick.dev.irq) {
 		pr_err("%s: request_irq failed", np->name);
-		return;
+		return -EINVAL;
 	}
 
-	clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
-			SYSTICK_FREQ, 301, 16, clocksource_mmio_readl_up);
+	ret = clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
+				    SYSTICK_FREQ, 301, 16,
+				    clocksource_mmio_readl_up);
+	if (ret)
+		return ret;
 
 	clockevents_register_device(&systick.dev);
 
 	pr_info("%s: running - mult: %d, shift: %d\n",
 			np->name, systick.dev.mult, systick.dev.shift);
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(systick, "ralink,cevt-systick", ralink_systick_init);
+CLOCKSOURCE_OF_DECLARE_RET(systick, "ralink,cevt-systick", ralink_systick_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 58/63] clocksource/drivers/nios2: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (56 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 57/63] clocksource/drivers/ralink: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 59/63] clocksource/drivers/smp_twd: " Daniel Lezcano
                   ` (4 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Ley Foon Tan, Rafael J. Wysocki, Viresh Kumar,
	Marc Zyngier, moderated list:NIOS2 ARCHITECTURE

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/nios2/kernel/time.c | 69 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 48 insertions(+), 21 deletions(-)

diff --git a/arch/nios2/kernel/time.c b/arch/nios2/kernel/time.c
index e835dda..9fa7739 100644
--- a/arch/nios2/kernel/time.c
+++ b/arch/nios2/kernel/time.c
@@ -206,15 +206,21 @@ irqreturn_t timer_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static void __init nios2_timer_get_base_and_freq(struct device_node *np,
+static int __init nios2_timer_get_base_and_freq(struct device_node *np,
 				void __iomem **base, u32 *freq)
 {
 	*base = of_iomap(np, 0);
-	if (!*base)
-		panic("Unable to map reg for %s\n", np->name);
+	if (!*base) {
+		pr_crit("Unable to map reg for %s\n", np->name);
+		return -ENXIO;
+	}
+
+	if (of_property_read_u32(np, "clock-frequency", freq)) {
+		pr_crit("Unable to get %s clock frequency\n", np->name);
+		return -EINVAL;
+	}
 
-	if (of_property_read_u32(np, "clock-frequency", freq))
-		panic("Unable to get %s clock frequency\n", np->name);
+	return 0;
 }
 
 static struct nios2_clockevent_dev nios2_ce = {
@@ -231,17 +237,21 @@ static struct nios2_clockevent_dev nios2_ce = {
 	},
 };
 
-static __init void nios2_clockevent_init(struct device_node *timer)
+static __init int nios2_clockevent_init(struct device_node *timer)
 {
 	void __iomem *iobase;
 	u32 freq;
-	int irq;
+	int irq, ret;
 
-	nios2_timer_get_base_and_freq(timer, &iobase, &freq);
+	ret = nios2_timer_get_base_and_freq(timer, &iobase, &freq);
+	if (ret)
+		return ret;
 
 	irq = irq_of_parse_and_map(timer, 0);
-	if (!irq)
-		panic("Unable to parse timer irq\n");
+	if (!irq) {
+		pr_crit("Unable to parse timer irq\n");
+		return -EINVAL;
+	}
 
 	nios2_ce.timer.base = iobase;
 	nios2_ce.timer.freq = freq;
@@ -253,25 +263,35 @@ static __init void nios2_clockevent_init(struct device_node *timer)
 	/* clear pending interrupt */
 	timer_writew(&nios2_ce.timer, 0, ALTERA_TIMER_STATUS_REG);
 
-	if (request_irq(irq, timer_interrupt, IRQF_TIMER, timer->name,
-		&nios2_ce.ced))
-		panic("Unable to setup timer irq\n");
+	ret = request_irq(irq, timer_interrupt, IRQF_TIMER, timer->name,
+			  &nios2_ce.ced);
+	if (ret) {
+		pr_crit("Unable to setup timer irq\n");
+		return ret;
+	}
 
 	clockevents_config_and_register(&nios2_ce.ced, freq, 1, ULONG_MAX);
+
+	return 0;
 }
 
-static __init void nios2_clocksource_init(struct device_node *timer)
+static __init int nios2_clocksource_init(struct device_node *timer)
 {
 	unsigned int ctrl;
 	void __iomem *iobase;
 	u32 freq;
+	int ret;
 
-	nios2_timer_get_base_and_freq(timer, &iobase, &freq);
+	ret = nios2_timer_get_base_and_freq(timer, &iobase, &freq);
+	if (ret)
+		return ret;
 
 	nios2_cs.timer.base = iobase;
 	nios2_cs.timer.freq = freq;
 
-	clocksource_register_hz(&nios2_cs.cs, freq);
+	ret = clocksource_register_hz(&nios2_cs.cs, freq);
+	if (ret)
+		return ret;
 
 	timer_writew(&nios2_cs.timer, USHRT_MAX, ALTERA_TIMER_PERIODL_REG);
 	timer_writew(&nios2_cs.timer, USHRT_MAX, ALTERA_TIMER_PERIODH_REG);
@@ -282,6 +302,8 @@ static __init void nios2_clocksource_init(struct device_node *timer)
 
 	/* Calibrate the delay loop directly */
 	lpj_fine = freq / HZ;
+
+	return 0;
 }
 
 /*
@@ -289,22 +311,25 @@ static __init void nios2_clocksource_init(struct device_node *timer)
  * more instances, the second one gets used as clocksource and all
  * others are unused.
 */
-static void __init nios2_time_init(struct device_node *timer)
+static int __init nios2_time_init(struct device_node *timer)
 {
 	static int num_called;
+	int ret;
 
 	switch (num_called) {
 	case 0:
-		nios2_clockevent_init(timer);
+		ret = nios2_clockevent_init(timer);
 		break;
 	case 1:
-		nios2_clocksource_init(timer);
+		ret = nios2_clocksource_init(timer);
 		break;
 	default:
 		break;
 	}
 
 	num_called++;
+
+	return ret;
 }
 
 void read_persistent_clock(struct timespec *ts)
@@ -321,10 +346,12 @@ void __init time_init(void)
 	for_each_compatible_node(np, NULL,  ALTR_TIMER_COMPATIBLE)
 		count++;
 
-	if (count < 2)
+	if (count < 2) {
 		panic("%d timer is found, it needs 2 timers in system\n", count);
 
 	clocksource_probe();
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(nios2_timer, ALTR_TIMER_COMPATIBLE, nios2_time_init);
+CLOCKSOURCE_OF_DECLARE_RET(nios2_timer, ALTR_TIMER_COMPATIBLE, nios2_time_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 59/63] clocksource/drivers/smp_twd: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (57 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 58/63] clocksource/drivers/nios2: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 60/63] clocksource/drivers/nps: " Daniel Lezcano
                   ` (3 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Russell King, Viresh Kumar, Marc Gonzalez,
	Felipe Balbi, moderated list:ARM PORT

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/arm/kernel/smp_twd.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
index 1bfa7a7..2b24be4 100644
--- a/arch/arm/kernel/smp_twd.c
+++ b/arch/arm/kernel/smp_twd.c
@@ -390,7 +390,7 @@ int __init twd_local_timer_register(struct twd_local_timer *tlt)
 }
 
 #ifdef CONFIG_OF
-static void __init twd_local_timer_of_register(struct device_node *np)
+static int __init twd_local_timer_of_register(struct device_node *np)
 {
 	int err;
 
@@ -410,8 +410,9 @@ static void __init twd_local_timer_of_register(struct device_node *np)
 
 out:
 	WARN(err, "twd_local_timer_of_register failed (%d)\n", err);
+	return err;
 }
-CLOCKSOURCE_OF_DECLARE(arm_twd_a9, "arm,cortex-a9-twd-timer", twd_local_timer_of_register);
-CLOCKSOURCE_OF_DECLARE(arm_twd_a5, "arm,cortex-a5-twd-timer", twd_local_timer_of_register);
-CLOCKSOURCE_OF_DECLARE(arm_twd_11mp, "arm,arm11mp-twd-timer", twd_local_timer_of_register);
+CLOCKSOURCE_OF_DECLARE_RET(arm_twd_a9, "arm,cortex-a9-twd-timer", twd_local_timer_of_register);
+CLOCKSOURCE_OF_DECLARE_RET(arm_twd_a5, "arm,cortex-a5-twd-timer", twd_local_timer_of_register);
+CLOCKSOURCE_OF_DECLARE_RET(arm_twd_11mp, "arm,arm11mp-twd-timer", twd_local_timer_of_register);
 #endif
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 60/63] clocksource/drivers/nps: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (58 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 59/63] clocksource/drivers/smp_twd: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-16 21:27 ` [PATCH V2 61/63] clocksource/drivers/arc: " Daniel Lezcano
                   ` (2 subsequent siblings)
  62 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel, Arnd Bergmann

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>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/clocksource/timer-nps.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/timer-nps.c b/drivers/clocksource/timer-nps.c
index d461089..b5c7b2b 100644
--- a/drivers/clocksource/timer-nps.c
+++ b/drivers/clocksource/timer-nps.c
@@ -55,8 +55,8 @@ static cycle_t nps_clksrc_read(struct clocksource *clksrc)
 	return (cycle_t)ioread32be(nps_msu_reg_low_addr[cluster]);
 }
 
-static void __init nps_setup_clocksource(struct device_node *node,
-					 struct clk *clk)
+static int __init nps_setup_clocksource(struct device_node *node,
+					struct clk *clk)
 {
 	int ret, cluster;
 
@@ -68,7 +68,7 @@ static void __init nps_setup_clocksource(struct device_node *node,
 	ret = clk_prepare_enable(clk);
 	if (ret) {
 		pr_err("Couldn't enable parent clock\n");
-		return;
+		return ret;
 	}
 
 	nps_timer_rate = clk_get_rate(clk);
@@ -79,20 +79,22 @@ static void __init nps_setup_clocksource(struct device_node *node,
 		pr_err("Couldn't register clock source.\n");
 		clk_disable_unprepare(clk);
 	}
+
+	return ret;
 }
 
-static void __init nps_timer_init(struct device_node *node)
+static int __init nps_timer_init(struct device_node *node)
 {
 	struct clk *clk;
 
 	clk = of_clk_get(node, 0);
 	if (IS_ERR(clk)) {
 		pr_err("Can't get timer clock.\n");
-		return;
+		return PTR_ERR(clk);
 	}
 
-	nps_setup_clocksource(node, clk);
+	return nps_setup_clocksource(node, clk);
 }
 
-CLOCKSOURCE_OF_DECLARE(ezchip_nps400_clksrc, "ezchip,nps400-timer",
-		       nps_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(ezchip_nps400_clksrc, "ezchip,nps400-timer",
+			   nps_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 61/63] clocksource/drivers/arc: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (59 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 60/63] clocksource/drivers/nps: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-17  8:59   ` Vineet Gupta
  2016-06-16 21:27 ` [PATCH V2 62/63] clocksource/drivers/oxnas-rps: " Daniel Lezcano
       [not found] ` <1466112442-31105-64-git-send-email-daniel.lezcano@linaro.org>
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Vineet Gupta, Noam Camus, Viresh Kumar,
	Adam Buchbinder, open list:SYNOPSYS ARC ARCH...

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/arc/kernel/time.c | 69 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 27 deletions(-)

diff --git a/arch/arc/kernel/time.c b/arch/arc/kernel/time.c
index 4549ab2..36110cd 100644
--- a/arch/arc/kernel/time.c
+++ b/arch/arc/kernel/time.c
@@ -116,21 +116,21 @@ static struct clocksource arc_counter_gfrc = {
 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static void __init arc_cs_setup_gfrc(struct device_node *node)
+static int __init arc_cs_setup_gfrc(struct device_node *node)
 {
 	int exists = cpuinfo_arc700[0].extn.gfrc;
 	int ret;
 
 	if (WARN(!exists, "Global-64-bit-Ctr clocksource not detected"))
-		return;
+		return -ENXIO;
 
 	ret = arc_get_timer_clk(node);
 	if (ret)
-		return;
+		return ret;
 
-	clocksource_register_hz(&arc_counter_gfrc, arc_timer_freq);
+	return clocksource_register_hz(&arc_counter_gfrc, arc_timer_freq);
 }
-CLOCKSOURCE_OF_DECLARE(arc_gfrc, "snps,archs-timer-gfrc", arc_cs_setup_gfrc);
+CLOCKSOURCE_OF_DECLARE_RET(arc_gfrc, "snps,archs-timer-gfrc", arc_cs_setup_gfrc);
 
 #endif
 
@@ -172,27 +172,27 @@ static struct clocksource arc_counter_rtc = {
 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static void __init arc_cs_setup_rtc(struct device_node *node)
+static int __init arc_cs_setup_rtc(struct device_node *node)
 {
 	int exists = cpuinfo_arc700[smp_processor_id()].extn.rtc;
 	int ret;
 
 	if (WARN(!exists, "Local-64-bit-Ctr clocksource not detected"))
-		return;
+		return -ENXIO;
 
 	/* Local to CPU hence not usable in SMP */
 	if (WARN(IS_ENABLED(CONFIG_SMP), "Local-64-bit-Ctr not usable in SMP"))
-		return;
+		return -EINVAL;
 
 	ret = arc_get_timer_clk(node);
 	if (ret)
-		return;
+		return ret;
 
 	write_aux_reg(AUX_RTC_CTRL, 1);
 
-	clocksource_register_hz(&arc_counter_rtc, arc_timer_freq);
+	return clocksource_register_hz(&arc_counter_rtc, arc_timer_freq);
 }
-CLOCKSOURCE_OF_DECLARE(arc_rtc, "snps,archs-timer-rtc", arc_cs_setup_rtc);
+CLOCKSOURCE_OF_DECLARE_RET(arc_rtc, "snps,archs-timer-rtc", arc_cs_setup_rtc);
 
 #endif
 
@@ -213,23 +213,23 @@ static struct clocksource arc_counter_timer1 = {
 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static void __init arc_cs_setup_timer1(struct device_node *node)
+static int __init arc_cs_setup_timer1(struct device_node *node)
 {
 	int ret;
 
 	/* Local to CPU hence not usable in SMP */
 	if (IS_ENABLED(CONFIG_SMP))
-		return;
+		return 0;
 
 	ret = arc_get_timer_clk(node);
 	if (ret)
-		return;
+		return ret;
 
 	write_aux_reg(ARC_REG_TIMER1_LIMIT, ARC_TIMER_MAX);
 	write_aux_reg(ARC_REG_TIMER1_CNT, 0);
 	write_aux_reg(ARC_REG_TIMER1_CTRL, TIMER_CTRL_NH);
 
-	clocksource_register_hz(&arc_counter_timer1, arc_timer_freq);
+	return clocksource_register_hz(&arc_counter_timer1, arc_timer_freq);
 }
 
 /********** Clock Event Device *********/
@@ -324,20 +324,28 @@ static struct notifier_block arc_timer_cpu_nb = {
 /*
  * clockevent setup for boot CPU
  */
-static void __init arc_clockevent_setup(struct device_node *node)
+static int __init arc_clockevent_setup(struct device_node *node)
 {
 	struct clock_event_device *evt = this_cpu_ptr(&arc_clockevent_device);
 	int ret;
 
-	register_cpu_notifier(&arc_timer_cpu_nb);
+	ret = register_cpu_notifier(&arc_timer_cpu_nb);
+	if (ret) {
+		pr_err("Failed to register cpu notifier");
+		return ret;
+	}
 
 	arc_timer_irq = irq_of_parse_and_map(node, 0);
-	if (arc_timer_irq <= 0)
-		panic("clockevent: missing irq");
+	if (arc_timer_irq <= 0) {
+		pr_err("clockevent: missing irq");
+		return -EINVAL;
+	}
 
 	ret = arc_get_timer_clk(node);
-	if (ret)
-		panic("clockevent: missing clk");
+	if (ret) {
+		pr_err("clockevent: missing clk");
+		return ret;
+	}
 
 	evt->irq = arc_timer_irq;
 	evt->cpumask = cpumask_of(smp_processor_id());
@@ -347,24 +355,31 @@ static void __init arc_clockevent_setup(struct device_node *node)
 	/* Needs apriori irq_set_percpu_devid() done in intc map function */
 	ret = request_percpu_irq(arc_timer_irq, timer_irq_handler,
 				 "Timer0 (per-cpu-tick)", evt);
-	if (ret)
-		panic("clockevent: unable to request irq\n");
+	if (ret) {
+		pr_err("clockevent: unable to request irq\n");
+		returnr ret;
+	}
 
 	enable_percpu_irq(arc_timer_irq, 0);
+
+	return 0;
 }
 
-static void __init arc_of_timer_init(struct device_node *np)
+static int __init arc_of_timer_init(struct device_node *np)
 {
 	static int init_count = 0;
+	int ret;
 
 	if (!init_count) {
 		init_count = 1;
-		arc_clockevent_setup(np);
+		ret = arc_clockevent_setup(np);
 	} else {
-		arc_cs_setup_timer1(np);
+		ret = arc_cs_setup_timer1(np);
 	}
+
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(arc_clkevt, "snps,arc-timer", arc_of_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(arc_clkevt, "snps,arc-timer", arc_of_timer_init);
 
 /*
  * Called from start_kernel() - boot CPU only
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V2 62/63] clocksource/drivers/oxnas-rps: Convert init function to return error
  2016-06-16 21:26 [PATCH V2 00/63] clocksource/drivers/clksrc-of: Improve error handling Daniel Lezcano
                   ` (60 preceding siblings ...)
  2016-06-16 21:27 ` [PATCH V2 61/63] clocksource/drivers/arc: " Daniel Lezcano
@ 2016-06-16 21:27 ` Daniel Lezcano
  2016-06-17  6:58   ` Neil Armstrong
       [not found] ` <1466112442-31105-64-git-send-email-daniel.lezcano@linaro.org>
  62 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-16 21:27 UTC (permalink / raw)
  To: daniel.lezcano, tglx
  Cc: linux-kernel, Neil Armstrong, moderated list:ARM/OXNAS platfor...

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-oxnas-rps.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/clocksource/timer-oxnas-rps.c b/drivers/clocksource/timer-oxnas-rps.c
index c002e99..0d99f40 100644
--- a/drivers/clocksource/timer-oxnas-rps.c
+++ b/drivers/clocksource/timer-oxnas-rps.c
@@ -220,32 +220,37 @@ static int __init oxnas_rps_clocksource_init(struct oxnas_rps_timer *rps)
 	return 0;
 }
 
-static void __init oxnas_rps_timer_init(struct device_node *np)
+static int __init oxnas_rps_timer_init(struct device_node *np)
 {
 	struct oxnas_rps_timer *rps;
 	void __iomem *base;
 	int ret;
 
 	rps = kzalloc(sizeof(*rps), GFP_KERNEL);
-	if (!rps) {
-		pr_err("Failed to allocate rps structure\n");
-		return;
-	}
+	if (!rps)
+		return -ENOMEM;
 
 	rps->clk = of_clk_get(np, 0);
-	if (WARN_ON(IS_ERR(rps->clk)))
+	if (IS_ERR(rps->clk)) {
+		ret = PTR_ERR(rps->clk);
 		goto err_alloc;
+	}
 
-	if (WARN_ON(clk_prepare_enable(rps->clk)))
+	ret = clk_prepare_enable(rps->clk);
+	if (ret)
 		goto err_clk;
 
 	base = of_iomap(np, 0);
-	if (WARN_ON(!base))
+	if (!base) {
+		ret = -ENXIO;
 		goto err_clk_prepare;
+	}
 
 	rps->irq = irq_of_parse_and_map(np, 0);
-	if (WARN_ON(rps->irq < 0))
+	if (rps->irq < 0) {
+		ret = -EINVAL;
 		goto err_iomap;
+	}
 
 	rps->clkevt_base = base + TIMER1_REG_OFFSET;
 	rps->clksrc_base = base + TIMER2_REG_OFFSET;
@@ -261,7 +266,7 @@ static void __init oxnas_rps_timer_init(struct device_node *np)
 	ret = request_irq(rps->irq, oxnas_rps_timer_irq,
 			  IRQF_TIMER | IRQF_IRQPOLL,
 			  "rps-timer", rps);
-	if (WARN_ON(ret))
+	if (ret)
 		goto err_iomap;
 
 	ret = oxnas_rps_clocksource_init(rps);
@@ -272,7 +277,7 @@ static void __init oxnas_rps_timer_init(struct device_node *np)
 	if (ret)
 		goto err_irqreq;
 
-	return;
+	return 0;
 
 err_irqreq:
 	free_irq(rps->irq, rps);
@@ -284,7 +289,9 @@ err_clk:
 	clk_put(rps->clk);
 err_alloc:
 	kfree(rps);
+
+	return ret;
 }
 
-CLOCKSOURCE_OF_DECLARE(ox810se_rps,
-		       "oxsemi,ox810se-rps-timer", oxnas_rps_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(ox810se_rps,
+			   "oxsemi,ox810se-rps-timer", oxnas_rps_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 07/63] clocksource/drivers/cadence_ttc: Convert init function to return error
  2016-06-16 21:26 ` [PATCH V2 07/63] clocksource/drivers/cadence_ttc: " Daniel Lezcano
@ 2016-06-16 21:43   ` Sören Brinkmann
  0 siblings, 0 replies; 112+ messages in thread
From: Sören Brinkmann @ 2016-06-16 21:43 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: tglx, linux-kernel, Michal Simek, moderated list:ARM/ZYNQ ARCHITEC...

On Thu, 2016-06-16 at 23:26:26 +0200, Daniel Lezcano wrote:
> 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: Sören Brinkmann <soren.brinkmann@xilinx.com>

	Sören

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 11/63] clocksource/drivers/digitcolor: Convert init function to return error
  2016-06-16 21:26 ` [PATCH V2 11/63] clocksource/drivers/digitcolor: " Daniel Lezcano
@ 2016-06-17  3:15   ` Baruch Siach
  0 siblings, 0 replies; 112+ messages in thread
From: Baruch Siach @ 2016-06-17  3:15 UTC (permalink / raw)
  To: Daniel Lezcano; +Cc: tglx, linux-kernel, moderated list:ARM/CONEXANT DIGI...

Hi Daniel,

On Thu, Jun 16, 2016 at 11:26:30PM +0200, Daniel Lezcano wrote:
> 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>

It would be nice to have at least LAKL on Cc of the cover letter as well, so 
we can get the big picture. I found it at 
http://article.gmane.org/gmane.linux.kernel/2246137.

But anyway, for this and the final patch:

Acked-by: Baruch Siach <baruch@tkos.co.il>

Thanks,
baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 25/63] clocksource/drivers/mxs_timer: Convert init function to return error
  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
  1 sibling, 1 reply; 112+ messages in thread
From: Uwe Kleine-König @ 2016-06-17  6:33 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: tglx, Lorenzo Pieralisi, Liviu Dudau, linux-kernel,
	moderated list:ARM/VERSATILE EXP...,
	Sudeep Holla, kernel

Hello,

On Thu, Jun 16, 2016 at 11:26:44PM +0200, Daniel Lezcano wrote:
> 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/mps2-timer.c | 10 ++++++----
>  drivers/clocksource/mxs_timer.c  |  2 +-

Did you forget to split here? The changelog only mentions mxs.

>  2 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/clocksource/mps2-timer.c b/drivers/clocksource/mps2-timer.c
> index 3d33a5e..c303fa9 100644
> --- a/drivers/clocksource/mps2-timer.c
> +++ b/drivers/clocksource/mps2-timer.c
> @@ -250,7 +250,7 @@ out:
>  	return ret;
>  }
>  
> -static void __init mps2_timer_init(struct device_node *np)
> +static int __init mps2_timer_init(struct device_node *np)
>  {
>  	static int has_clocksource, has_clockevent;
>  	int ret;
> @@ -259,7 +259,7 @@ static void __init mps2_timer_init(struct device_node *np)
>  		ret = mps2_clocksource_init(np);
>  		if (!ret) {
>  			has_clocksource = 1;
> -			return;
> +			return 0;
>  		}
>  	}
>  
> @@ -267,9 +267,11 @@ static void __init mps2_timer_init(struct device_node *np)
>  		ret = mps2_clockevent_init(np);
>  		if (!ret) {
>  			has_clockevent = 1;
> -			return;
> +			return 0;
>  		}
>  	}
> +
> +	return 0;
>  }
>  
> -CLOCKSOURCE_OF_DECLARE(mps2_timer, "arm,mps2-timer", mps2_timer_init);
> +CLOCKSOURCE_OF_DECLARE_RET(mps2_timer, "arm,mps2-timer", mps2_timer_init);
> diff --git a/drivers/clocksource/mxs_timer.c b/drivers/clocksource/mxs_timer.c
> index f5ce296..16cf53b 100644
> --- a/drivers/clocksource/mxs_timer.c
> +++ b/drivers/clocksource/mxs_timer.c
> @@ -226,7 +226,7 @@ static int __init mxs_clocksource_init(struct clk *timer_clk)
>  	return 0;
>  }
>  
> -static void __init mxs_timer_init(struct device_node *np)
> +static int __init mxs_timer_init(struct device_node *np)
>  {
>  	struct clk *timer_clk;
>  	int irq;

I didn't try, but I expect that the "return;" a few lines below results
in at least a warning and the compiler also warns about a missing return
at the end of the function.

Best regards
Uwe


-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 35/63] clocksource/drivers/time-lpc32xx: Convert init function to return error
  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
  0 siblings, 1 reply; 112+ messages in thread
From: Uwe Kleine-König @ 2016-06-17  6:52 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: tglx, moderated list:ARM/ENERGY MICRO...,
	linux-kernel, Uwe Kleine-König

Hello Daniel,

$Subject ~= s/lpc32xx/efm32/

On Thu, Jun 16, 2016 at 11:26:54PM +0200, Daniel Lezcano wrote:
> 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

These are both wrong for efm32. It doesn't panic and doesn't print an
error message (obviously the "let the caller unaware" part is true).

> 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.

Apart from the comment below the error handling is already fine in this
driver.

> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
>  drivers/clocksource/time-efm32.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/clocksource/time-efm32.c b/drivers/clocksource/time-efm32.c
> index b06e4c2..b71ffc6 100644
> --- a/drivers/clocksource/time-efm32.c
> +++ b/drivers/clocksource/time-efm32.c
> @@ -233,7 +233,11 @@ static int __init efm32_clockevent_init(struct device_node *np)
>  					DIV_ROUND_CLOSEST(rate, 1024),
>  					0xf, 0xffff);
>  
> -	setup_irq(irq, &efm32_clock_event_irq);
> +	ret = setup_irq(irq, &efm32_clock_event_irq);
> +	if (ret) {
> +		pr_err("Failed setup irq");
> +		goto err_get_irq;

I would prefer to introduce another label "err_setup_irq" at the same
place as err_get_irq and use it here.

> +	}
>  
>  	return 0;
>  

Best regards
Uwe


-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 62/63] clocksource/drivers/oxnas-rps: Convert init function to return error
  2016-06-16 21:27 ` [PATCH V2 62/63] clocksource/drivers/oxnas-rps: " Daniel Lezcano
@ 2016-06-17  6:58   ` Neil Armstrong
  0 siblings, 0 replies; 112+ messages in thread
From: Neil Armstrong @ 2016-06-17  6:58 UTC (permalink / raw)
  To: Daniel Lezcano, tglx; +Cc: linux-kernel, moderated list:ARM/OXNAS platfor...

On 06/16/2016 11:27 PM, Daniel Lezcano wrote:
> 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-oxnas-rps.c | 33 ++++++++++++++++++++-------------
>  1 file changed, 20 insertions(+), 13 deletions(-)

Acked-by: Neil Armstrong <narmstrong@baylibre.com>

Thanks,
Neil

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 33/63] clocksource/drivers/time-armada-370-xp: Convert init function to return error
  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
  0 siblings, 2 replies; 112+ messages in thread
From: Jon Hunter @ 2016-06-17  7:21 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, Stephen Warren, Thierry Reding, Alexandre Courbot,
	open list:TEGRA ARCHITECTUR...


On 16/06/16 22:26, Daniel Lezcano wrote:
> 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/tegra20_timer.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)

The $subject does not appear to match with the driver you are modifying
here.

Cheers
Jon

-- 
nvpublic

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 33/63] clocksource/drivers/time-armada-370-xp: Convert init function to return error
  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
  1 sibling, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-17  8:09 UTC (permalink / raw)
  To: Jon Hunter, tglx
  Cc: linux-kernel, Stephen Warren, Thierry Reding, Alexandre Courbot,
	open list:TEGRA ARCHITECTUR...

On 06/17/2016 09:21 AM, Jon Hunter wrote:
>
> On 16/06/16 22:26, Daniel Lezcano wrote:
>> 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/tegra20_timer.c | 28 ++++++++++++++++------------
>>   1 file changed, 16 insertions(+), 12 deletions(-)
>
> The $subject does not appear to match with the driver you are modifying
> here.

Ah, crap. I introduced a shift somewhere in the patchset. Fixed.

Thanks !

   -- Daniel


-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH V3] clocksource/drivers/time-efm32: Convert init function to return error
  2016-06-17  6:52   ` Uwe Kleine-König
@ 2016-06-17  8:44     ` Daniel Lezcano
  2016-06-17  9:46       ` Uwe Kleine-König
  0 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-17  8:44 UTC (permalink / raw)
  To: daniel.lezcano, tglx, kernel; +Cc: linux-kernel, linux-arm-kernel

The init functions do not return any error and let the caller unaware of
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-efm32.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/clocksource/time-efm32.c b/drivers/clocksource/time-efm32.c
index b06e4c2..6e2f79f 100644
--- a/drivers/clocksource/time-efm32.c
+++ b/drivers/clocksource/time-efm32.c
@@ -233,10 +233,15 @@ static int __init efm32_clockevent_init(struct device_node *np)
 					DIV_ROUND_CLOSEST(rate, 1024),
 					0xf, 0xffff);
 
-	setup_irq(irq, &efm32_clock_event_irq);
+	ret = setup_irq(irq, &efm32_clock_event_irq);
+	if (ret) {
+		pr_err("Failed setup irq");
+		goto err_setup_irq;
+	}
 
 	return 0;
 
+err_setup_irq:
 err_get_irq:
 
 	iounmap(base);
@@ -255,16 +260,16 @@ err_clk_get:
  * This function asserts that we have exactly one clocksource and one
  * clock_event_device in the end.
  */
-static void __init efm32_timer_init(struct device_node *np)
+static int __init efm32_timer_init(struct device_node *np)
 {
 	static int has_clocksource, has_clockevent;
-	int ret;
+	int ret = 0;
 
 	if (!has_clocksource) {
 		ret = efm32_clocksource_init(np);
 		if (!ret) {
 			has_clocksource = 1;
-			return;
+			return 0;
 		}
 	}
 
@@ -272,9 +277,11 @@ static void __init efm32_timer_init(struct device_node *np)
 		ret = efm32_clockevent_init(np);
 		if (!ret) {
 			has_clockevent = 1;
-			return;
+			return 0;
 		}
 	}
+
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(efm32compat, "efm32,timer", efm32_timer_init);
-CLOCKSOURCE_OF_DECLARE(efm32, "energymicro,efm32-timer", efm32_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(efm32compat, "efm32,timer", efm32_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(efm32, "energymicro,efm32-timer", efm32_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 57/63] clocksource/drivers/ralink: Convert init function to return error
  2016-06-16 21:27 ` [PATCH V2 57/63] clocksource/drivers/ralink: " Daniel Lezcano
@ 2016-06-17  8:54   ` John Crispin
  0 siblings, 0 replies; 112+ messages in thread
From: John Crispin @ 2016-06-17  8:54 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, Ralf Baechle, open list:RALINK MIPS ARCHI...



On 16/06/2016 23:27, Daniel Lezcano wrote:
> 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: John Crispin <john@phrozen.org>

> ---
>  arch/mips/ralink/cevt-rt3352.c | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/mips/ralink/cevt-rt3352.c b/arch/mips/ralink/cevt-rt3352.c
> index 3ad0b07..f2d3c79 100644
> --- a/arch/mips/ralink/cevt-rt3352.c
> +++ b/arch/mips/ralink/cevt-rt3352.c
> @@ -117,11 +117,13 @@ static int systick_set_oneshot(struct clock_event_device *evt)
>  	return 0;
>  }
>  
> -static void __init ralink_systick_init(struct device_node *np)
> +static int __init ralink_systick_init(struct device_node *np)
>  {
> +	int ret;
> +
>  	systick.membase = of_iomap(np, 0);
>  	if (!systick.membase)
> -		return;
> +		return -ENXIO;
>  
>  	systick_irqaction.name = np->name;
>  	systick.dev.name = np->name;
> @@ -131,16 +133,21 @@ static void __init ralink_systick_init(struct device_node *np)
>  	systick.dev.irq = irq_of_parse_and_map(np, 0);
>  	if (!systick.dev.irq) {
>  		pr_err("%s: request_irq failed", np->name);
> -		return;
> +		return -EINVAL;
>  	}
>  
> -	clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
> -			SYSTICK_FREQ, 301, 16, clocksource_mmio_readl_up);
> +	ret = clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
> +				    SYSTICK_FREQ, 301, 16,
> +				    clocksource_mmio_readl_up);
> +	if (ret)
> +		return ret;
>  
>  	clockevents_register_device(&systick.dev);
>  
>  	pr_info("%s: running - mult: %d, shift: %d\n",
>  			np->name, systick.dev.mult, systick.dev.shift);
> +
> +	return 0;
>  }
>  
> -CLOCKSOURCE_OF_DECLARE(systick, "ralink,cevt-systick", ralink_systick_init);
> +CLOCKSOURCE_OF_DECLARE_RET(systick, "ralink,cevt-systick", ralink_systick_init);
> 

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 61/63] clocksource/drivers/arc: Convert init function to return error
  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
  0 siblings, 1 reply; 112+ messages in thread
From: Vineet Gupta @ 2016-06-17  8:59 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, Noam Camus, Viresh Kumar, Adam Buchbinder,
	open list:SYNOPSYS ARC ARCH...

On Thursday 16 June 2016 11:27 PM, Daniel Lezcano wrote:
> 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>
> ---

[...]

>  
> @@ -172,27 +172,27 @@ static struct clocksource arc_counter_rtc = {
>  	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
>  };
>  
> -static void __init arc_cs_setup_rtc(struct device_node *node)
> +static int __init arc_cs_setup_rtc(struct device_node *node)
>  {
>  	int exists = cpuinfo_arc700[smp_processor_id()].extn.rtc;
>  	int ret;
>  
>  	if (WARN(!exists, "Local-64-bit-Ctr clocksource not detected"))
> -		return;
> +		return -ENXIO;
>  
>  	/* Local to CPU hence not usable in SMP */
>  	if (WARN(IS_ENABLED(CONFIG_SMP), "Local-64-bit-Ctr not usable in SMP"))
> -		return;
> +		return -EINVAL;
>  
>  	ret = arc_get_timer_clk(node);
>  	if (ret)
> -		return;
> +		return ret;
>  
>  	write_aux_reg(AUX_RTC_CTRL, 1);
>  
> -	clocksource_register_hz(&arc_counter_rtc, arc_timer_freq);
> +	return clocksource_register_hz(&arc_counter_rtc, arc_timer_freq);
>  }
> -CLOCKSOURCE_OF_DECLARE(arc_rtc, "snps,archs-timer-rtc", arc_cs_setup_rtc);
> +CLOCKSOURCE_OF_DECLARE_RET(arc_rtc, "snps,archs-timer-rtc", arc_cs_setup_rtc);
>  
>  #endif
>  
> @@ -213,23 +213,23 @@ static struct clocksource arc_counter_timer1 = {
>  	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
>  };
>  
> -static void __init arc_cs_setup_timer1(struct device_node *node)
> +static int __init arc_cs_setup_timer1(struct device_node *node)
>  {
>  	int ret;
>  
>  	/* Local to CPU hence not usable in SMP */
>  	if (IS_ENABLED(CONFIG_SMP))
> -		return;
> +		return 0;

-EINVAL to keep it similar as rtc above

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH V3] clocksource/drivers/tegra20: Convert init function to return error
  2016-06-17  7:21   ` Jon Hunter
  2016-06-17  8:09     ` Daniel Lezcano
@ 2016-06-17  9:06     ` Daniel Lezcano
  1 sibling, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-17  9:06 UTC (permalink / raw)
  To: daniel.lezcano, jonathanh, tglx
  Cc: linux-kernel, thierry.reding, swarren, linux-tegra

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/tegra20_timer.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/clocksource/tegra20_timer.c b/drivers/clocksource/tegra20_timer.c
index 7b94ad2..543c37e 100644
--- a/drivers/clocksource/tegra20_timer.c
+++ b/drivers/clocksource/tegra20_timer.c
@@ -165,7 +165,7 @@ static struct irqaction tegra_timer_irq = {
 	.dev_id		= &tegra_clockevent,
 };
 
-static void __init tegra20_init_timer(struct device_node *np)
+static int __init tegra20_init_timer(struct device_node *np)
 {
 	struct clk *clk;
 	unsigned long rate;
@@ -174,13 +174,13 @@ static void __init tegra20_init_timer(struct device_node *np)
 	timer_reg_base = of_iomap(np, 0);
 	if (!timer_reg_base) {
 		pr_err("Can't map timer registers\n");
-		BUG();
+		return -ENXIO;
 	}
 
 	tegra_timer_irq.irq = irq_of_parse_and_map(np, 2);
 	if (tegra_timer_irq.irq <= 0) {
 		pr_err("Failed to map timer IRQ\n");
-		BUG();
+		return -EINVAL;
 	}
 
 	clk = of_clk_get(np, 0);
@@ -211,10 +211,12 @@ static void __init tegra20_init_timer(struct device_node *np)
 
 	sched_clock_register(tegra_read_sched_clock, 32, 1000000);
 
-	if (clocksource_mmio_init(timer_reg_base + TIMERUS_CNTR_1US,
-		"timer_us", 1000000, 300, 32, clocksource_mmio_readl_up)) {
+	ret = clocksource_mmio_init(timer_reg_base + TIMERUS_CNTR_1US,
+				    "timer_us", 1000000, 300, 32,
+				    clocksource_mmio_readl_up);
+	if (ret) {
 		pr_err("Failed to register clocksource\n");
-		BUG();
+		return ret;
 	}
 
 	tegra_delay_timer.read_current_timer =
@@ -225,24 +227,26 @@ static void __init tegra20_init_timer(struct device_node *np)
 	ret = setup_irq(tegra_timer_irq.irq, &tegra_timer_irq);
 	if (ret) {
 		pr_err("Failed to register timer IRQ: %d\n", ret);
-		BUG();
+		return ret;
 	}
 
 	tegra_clockevent.cpumask = cpu_all_mask;
 	tegra_clockevent.irq = tegra_timer_irq.irq;
 	clockevents_config_and_register(&tegra_clockevent, 1000000,
 					0x1, 0x1fffffff);
+
+	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer);
+CLOCKSOURCE_OF_DECLARE_RET(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer);
 
-static void __init tegra20_init_rtc(struct device_node *np)
+static int __init tegra20_init_rtc(struct device_node *np)
 {
 	struct clk *clk;
 
 	rtc_base = of_iomap(np, 0);
 	if (!rtc_base) {
 		pr_err("Can't map RTC registers");
-		BUG();
+		return -ENXIO;
 	}
 
 	/*
@@ -255,6 +259,6 @@ static void __init tegra20_init_rtc(struct device_node *np)
 	else
 		clk_prepare_enable(clk);
 
-	register_persistent_clock(NULL, tegra_read_persistent_clock64);
+	return register_persistent_clock(NULL, tegra_read_persistent_clock64);
 }
-CLOCKSOURCE_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc);
+CLOCKSOURCE_OF_DECLARE_RET(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 31/63] clocksource/drivers/tango_xtal: Convert init function to return error
  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
  0 siblings, 1 reply; 112+ messages in thread
From: Mason @ 2016-06-17  9:19 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner; +Cc: LKML, Sebastian Frias

On 16/06/2016 23:26, Daniel Lezcano wrote:

> 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/sun4i_timer.c | 45 ++++++++++++++++++++++++++++-----------
>  1 file changed, 32 insertions(+), 13 deletions(-)

NACK ;-)

The subject specifies tango_xtal, but the patch changes sun4i_timer.
(Looks like all patches in the series are off by one.)
And I see you've already acknowledged the issue an hour ago.

The actual patch for tango_xtal is [PATCH V2 32/63] clocksource/drivers/tegra20_timer

BTW, I wasn't CCed on the tango_xtal patch.
I suppose I forgot to add the appropriate line in MAINTAINERS?

Regards.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/time-efm32: Convert init function to return error
  2016-06-17  8:44     ` [PATCH V3] clocksource/drivers/time-efm32: " Daniel Lezcano
@ 2016-06-17  9:46       ` Uwe Kleine-König
  0 siblings, 0 replies; 112+ messages in thread
From: Uwe Kleine-König @ 2016-06-17  9:46 UTC (permalink / raw)
  To: Daniel Lezcano; +Cc: tglx, kernel, linux-kernel, linux-arm-kernel

On Fri, Jun 17, 2016 at 10:44:19AM +0200, Daniel Lezcano wrote:
> The init functions do not return any error and let the caller unaware of
> 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: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH V3] clocksource/drivers/arc: Convert init function to return error
  2016-06-17  8:59   ` Vineet Gupta
@ 2016-06-17 10:09     ` Daniel Lezcano
  2016-06-17 14:30       ` Vineet Gupta
  2016-06-24  4:06       ` Vineet Gupta
  0 siblings, 2 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-17 10:09 UTC (permalink / raw)
  To: daniel.lezcano, Vineet.Gupta1, tglx; +Cc: linux-kernel, linux-snps-arc

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/arc/kernel/time.c | 69 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 27 deletions(-)

diff --git a/arch/arc/kernel/time.c b/arch/arc/kernel/time.c
index 4549ab2..b211f80 100644
--- a/arch/arc/kernel/time.c
+++ b/arch/arc/kernel/time.c
@@ -116,21 +116,21 @@ static struct clocksource arc_counter_gfrc = {
 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static void __init arc_cs_setup_gfrc(struct device_node *node)
+static int __init arc_cs_setup_gfrc(struct device_node *node)
 {
 	int exists = cpuinfo_arc700[0].extn.gfrc;
 	int ret;
 
 	if (WARN(!exists, "Global-64-bit-Ctr clocksource not detected"))
-		return;
+		return -ENXIO;
 
 	ret = arc_get_timer_clk(node);
 	if (ret)
-		return;
+		return ret;
 
-	clocksource_register_hz(&arc_counter_gfrc, arc_timer_freq);
+	return clocksource_register_hz(&arc_counter_gfrc, arc_timer_freq);
 }
-CLOCKSOURCE_OF_DECLARE(arc_gfrc, "snps,archs-timer-gfrc", arc_cs_setup_gfrc);
+CLOCKSOURCE_OF_DECLARE_RET(arc_gfrc, "snps,archs-timer-gfrc", arc_cs_setup_gfrc);
 
 #endif
 
@@ -172,27 +172,27 @@ static struct clocksource arc_counter_rtc = {
 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static void __init arc_cs_setup_rtc(struct device_node *node)
+static int __init arc_cs_setup_rtc(struct device_node *node)
 {
 	int exists = cpuinfo_arc700[smp_processor_id()].extn.rtc;
 	int ret;
 
 	if (WARN(!exists, "Local-64-bit-Ctr clocksource not detected"))
-		return;
+		return -ENXIO;
 
 	/* Local to CPU hence not usable in SMP */
 	if (WARN(IS_ENABLED(CONFIG_SMP), "Local-64-bit-Ctr not usable in SMP"))
-		return;
+		return -EINVAL;
 
 	ret = arc_get_timer_clk(node);
 	if (ret)
-		return;
+		return ret;
 
 	write_aux_reg(AUX_RTC_CTRL, 1);
 
-	clocksource_register_hz(&arc_counter_rtc, arc_timer_freq);
+	return clocksource_register_hz(&arc_counter_rtc, arc_timer_freq);
 }
-CLOCKSOURCE_OF_DECLARE(arc_rtc, "snps,archs-timer-rtc", arc_cs_setup_rtc);
+CLOCKSOURCE_OF_DECLARE_RET(arc_rtc, "snps,archs-timer-rtc", arc_cs_setup_rtc);
 
 #endif
 
@@ -213,23 +213,23 @@ static struct clocksource arc_counter_timer1 = {
 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static void __init arc_cs_setup_timer1(struct device_node *node)
+static int __init arc_cs_setup_timer1(struct device_node *node)
 {
 	int ret;
 
 	/* Local to CPU hence not usable in SMP */
 	if (IS_ENABLED(CONFIG_SMP))
-		return;
+		return -EINVAL;
 
 	ret = arc_get_timer_clk(node);
 	if (ret)
-		return;
+		return ret;
 
 	write_aux_reg(ARC_REG_TIMER1_LIMIT, ARC_TIMER_MAX);
 	write_aux_reg(ARC_REG_TIMER1_CNT, 0);
 	write_aux_reg(ARC_REG_TIMER1_CTRL, TIMER_CTRL_NH);
 
-	clocksource_register_hz(&arc_counter_timer1, arc_timer_freq);
+	return clocksource_register_hz(&arc_counter_timer1, arc_timer_freq);
 }
 
 /********** Clock Event Device *********/
@@ -324,20 +324,28 @@ static struct notifier_block arc_timer_cpu_nb = {
 /*
  * clockevent setup for boot CPU
  */
-static void __init arc_clockevent_setup(struct device_node *node)
+static int __init arc_clockevent_setup(struct device_node *node)
 {
 	struct clock_event_device *evt = this_cpu_ptr(&arc_clockevent_device);
 	int ret;
 
-	register_cpu_notifier(&arc_timer_cpu_nb);
+	ret = register_cpu_notifier(&arc_timer_cpu_nb);
+	if (ret) {
+		pr_err("Failed to register cpu notifier");
+		return ret;
+	}
 
 	arc_timer_irq = irq_of_parse_and_map(node, 0);
-	if (arc_timer_irq <= 0)
-		panic("clockevent: missing irq");
+	if (arc_timer_irq <= 0) {
+		pr_err("clockevent: missing irq");
+		return -EINVAL;
+	}
 
 	ret = arc_get_timer_clk(node);
-	if (ret)
-		panic("clockevent: missing clk");
+	if (ret) {
+		pr_err("clockevent: missing clk");
+		return ret;
+	}
 
 	evt->irq = arc_timer_irq;
 	evt->cpumask = cpumask_of(smp_processor_id());
@@ -347,24 +355,31 @@ static void __init arc_clockevent_setup(struct device_node *node)
 	/* Needs apriori irq_set_percpu_devid() done in intc map function */
 	ret = request_percpu_irq(arc_timer_irq, timer_irq_handler,
 				 "Timer0 (per-cpu-tick)", evt);
-	if (ret)
-		panic("clockevent: unable to request irq\n");
+	if (ret) {
+		pr_err("clockevent: unable to request irq\n");
+		returnr ret;
+	}
 
 	enable_percpu_irq(arc_timer_irq, 0);
+
+	return 0;
 }
 
-static void __init arc_of_timer_init(struct device_node *np)
+static int __init arc_of_timer_init(struct device_node *np)
 {
 	static int init_count = 0;
+	int ret;
 
 	if (!init_count) {
 		init_count = 1;
-		arc_clockevent_setup(np);
+		ret = arc_clockevent_setup(np);
 	} else {
-		arc_cs_setup_timer1(np);
+		ret = arc_cs_setup_timer1(np);
 	}
+
+	return ret;
 }
-CLOCKSOURCE_OF_DECLARE(arc_clkevt, "snps,arc-timer", arc_of_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(arc_clkevt, "snps,arc-timer", arc_of_timer_init);
 
 /*
  * Called from start_kernel() - boot CPU only
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V3] clocksource/drivers/tango_xtal: Convert init function to return error
  2016-06-17  9:19   ` Mason
@ 2016-06-17 10:26     ` Daniel Lezcano
  2016-06-17 12:35       ` Marc Gonzalez
  0 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-17 10:26 UTC (permalink / raw)
  To: daniel.lezcano, slash.tmp, tglx; +Cc: linux-kernel

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/tango_xtal.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/tango_xtal.c b/drivers/clocksource/tango_xtal.c
index c407c47..7dc716c 100644
--- a/drivers/clocksource/tango_xtal.c
+++ b/drivers/clocksource/tango_xtal.c
@@ -19,7 +19,7 @@ static u64 notrace read_sched_clock(void)
 	return read_xtal_counter();
 }
 
-static void __init tango_clocksource_init(struct device_node *np)
+static int __init tango_clocksource_init(struct device_node *np)
 {
 	struct clk *clk;
 	int xtal_freq, ret;
@@ -27,13 +27,13 @@ static void __init tango_clocksource_init(struct device_node *np)
 	xtal_in_cnt = of_iomap(np, 0);
 	if (xtal_in_cnt == NULL) {
 		pr_err("%s: invalid address\n", np->full_name);
-		return;
+		return -ENXIO;
 	}
 
 	clk = of_clk_get(np, 0);
 	if (IS_ERR(clk)) {
 		pr_err("%s: invalid clock\n", np->full_name);
-		return;
+		return PTR_ERR(clk);
 	}
 
 	xtal_freq = clk_get_rate(clk);
@@ -44,11 +44,13 @@ static void __init tango_clocksource_init(struct device_node *np)
 				    32, clocksource_mmio_readl_up);
 	if (ret) {
 		pr_err("%s: registration failed\n", np->full_name);
-		return;
+		return ret;
 	}
 
 	sched_clock_register(read_sched_clock, 32, xtal_freq);
 	register_current_timer_delay(&delay_timer);
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init);
+CLOCKSOURCE_OF_DECLARE_RET(tango, "sigma,tick-counter", tango_clocksource_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* [PATCH V3] clocksource/drivers/mxs: Convert init function to return error
  2016-06-17  6:33   ` Uwe Kleine-König
@ 2016-06-17 10:43     ` Daniel Lezcano
  0 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-17 10:43 UTC (permalink / raw)
  To: daniel.lezcano, tglx, ukl; +Cc: linux-kernel

The init function does not return any error, it prints a message, returns and
lets 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/mxs_timer.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/mxs_timer.c b/drivers/clocksource/mxs_timer.c
index f5ce296..17b9d19 100644
--- a/drivers/clocksource/mxs_timer.c
+++ b/drivers/clocksource/mxs_timer.c
@@ -226,10 +226,10 @@ static int __init mxs_clocksource_init(struct clk *timer_clk)
 	return 0;
 }
 
-static void __init mxs_timer_init(struct device_node *np)
+static int __init mxs_timer_init(struct device_node *np)
 {
 	struct clk *timer_clk;
-	int irq;
+	int irq, ret;
 
 	mxs_timrot_base = of_iomap(np, 0);
 	WARN_ON(!mxs_timrot_base);
@@ -237,10 +237,12 @@ static void __init mxs_timer_init(struct device_node *np)
 	timer_clk = of_clk_get(np, 0);
 	if (IS_ERR(timer_clk)) {
 		pr_err("%s: failed to get clk\n", __func__);
-		return;
+		return PTR_ERR(timer_clk);
 	}
 
-	clk_prepare_enable(timer_clk);
+	ret = clk_prepare_enable(timer_clk);
+	if (ret)
+		return ret;
 
 	/*
 	 * Initialize timers to a known state
@@ -278,11 +280,19 @@ static void __init mxs_timer_init(struct device_node *np)
 			mxs_timrot_base + HW_TIMROT_FIXED_COUNTn(1));
 
 	/* init and register the timer to the framework */
-	mxs_clocksource_init(timer_clk);
-	mxs_clockevent_init(timer_clk);
+	ret = mxs_clocksource_init(timer_clk);
+	if (ret)
+		return ret;
+
+	ret = mxs_clockevent_init(timer_clk);
+	if (ret)
+		return ret;
 
 	/* Make irqs happen */
 	irq = irq_of_parse_and_map(np, 0);
-	setup_irq(irq, &mxs_timer_irq);
+	if (irq <= 0)
+		return -EINVAL;
+
+	return setup_irq(irq, &mxs_timer_irq);
 }
-CLOCKSOURCE_OF_DECLARE(mxs, "fsl,timrot", mxs_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(mxs, "fsl,timrot", mxs_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/tango_xtal: Convert init function to return error
  2016-06-17 10:26     ` [PATCH V3] " Daniel Lezcano
@ 2016-06-17 12:35       ` Marc Gonzalez
  2016-06-17 12:43         ` Daniel Lezcano
  0 siblings, 1 reply; 112+ messages in thread
From: Marc Gonzalez @ 2016-06-17 12:35 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner; +Cc: LKML, Mason, Sebastian Frias

On 17/06/2016 12:26, Daniel Lezcano wrote:

> 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
                         ^^^                    ^^
"leave the caller unaware of [...]" (?)

> 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
                                 ^^^^^^^^^^^
"just returns an error code from the init function" (?)

> function.
> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
>  drivers/clocksource/tango_xtal.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/clocksource/tango_xtal.c b/drivers/clocksource/tango_xtal.c
> index c407c47..7dc716c 100644
> --- a/drivers/clocksource/tango_xtal.c
> +++ b/drivers/clocksource/tango_xtal.c
> @@ -19,7 +19,7 @@ static u64 notrace read_sched_clock(void)
>  	return read_xtal_counter();
>  }
>  
> -static void __init tango_clocksource_init(struct device_node *np)
> +static int __init tango_clocksource_init(struct device_node *np)
>  {
>  	struct clk *clk;
>  	int xtal_freq, ret;
> @@ -27,13 +27,13 @@ static void __init tango_clocksource_init(struct device_node *np)
>  	xtal_in_cnt = of_iomap(np, 0);
>  	if (xtal_in_cnt == NULL) {
>  		pr_err("%s: invalid address\n", np->full_name);
> -		return;
> +		return -ENXIO;
>  	}
>  
>  	clk = of_clk_get(np, 0);
>  	if (IS_ERR(clk)) {
>  		pr_err("%s: invalid clock\n", np->full_name);
> -		return;
> +		return PTR_ERR(clk);
>  	}
>  
>  	xtal_freq = clk_get_rate(clk);
> @@ -44,11 +44,13 @@ static void __init tango_clocksource_init(struct device_node *np)
>  				    32, clocksource_mmio_readl_up);
>  	if (ret) {
>  		pr_err("%s: registration failed\n", np->full_name);
> -		return;
> +		return ret;
>  	}
>  
>  	sched_clock_register(read_sched_clock, 32, xtal_freq);
>  	register_current_timer_delay(&delay_timer);
> +
> +	return 0;
>  }
>  
> -CLOCKSOURCE_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init);
> +CLOCKSOURCE_OF_DECLARE_RET(tango, "sigma,tick-counter", tango_clocksource_init);

The code looks good to me.
Acked-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>

Could you merge, on top of these, the patch we discussed a few weeks ago
for changing ret to err? (I will attach the patch to this message.)

Regards.

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/tango_xtal: Convert init function to return error
  2016-06-17 12:35       ` Marc Gonzalez
@ 2016-06-17 12:43         ` Daniel Lezcano
  0 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-17 12:43 UTC (permalink / raw)
  To: Marc Gonzalez, Thomas Gleixner; +Cc: LKML, Mason, Sebastian Frias

On 06/17/2016 02:35 PM, Marc Gonzalez wrote:
> On 17/06/2016 12:26, Daniel Lezcano wrote:
>
>> 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
>                           ^^^                    ^^
> "leave the caller unaware of [...]" (?)
>
>> 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
>                                   ^^^^^^^^^^^
> "just returns an error code from the init function" (?)

Ok, I will do the change when adding the acked-by tag.

[ ... ]

> The code looks good to me.
> Acked-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
>
> Could you merge, on top of these, the patch we discussed a few weeks ago
> for changing ret to err? (I will attach the patch to this message.)

I don't really mind to convert 'ret' to 'err' if it is your preference 
but can it wait after the changes I initiated ? Much more patches will 
come to consolidate the init functions.



-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/arc: Convert init function to return error
  2016-06-17 10:09     ` [PATCH V3] " Daniel Lezcano
@ 2016-06-17 14:30       ` Vineet Gupta
  2016-06-24  4:06       ` Vineet Gupta
  1 sibling, 0 replies; 112+ messages in thread
From: Vineet Gupta @ 2016-06-17 14:30 UTC (permalink / raw)
  To: Daniel Lezcano, tglx; +Cc: linux-kernel, linux-snps-arc

On Friday 17 June 2016 12:09 PM, Daniel Lezcano wrote:
> 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: Vineet Gupta <vgupta@synopsys.com>

P.S. It would be nice to get cover letter for a series in addition to relevant
patches for full context, although per prev discussion on ARC timers, I kind of
knew what the idea was !

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 63/63] clocksources: Switch back to the clksrc table
       [not found] ` <1466112442-31105-64-git-send-email-daniel.lezcano@linaro.org>
@ 2016-06-17 14:33   ` Vineet Gupta
  0 siblings, 0 replies; 112+ messages in thread
From: Vineet Gupta @ 2016-06-17 14:33 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, Russell King, Michal Simek, John Crispin,
	Ralf Baechle, Ley Foon Tan, Srinivas Kandagatla, Maxime Coquelin,
	Patrice Chotard, Stephen Warren, Lee Jones, Eric Anholt,
	Florian Fainelli, Ray Jui, Scott Branden, Sören Brinkmann,
	Linus Walleij, Alexander Shiyan, Kukjin Kim

On Thursday 16 June 2016 11:27 PM, Daniel Lezcano wrote:
> All the clocksource drivers's init function are now converted to return
> an error code. CLOCKSOURCE_OF_DECLARE 

s/CLOCKSOURCE_OF_DECLARE/CLOCKSOURCE_OF_DECLARE_RET

is no longer used as well as the
> clksrc-of table.
> 
> Let's convert back the names:
>  - CLOCKSOURCE_OF_DECLARE_RET => CLOCKSOURCE_OF_DECLARE
>  - clksrc-of-ret              => clksrc-of
> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
>  arch/arc/kernel/time.c                    |  6 +++---

Acked-by: Vineet Gupta <vgupta@synopsys.com>  #for arch/arc

Thx,
-Vineet

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 45/63] clocksource/drivers/timer-keystone: Convert init function to return error
  2016-06-16 21:27 ` [PATCH V2 45/63] clocksource/drivers/timer-keystone: " Daniel Lezcano
@ 2016-06-17 16:03   ` Santosh Shilimkar
  0 siblings, 0 replies; 112+ messages in thread
From: Santosh Shilimkar @ 2016-06-17 16:03 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, Santosh Shilimkar, moderated list:ARM/TEXAS INSTRUM...

On 6/16/2016 2:27 PM, Daniel Lezcano wrote:
> 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-keystone.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
>
Acked-by: Santosh Shilimkar <ssantosh@kernel.org>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 15/63] clocksource/drivers/clksrc-dbx500: Convert init function to return error
  2016-06-16 21:26 ` [PATCH V2 15/63] clocksource/drivers/clksrc-dbx500: " Daniel Lezcano
@ 2016-06-17 16:10   ` Linus Walleij
  0 siblings, 0 replies; 112+ messages in thread
From: Linus Walleij @ 2016-06-17 16:10 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: Thomas Gleixner, linux-kernel, moderated list:ARM/Ux500 ARM ARC...

On Thu, Jun 16, 2016 at 11:26 PM, Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:

> 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: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 50/63] clocksource/drivers/timer-u300: Convert init function to return error
  2016-06-16 21:27 ` [PATCH V2 50/63] clocksource/drivers/timer-u300: " Daniel Lezcano
@ 2016-06-17 16:11   ` Linus Walleij
  0 siblings, 0 replies; 112+ messages in thread
From: Linus Walleij @ 2016-06-17 16:11 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: Thomas Gleixner, linux-kernel, moderated list:ARM/U300 MACHINE...

On Thu, Jun 16, 2016 at 11:27 PM, Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:

> 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: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 04/63] clocksource/drivers/mkt_timer: Convert init function to return error
  2016-06-16 21:26 ` [PATCH V2 04/63] clocksource/drivers/mkt_timer: " Daniel Lezcano
@ 2016-06-17 16:16   ` Matthias Brugger
  0 siblings, 0 replies; 112+ messages in thread
From: Matthias Brugger @ 2016-06-17 16:16 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, moderated list:ARM/Mediatek SoC...,
	moderated list:ARM/Mediatek SoC...



On 16/06/16 23:26, Daniel Lezcano wrote:
> 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/mtk_timer.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>

Acked-by: Matthias Brugger <matthias.bgg@gmail.com>

> diff --git a/drivers/clocksource/mtk_timer.c b/drivers/clocksource/mtk_timer.c
> index 7e583f8..432a2c0 100644
> --- a/drivers/clocksource/mtk_timer.c
> +++ b/drivers/clocksource/mtk_timer.c
> @@ -181,7 +181,7 @@ static void mtk_timer_enable_irq(struct mtk_clock_event_device *evt, u8 timer)
>   			evt->gpt_base + GPT_IRQ_EN_REG);
>   }
>
> -static void __init mtk_timer_init(struct device_node *node)
> +static int __init mtk_timer_init(struct device_node *node)
>   {
>   	struct mtk_clock_event_device *evt;
>   	struct resource res;
> @@ -190,7 +190,7 @@ static void __init mtk_timer_init(struct device_node *node)
>
>   	evt = kzalloc(sizeof(*evt), GFP_KERNEL);
>   	if (!evt)
> -		return;
> +		return -ENOMEM;
>
>   	evt->dev.name = "mtk_tick";
>   	evt->dev.rating = 300;
> @@ -248,7 +248,7 @@ static void __init mtk_timer_init(struct device_node *node)
>
>   	mtk_timer_enable_irq(evt, GPT_CLK_EVT);
>
> -	return;
> +	return 0;
>
>   err_clk_disable:
>   	clk_disable_unprepare(clk);
> @@ -262,5 +262,7 @@ err_mem:
>   	release_mem_region(res.start, resource_size(&res));
>   err_kzalloc:
>   	kfree(evt);
> +
> +	return -EINVAL;
>   }
> -CLOCKSOURCE_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_timer_init);
> +CLOCKSOURCE_OF_DECLARE_RET(mtk_mt6577, "mediatek,mt6577-timer", mtk_timer_init);
>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 03/63] clocksource/drivers/rockchip_timer: Convert init function to return error
  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
  0 siblings, 1 reply; 112+ messages in thread
From: Heiko Stübner @ 2016-06-18 10:38 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: tglx, linux-kernel, moderated list:ARM/Rockchip SoC...,
	open list:ARM/Rockchip SoC...

Am Donnerstag, 16. Juni 2016, 23:26:22 schrieb Daniel Lezcano:
> 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/rockchip_timer.c | 26 ++++++++++++++------------
>  1 file changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/clocksource/rockchip_timer.c
> b/drivers/clocksource/rockchip_timer.c index a3f22b0..d10bdee 100644
> --- a/drivers/clocksource/rockchip_timer.c
> +++ b/drivers/clocksource/rockchip_timer.c
> @@ -113,17 +113,17 @@ static irqreturn_t rk_timer_interrupt(int irq, void
> *dev_id) return IRQ_HANDLED;
>  }
> 
> -static void __init rk_timer_init(struct device_node *np, u32 ctrl_reg)
> +static int __init rk_timer_init(struct device_node *np, u32 ctrl_reg)
>  {
>  	struct clock_event_device *ce = &bc_timer.ce;
>  	struct clk *timer_clk;
>  	struct clk *pclk;
> -	int ret, irq;
> +	int ret = -EINVAL, irq;
> 
>  	bc_timer.base = of_iomap(np, 0);
>  	if (!bc_timer.base) {
>  		pr_err("Failed to get base address for '%s'\n", TIMER_NAME);
> -		return;
> +		return -ENXIO;
>  	}
>  	bc_timer.ctrl = bc_timer.base + ctrl_reg;

wouldn't it be nicer to also save the error values from all the intermediate
clock calls (ret = PTR_ERR(pclk) and so on).
Right now it will be always -EINVAL for all those clk calls and also
the irq_of_parse_and_map.

Heiko

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH V3] clocksource/drivers/rockchip_timer: Convert init function to return error
  2016-06-18 10:38   ` Heiko Stübner
@ 2016-06-18 12:54     ` Daniel Lezcano
  2016-06-18 13:47       ` Heiko Stübner
  0 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-18 12:54 UTC (permalink / raw)
  To: daniel.lezcano, tglx, heiko
  Cc: linux-kernel, linux-rockchip, linux-arm-kernel

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/rockchip_timer.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/clocksource/rockchip_timer.c b/drivers/clocksource/rockchip_timer.c
index a3f22b0..85aee69 100644
--- a/drivers/clocksource/rockchip_timer.c
+++ b/drivers/clocksource/rockchip_timer.c
@@ -113,38 +113,42 @@ static irqreturn_t rk_timer_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static void __init rk_timer_init(struct device_node *np, u32 ctrl_reg)
+static int __init rk_timer_init(struct device_node *np, u32 ctrl_reg)
 {
 	struct clock_event_device *ce = &bc_timer.ce;
 	struct clk *timer_clk;
 	struct clk *pclk;
-	int ret, irq;
+	int ret = -EINVAL, irq;
 
 	bc_timer.base = of_iomap(np, 0);
 	if (!bc_timer.base) {
 		pr_err("Failed to get base address for '%s'\n", TIMER_NAME);
-		return;
+		return -ENXIO;
 	}
 	bc_timer.ctrl = bc_timer.base + ctrl_reg;
 
 	pclk = of_clk_get_by_name(np, "pclk");
 	if (IS_ERR(pclk)) {
+		ret = PTR_ERR(pclk);
 		pr_err("Failed to get pclk for '%s'\n", TIMER_NAME);
 		goto out_unmap;
 	}
 
-	if (clk_prepare_enable(pclk)) {
+	ret = clk_prepare_enable(pclk);
+	if (ret) {
 		pr_err("Failed to enable pclk for '%s'\n", TIMER_NAME);
 		goto out_unmap;
 	}
 
 	timer_clk = of_clk_get_by_name(np, "timer");
 	if (IS_ERR(timer_clk)) {
+		ret = PTR_ERR(timer_clk);
 		pr_err("Failed to get timer clock for '%s'\n", TIMER_NAME);
 		goto out_timer_clk;
 	}
 
-	if (clk_prepare_enable(timer_clk)) {
+	ret = clk_prepare_enable(timer_clk);
+	if (ret) {
 		pr_err("Failed to enable timer clock\n");
 		goto out_timer_clk;
 	}
@@ -153,6 +157,7 @@ static void __init rk_timer_init(struct device_node *np, u32 ctrl_reg)
 
 	irq = irq_of_parse_and_map(np, 0);
 	if (!irq) {
+		ret = -EINVAL;
 		pr_err("Failed to map interrupts for '%s'\n", TIMER_NAME);
 		goto out_irq;
 	}
@@ -178,7 +183,7 @@ static void __init rk_timer_init(struct device_node *np, u32 ctrl_reg)
 
 	clockevents_config_and_register(ce, bc_timer.freq, 1, UINT_MAX);
 
-	return;
+	return 0;
 
 out_irq:
 	clk_disable_unprepare(timer_clk);
@@ -186,19 +191,21 @@ out_timer_clk:
 	clk_disable_unprepare(pclk);
 out_unmap:
 	iounmap(bc_timer.base);
+
+	return ret;
 }
 
-static void __init rk3288_timer_init(struct device_node *np)
+static int __init rk3288_timer_init(struct device_node *np)
 {
-	rk_timer_init(np, TIMER_CONTROL_REG3288);
+	return rk_timer_init(np, TIMER_CONTROL_REG3288);
 }
 
-static void __init rk3399_timer_init(struct device_node *np)
+static int __init rk3399_timer_init(struct device_node *np)
 {
-	rk_timer_init(np, TIMER_CONTROL_REG3399);
+	return rk_timer_init(np, TIMER_CONTROL_REG3399);
 }
 
-CLOCKSOURCE_OF_DECLARE(rk3288_timer, "rockchip,rk3288-timer",
-		       rk3288_timer_init);
-CLOCKSOURCE_OF_DECLARE(rk3399_timer, "rockchip,rk3399-timer",
-		       rk3399_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(rk3288_timer, "rockchip,rk3288-timer",
+			   rk3288_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(rk3399_timer, "rockchip,rk3399-timer",
+			   rk3399_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/rockchip_timer: Convert init function to return error
  2016-06-18 12:54     ` [PATCH V3] " Daniel Lezcano
@ 2016-06-18 13:47       ` Heiko Stübner
  0 siblings, 0 replies; 112+ messages in thread
From: Heiko Stübner @ 2016-06-18 13:47 UTC (permalink / raw)
  To: Daniel Lezcano; +Cc: tglx, linux-kernel, linux-rockchip, linux-arm-kernel

Am Samstag, 18. Juni 2016, 14:54:07 schrieb Daniel Lezcano:
> 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>

looks good now :-)
Reviewed-by: Heiko Stuebner <heiko@sntech.de>

on a rk3399-evb
Tested-by: Heiko Stuebner <heiko@sntech.de>


Heiko

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 08/63] clocksource/drivers/st_lpc: Convert init function to return error
  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
  1 sibling, 0 replies; 112+ messages in thread
From: Patrice Chotard @ 2016-06-20  7:39 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, Srinivas Kandagatla, Maxime Coquelin,
	moderated list:ARM/STI ARCHITECTURE,
	open list:ARM/STI ARCHITECTURE

Hi Daniel

On 06/16/2016 11:26 PM, Daniel Lezcano wrote:
> 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/clksrc_st_lpc.c | 22 +++++++++++++---------
>   1 file changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/clocksource/clksrc_st_lpc.c b/drivers/clocksource/clksrc_st_lpc.c
> index 65ec467..c9022a9 100644
> --- a/drivers/clocksource/clksrc_st_lpc.c
> +++ b/drivers/clocksource/clksrc_st_lpc.c
> @@ -92,7 +92,7 @@ static int __init st_clksrc_setup_clk(struct device_node *np)
>   	return 0;
>   }
>   
> -static void __init st_clksrc_of_register(struct device_node *np)
> +static int __init st_clksrc_of_register(struct device_node *np)
>   {
>   	int ret;
>   	uint32_t mode;
> @@ -100,32 +100,36 @@ static void __init st_clksrc_of_register(struct device_node *np)
>   	ret = of_property_read_u32(np, "st,lpc-mode", &mode);
>   	if (ret) {
>   		pr_err("clksrc-st-lpc: An LPC mode must be provided\n");
> -		return;
> +		return ret;
>   	}
>   
>   	/* LPC can either run as a Clocksource or in RTC or WDT mode */
>   	if (mode != ST_LPC_MODE_CLKSRC)
> -		return;
> +		return 0;
>   
>   	ddata.base = of_iomap(np, 0);
>   	if (!ddata.base) {
>   		pr_err("clksrc-st-lpc: Unable to map iomem\n");
> -		return;
> +		return -ENXIO;
>   	}
>   
> -	if (st_clksrc_setup_clk(np)) {
> +	ret = st_clksrc_setup_clk(np);
> +	if (ret) {
>   		iounmap(ddata.base);
> -		return;
> +		return ret;
>   	}
>   
> -	if (st_clksrc_init()) {
> +	ret = st_clksrc_init();
> +	if (ret) {
>   		clk_disable_unprepare(ddata.clk);
>   		clk_put(ddata.clk);
>   		iounmap(ddata.base);
> -		return;
> +		return ret;
>   	}
>   
>   	pr_info("clksrc-st-lpc: clocksource initialised - running @ %luHz\n",
>   		clk_get_rate(ddata.clk));
> +
> +	return ret;
>   }
> -CLOCKSOURCE_OF_DECLARE(ddata, "st,stih407-lpc", st_clksrc_of_register);
> +CLOCKSOURCE_OF_DECLARE_RET(ddata, "st,stih407-lpc", st_clksrc_of_register);

Acked-by: Patrice Chotard <patrice.chotard@st.com>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 51/63] clocksource/drivers/versatile: Convert init function to return error
  2016-06-16 21:27 ` [PATCH V2 51/63] clocksource/drivers/versatile: " Daniel Lezcano
@ 2016-06-20  9:13   ` Liviu Dudau
  0 siblings, 0 replies; 112+ messages in thread
From: Liviu Dudau @ 2016-06-20  9:13 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: tglx, linux-kernel, Sudeep Holla, Lorenzo Pieralisi,
	moderated list:ARM/VERSATILE EXP...

On Thu, Jun 16, 2016 at 11:27:10PM +0200, Daniel Lezcano wrote:
> 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/versatile.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clocksource/versatile.c b/drivers/clocksource/versatile.c
> index 0a26d3d..8daeffa 100644
> --- a/drivers/clocksource/versatile.c
> +++ b/drivers/clocksource/versatile.c
> @@ -25,18 +25,20 @@ static u64 notrace versatile_sys_24mhz_read(void)
>  	return readl(versatile_sys_24mhz);
>  }
>  
> -static void __init versatile_sched_clock_init(struct device_node *node)
> +static int __init versatile_sched_clock_init(struct device_node *node)
>  {
>  	void __iomem *base = of_iomap(node, 0);
>  
>  	if (!base)
> -		return;
> +		return -ENXIO;
>  
>  	versatile_sys_24mhz = base + SYS_24MHZ;
>  
>  	sched_clock_register(versatile_sys_24mhz_read, 32, 24000000);
> +
> +	return 0;
>  }
> -CLOCKSOURCE_OF_DECLARE(vexpress, "arm,vexpress-sysreg",
> +CLOCKSOURCE_OF_DECLARE_RET(vexpress, "arm,vexpress-sysreg",
>  		       versatile_sched_clock_init);
> -CLOCKSOURCE_OF_DECLARE(versatile, "arm,versatile-sysreg",
> +CLOCKSOURCE_OF_DECLARE_RET(versatile, "arm,versatile-sysreg",
>  		       versatile_sched_clock_init);
> -- 
> 1.9.1
> 

Acked-by: Liviu Dudau <Liviu.Dudau@arm.com>

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 25/63] clocksource/drivers/mxs_timer: Convert init function to return error
  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-20  9:15   ` Liviu Dudau
  2016-06-20  9:24     ` Daniel Lezcano
  2016-06-20  9:26     ` [PATCH V3] clocksource/drivers/mps2-timer: " Daniel Lezcano
  1 sibling, 2 replies; 112+ messages in thread
From: Liviu Dudau @ 2016-06-20  9:15 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: tglx, linux-kernel, Sudeep Holla, Lorenzo Pieralisi,
	moderated list:ARM/VERSATILE EXP...

On Thu, Jun 16, 2016 at 11:26:44PM +0200, Daniel Lezcano wrote:
> 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/mps2-timer.c | 10 ++++++----
>  drivers/clocksource/mxs_timer.c  |  2 +-
>  2 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/clocksource/mps2-timer.c b/drivers/clocksource/mps2-timer.c
> index 3d33a5e..c303fa9 100644
> --- a/drivers/clocksource/mps2-timer.c
> +++ b/drivers/clocksource/mps2-timer.c
> @@ -250,7 +250,7 @@ out:
>  	return ret;
>  }
>  
> -static void __init mps2_timer_init(struct device_node *np)
> +static int __init mps2_timer_init(struct device_node *np)
>  {
>  	static int has_clocksource, has_clockevent;
>  	int ret;
> @@ -259,7 +259,7 @@ static void __init mps2_timer_init(struct device_node *np)
>  		ret = mps2_clocksource_init(np);
>  		if (!ret) {
>  			has_clocksource = 1;
> -			return;
> +			return 0;
>  		}
>  	}
>  
> @@ -267,9 +267,11 @@ static void __init mps2_timer_init(struct device_node *np)
>  		ret = mps2_clockevent_init(np);
>  		if (!ret) {
>  			has_clockevent = 1;
> -			return;
> +			return 0;
>  		}
>  	}
> +
> +	return 0;
>  }
>  
> -CLOCKSOURCE_OF_DECLARE(mps2_timer, "arm,mps2-timer", mps2_timer_init);
> +CLOCKSOURCE_OF_DECLARE_RET(mps2_timer, "arm,mps2-timer", mps2_timer_init);
> diff --git a/drivers/clocksource/mxs_timer.c b/drivers/clocksource/mxs_timer.c
> index f5ce296..16cf53b 100644
> --- a/drivers/clocksource/mxs_timer.c
> +++ b/drivers/clocksource/mxs_timer.c
> @@ -226,7 +226,7 @@ static int __init mxs_clocksource_init(struct clk *timer_clk)
>  	return 0;
>  }
>  
> -static void __init mxs_timer_init(struct device_node *np)
> +static int __init mxs_timer_init(struct device_node *np)
>  {
>  	struct clk *timer_clk;
>  	int irq;
> -- 
> 1.9.1
> 

This patch needs rework as it is changing (incompletely) two files that have different
maintainers.

Best regards,
Liviu

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 25/63] clocksource/drivers/mxs_timer: Convert init function to return error
  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
  1 sibling, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-20  9:24 UTC (permalink / raw)
  To: Liviu Dudau
  Cc: tglx, linux-kernel, Sudeep Holla, Lorenzo Pieralisi,
	moderated list:ARM/VERSATILE EXP...

On 06/20/2016 11:15 AM, Liviu Dudau wrote:
> On Thu, Jun 16, 2016 at 11:26:44PM +0200, Daniel Lezcano wrote:
>> 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>
>> ---

[ ... ]

Actually, this is fixed for mxs [1] (sorry the Cc script is misbehaving).

> This patch needs rework as it is changing (incompletely) two files that have different
> maintainers.

Let me resend the mps2 driver.

Thanks.

   -- Daniel

[1] http://www.spinics.net/lists/kernel/msg2281624.html


-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH V3] clocksource/drivers/mps2-timer: Convert init function to return error
  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     ` Daniel Lezcano
  2016-06-20  9:42       ` liviu.dudau
  1 sibling, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-20  9:26 UTC (permalink / raw)
  To: daniel.lezcano, tglx, liviu.dudau; +Cc: linux-kernel, linux-arm-kernel

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/mps2-timer.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clocksource/mps2-timer.c b/drivers/clocksource/mps2-timer.c
index 3d33a5e..c303fa9 100644
--- a/drivers/clocksource/mps2-timer.c
+++ b/drivers/clocksource/mps2-timer.c
@@ -250,7 +250,7 @@ out:
 	return ret;
 }
 
-static void __init mps2_timer_init(struct device_node *np)
+static int __init mps2_timer_init(struct device_node *np)
 {
 	static int has_clocksource, has_clockevent;
 	int ret;
@@ -259,7 +259,7 @@ static void __init mps2_timer_init(struct device_node *np)
 		ret = mps2_clocksource_init(np);
 		if (!ret) {
 			has_clocksource = 1;
-			return;
+			return 0;
 		}
 	}
 
@@ -267,9 +267,11 @@ static void __init mps2_timer_init(struct device_node *np)
 		ret = mps2_clockevent_init(np);
 		if (!ret) {
 			has_clockevent = 1;
-			return;
+			return 0;
 		}
 	}
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(mps2_timer, "arm,mps2-timer", mps2_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(mps2_timer, "arm,mps2-timer", mps2_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/mps2-timer: Convert init function to return error
  2016-06-20  9:26     ` [PATCH V3] clocksource/drivers/mps2-timer: " Daniel Lezcano
@ 2016-06-20  9:42       ` liviu.dudau
  0 siblings, 0 replies; 112+ messages in thread
From: liviu.dudau @ 2016-06-20  9:42 UTC (permalink / raw)
  To: Daniel Lezcano; +Cc: tglx, linux-kernel, linux-arm-kernel

On Mon, Jun 20, 2016 at 11:26:59AM +0200, Daniel Lezcano wrote:
> 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/mps2-timer.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clocksource/mps2-timer.c b/drivers/clocksource/mps2-timer.c
> index 3d33a5e..c303fa9 100644
> --- a/drivers/clocksource/mps2-timer.c
> +++ b/drivers/clocksource/mps2-timer.c
> @@ -250,7 +250,7 @@ out:
>  	return ret;
>  }
>  
> -static void __init mps2_timer_init(struct device_node *np)
> +static int __init mps2_timer_init(struct device_node *np)
>  {
>  	static int has_clocksource, has_clockevent;
>  	int ret;
> @@ -259,7 +259,7 @@ static void __init mps2_timer_init(struct device_node *np)
>  		ret = mps2_clocksource_init(np);
>  		if (!ret) {
>  			has_clocksource = 1;
> -			return;
> +			return 0;
>  		}
>  	}
>  
> @@ -267,9 +267,11 @@ static void __init mps2_timer_init(struct device_node *np)
>  		ret = mps2_clockevent_init(np);
>  		if (!ret) {
>  			has_clockevent = 1;
> -			return;
> +			return 0;
>  		}
>  	}
> +
> +	return 0;
>  }
>  
> -CLOCKSOURCE_OF_DECLARE(mps2_timer, "arm,mps2-timer", mps2_timer_init);
> +CLOCKSOURCE_OF_DECLARE_RET(mps2_timer, "arm,mps2-timer", mps2_timer_init);
> -- 
> 1.9.1
> 

Thanks!

Acked-by: Liviu Dudau <Liviu.Dudau@arm.com>


-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 12/63] clocksource/drivers/armv7m_systick: Convert init function to return error
  2016-06-16 21:26 ` [PATCH V2 12/63] clocksource/drivers/armv7m_systick: " Daniel Lezcano
@ 2016-06-20 11:31   ` Maxime Coquelin
  0 siblings, 0 replies; 112+ messages in thread
From: Maxime Coquelin @ 2016-06-20 11:31 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: Thomas Gleixner, linux-kernel, moderated list:ARM/STM32 ARCHITE...

2016-06-16 23:26 GMT+02:00 Daniel Lezcano <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/armv7m_systick.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)

Acked-by: Maxime Coquelin <mcoquelin.stm32@gmail.com>

Thanks!
Maxime

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 47/63] clocksource/drivers/timer-stm32: Convert init function to return error
  2016-06-16 21:27 ` [PATCH V2 47/63] clocksource/drivers/timer-stm32: " Daniel Lezcano
@ 2016-06-20 11:32   ` Maxime Coquelin
  0 siblings, 0 replies; 112+ messages in thread
From: Maxime Coquelin @ 2016-06-20 11:32 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: Thomas Gleixner, linux-kernel, moderated list:ARM/STM32 ARCHITE...

2016-06-16 23:27 GMT+02:00 Daniel Lezcano <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/timer-stm32.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)


Acked-by: Maxime Coquelin <mcoquelin.stm32@gmail.com>

Thanks!
Maxime

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 18/63] clocksource/drivers/arm_global_timer: Convert init function to return error
  2016-06-16 21:26 ` [PATCH V2 18/63] clocksource/drivers/arm_global_timer: " Daniel Lezcano
@ 2016-06-20 11:32   ` Maxime Coquelin
  0 siblings, 0 replies; 112+ messages in thread
From: Maxime Coquelin @ 2016-06-20 11:32 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, Srinivas Kandagatla, Patrice Chotard,
	moderated list:ARM/STI ARCHITECTURE,
	open list:ARM/STI ARCHITECTURE



On 06/16/2016 11:26 PM, Daniel Lezcano wrote:
> 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/arm_global_timer.c | 28 ++++++++++++++++++----------
>   1 file changed, 18 insertions(+), 10 deletions(-)
>
>

Acked-by: Maxime Coquelin <maxime.coquelin@st.com>

Thanks!
Maxime

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 08/63] clocksource/drivers/st_lpc: Convert init function to return error
  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
  1 sibling, 0 replies; 112+ messages in thread
From: Maxime Coquelin @ 2016-06-20 11:33 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, Srinivas Kandagatla, Patrice Chotard,
	moderated list:ARM/STI ARCHITECTURE,
	open list:ARM/STI ARCHITECTURE



On 06/16/2016 11:26 PM, Daniel Lezcano wrote:
> 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/clksrc_st_lpc.c | 22 +++++++++++++---------
>   1 file changed, 13 insertions(+), 9 deletions(-)
>
Acked-by: Maxime Coquelin <maxime.coquelin@st.com>

Thanks!
Maxime

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 36/63] clocksource/drivers/time-orion: Convert init function to return error
  2016-06-16 21:26 ` [PATCH V2 36/63] clocksource/drivers/time-orion: " Daniel Lezcano
@ 2016-06-20 17:08   ` Sylvain Lemieux
  0 siblings, 0 replies; 112+ messages in thread
From: Sylvain Lemieux @ 2016-06-20 17:08 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: tglx, linux-kernel, Joachim Eastwood, Vladimir Zapolskiy,
	moderated list:ARM/LPC18XX ARCHI...

On Thu, 2016-06-16 at 23:26 +0200, Daniel Lezcano wrote:
> 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-lpc32xx.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/clocksource/time-lpc32xx.c b/drivers/clocksource/time-lpc32xx.c
> index daae61e..cb5b866 100644
> --- a/drivers/clocksource/time-lpc32xx.c
> +++ b/drivers/clocksource/time-lpc32xx.c
> @@ -288,16 +288,16 @@ err_clk_enable:

[...]

Hi Daniel,

please update the patch subject
(i.e. replace "time-orion" by "time-lpc32xx).

You can add my "Acked-by" to the V3 patch:
Acked-by: Sylvain Lemieux <slemieux.tyco@gmail.com>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 14/63] clocksource/drivers/bcm_kona: Convert init function to return error
  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
  0 siblings, 2 replies; 112+ messages in thread
From: Ray Jui @ 2016-06-20 17:22 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, Florian Fainelli, Ray Jui, Scott Branden,
	open list:BROADCOM BCM281XX...

Hi Daniel,

On 6/16/2016 2:26 PM, Daniel Lezcano wrote:
> 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/bcm_kona_timer.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c
> index e717e87..98bc2a2 100644
> --- a/drivers/clocksource/bcm_kona_timer.c
> +++ b/drivers/clocksource/bcm_kona_timer.c
> @@ -163,14 +163,14 @@ static struct irqaction kona_timer_irq = {
>  	.handler = kona_timer_interrupt,
>  };
>
> -static void __init kona_timer_init(struct device_node *node)
> +static int __init kona_timer_init(struct device_node *node)
>  {
>  	u32 freq;
>  	struct clk *external_clk;
>
>  	if (!of_device_is_available(node)) {
>  		pr_info("Kona Timer v1 marked as disabled in device tree\n");
> -		return;
> +		return 0;

I thought we should return -ENODEV here.

Moreover, if this device node is not enabled, kona_timer_init won't even 
be invoked. Can we simply get rid of this check here?

>  	}
>
>  	external_clk = of_clk_get_by_name(node, NULL);
> @@ -182,7 +182,7 @@ static void __init kona_timer_init(struct device_node *node)
>  		arch_timer_rate = freq;
>  	} else {
>  		pr_err("Kona Timer v1 unable to determine clock-frequency");
> -		return;
> +		return -EINVAL;
>  	}
>
>  	/* Setup IRQ numbers */
> @@ -196,11 +196,13 @@ static void __init kona_timer_init(struct device_node *node)
>  	kona_timer_clockevents_init();
>  	setup_irq(timers.tmr_irq, &kona_timer_irq);
>  	kona_timer_set_next_event((arch_timer_rate / HZ), NULL);
> +
> +	return 0;
>  }
>
> -CLOCKSOURCE_OF_DECLARE(brcm_kona, "brcm,kona-timer", kona_timer_init);
> +CLOCKSOURCE_OF_DECLARE_RET(brcm_kona, "brcm,kona-timer", kona_timer_init);
>  /*
>   * bcm,kona-timer is deprecated by brcm,kona-timer
>   * being kept here for driver compatibility
>   */
> -CLOCKSOURCE_OF_DECLARE(bcm_kona, "bcm,kona-timer", kona_timer_init);
> +CLOCKSOURCE_OF_DECLARE_RET(bcm_kona, "bcm,kona-timer", kona_timer_init);
>

Thanks,

Ray

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 14/63] clocksource/drivers/bcm_kona: Convert init function to return error
  2016-06-20 17:22   ` Ray Jui
@ 2016-06-20 17:40     ` Daniel Lezcano
  2016-06-20 17:48     ` [PATCH V3] " Daniel Lezcano
  1 sibling, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-20 17:40 UTC (permalink / raw)
  To: Ray Jui, tglx
  Cc: linux-kernel, Florian Fainelli, Ray Jui, Scott Branden,
	open list:BROADCOM BCM281XX...

On 06/20/2016 07:22 PM, Ray Jui wrote:

[ ... ]

>> -static void __init kona_timer_init(struct device_node *node)
>> +static int __init kona_timer_init(struct device_node *node)
>>  {
>>      u32 freq;
>>      struct clk *external_clk;
>>
>>      if (!of_device_is_available(node)) {
>>          pr_info("Kona Timer v1 marked as disabled in device tree\n");
>> -        return;
>> +        return 0;
>
> I thought we should return -ENODEV here.
>
> Moreover, if this device node is not enabled, kona_timer_init won't even
> be invoked. Can we simply get rid of this check here?

Yes, absolutely :)



-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 112+ messages in thread

* [PATCH V3] clocksource/drivers/bcm_kona: Convert init function to return error
  2016-06-20 17:22   ` Ray Jui
  2016-06-20 17:40     ` Daniel Lezcano
@ 2016-06-20 17:48     ` Daniel Lezcano
  2016-06-20 17:50       ` Ray Jui
  1 sibling, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-20 17:48 UTC (permalink / raw)
  To: daniel.lezcano, tglx, ray.jui
  Cc: linux-kernel, f.fainelli, sbranden, bcm-kernel-feedback-list

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/bcm_kona_timer.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c
index e717e87..c251aa6 100644
--- a/drivers/clocksource/bcm_kona_timer.c
+++ b/drivers/clocksource/bcm_kona_timer.c
@@ -163,16 +163,11 @@ static struct irqaction kona_timer_irq = {
 	.handler = kona_timer_interrupt,
 };
 
-static void __init kona_timer_init(struct device_node *node)
+static int __init kona_timer_init(struct device_node *node)
 {
 	u32 freq;
 	struct clk *external_clk;
 
-	if (!of_device_is_available(node)) {
-		pr_info("Kona Timer v1 marked as disabled in device tree\n");
-		return;
-	}
-
 	external_clk = of_clk_get_by_name(node, NULL);
 
 	if (!IS_ERR(external_clk)) {
@@ -182,7 +177,7 @@ static void __init kona_timer_init(struct device_node *node)
 		arch_timer_rate = freq;
 	} else {
 		pr_err("Kona Timer v1 unable to determine clock-frequency");
-		return;
+		return -EINVAL;
 	}
 
 	/* Setup IRQ numbers */
@@ -196,11 +191,13 @@ static void __init kona_timer_init(struct device_node *node)
 	kona_timer_clockevents_init();
 	setup_irq(timers.tmr_irq, &kona_timer_irq);
 	kona_timer_set_next_event((arch_timer_rate / HZ), NULL);
+
+	return 0;
 }
 
-CLOCKSOURCE_OF_DECLARE(brcm_kona, "brcm,kona-timer", kona_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(brcm_kona, "brcm,kona-timer", kona_timer_init);
 /*
  * bcm,kona-timer is deprecated by brcm,kona-timer
  * being kept here for driver compatibility
  */
-CLOCKSOURCE_OF_DECLARE(bcm_kona, "bcm,kona-timer", kona_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(bcm_kona, "bcm,kona-timer", kona_timer_init);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/bcm_kona: Convert init function to return error
  2016-06-20 17:48     ` [PATCH V3] " Daniel Lezcano
@ 2016-06-20 17:50       ` Ray Jui
  2016-06-20 20:12         ` Daniel Lezcano
  0 siblings, 1 reply; 112+ messages in thread
From: Ray Jui @ 2016-06-20 17:50 UTC (permalink / raw)
  To: Daniel Lezcano, tglx
  Cc: linux-kernel, f.fainelli, sbranden, bcm-kernel-feedback-list

Hi Daniel,

On 6/20/2016 10:48 AM, Daniel Lezcano wrote:
> 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/bcm_kona_timer.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c
> index e717e87..c251aa6 100644
> --- a/drivers/clocksource/bcm_kona_timer.c
> +++ b/drivers/clocksource/bcm_kona_timer.c
> @@ -163,16 +163,11 @@ static struct irqaction kona_timer_irq = {
>  	.handler = kona_timer_interrupt,
>  };
>
> -static void __init kona_timer_init(struct device_node *node)
> +static int __init kona_timer_init(struct device_node *node)
>  {
>  	u32 freq;
>  	struct clk *external_clk;
>
> -	if (!of_device_is_available(node)) {
> -		pr_info("Kona Timer v1 marked as disabled in device tree\n");
> -		return;
> -	}
> -
>  	external_clk = of_clk_get_by_name(node, NULL);
>
>  	if (!IS_ERR(external_clk)) {
> @@ -182,7 +177,7 @@ static void __init kona_timer_init(struct device_node *node)
>  		arch_timer_rate = freq;
>  	} else {
>  		pr_err("Kona Timer v1 unable to determine clock-frequency");
> -		return;
> +		return -EINVAL;
>  	}
>
>  	/* Setup IRQ numbers */
> @@ -196,11 +191,13 @@ static void __init kona_timer_init(struct device_node *node)
>  	kona_timer_clockevents_init();
>  	setup_irq(timers.tmr_irq, &kona_timer_irq);
>  	kona_timer_set_next_event((arch_timer_rate / HZ), NULL);
> +
> +	return 0;
>  }
>
> -CLOCKSOURCE_OF_DECLARE(brcm_kona, "brcm,kona-timer", kona_timer_init);
> +CLOCKSOURCE_OF_DECLARE_RET(brcm_kona, "brcm,kona-timer", kona_timer_init);
>  /*
>   * bcm,kona-timer is deprecated by brcm,kona-timer
>   * being kept here for driver compatibility
>   */
> -CLOCKSOURCE_OF_DECLARE(bcm_kona, "bcm,kona-timer", kona_timer_init);
> +CLOCKSOURCE_OF_DECLARE_RET(bcm_kona, "bcm,kona-timer", kona_timer_init);

Looks good to me!

Acked-by: Ray Jui <ray.jui@broadcom.com>

Thanks,

Ray

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/bcm_kona: Convert init function to return error
  2016-06-20 17:50       ` Ray Jui
@ 2016-06-20 20:12         ` Daniel Lezcano
  0 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-20 20:12 UTC (permalink / raw)
  To: Ray Jui, tglx
  Cc: linux-kernel, f.fainelli, sbranden, bcm-kernel-feedback-list

On 06/20/2016 07:50 PM, Ray Jui wrote:

[ ... ]

>> -CLOCKSOURCE_OF_DECLARE(bcm_kona, "bcm,kona-timer", kona_timer_init);
>> +CLOCKSOURCE_OF_DECLARE_RET(bcm_kona, "bcm,kona-timer", kona_timer_init);
>
> Looks good to me!
>
> Acked-by: Ray Jui <ray.jui@broadcom.com>

Can you have a quick look at the patch [63/63] for the kona part where 
CLOCKSOURCE_OF_DECLARE_RET is renamed back to CLOCKSOURCE_OF_DECLARE ?

Thanks !

   -- Daniel


-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 01/63] of: Add a new macro to declare_of for one parameter function returning a value
  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
  0 siblings, 0 replies; 112+ messages in thread
From: Rob Herring @ 2016-06-20 21:03 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: Thomas Gleixner, linux-kernel, Frank Rowand, Grant Likely,
	open list:OPEN FIRMWARE AND...

On Thu, Jun 16, 2016 at 4:26 PM, Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:
> The macro OF_DECLARE_1 expect a void (*func)(struct device_node *) while the
> OF_DECLARE_2 expect a int (*func)(struct device_node *, struct device_node *).
>
> The second one allows to pass an init function returning a value, which make
> possible to call the functions in the table and check the return value in order
> to catch at a higher level the errors and handle them from there instead of
> doing a panic in each driver (well at least this is the case for the clkevt).
>
> Unfortunately the OF_DECLARE_1 does not allow that and that lead to some code
> duplication and crappyness in the drivers.
>
> The OF_DECLARE_1 is used by all the clk drivers and the clocksource/clockevent
> drivers. It is not possible to do the change in one shot as we have to change
> all the init functions.
>
> The OF_DECLARE_2 specifies an init function prototype with two parameters with
> the node and its parent. The latter won't be used, ever, in the timer drivers.
>
> Introduce a OF_DECLARE_1_RET macro to be used, and hopefully we can smoothly
> and iteratively change the users of OF_DECLARE_1 to use the new macro instead.
>
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
>  include/linux/of.h | 3 +++
>  1 file changed, 3 insertions(+)

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/arc: Convert init function to return error
  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
  1 sibling, 1 reply; 112+ messages in thread
From: Vineet Gupta @ 2016-06-24  4:06 UTC (permalink / raw)
  To: Daniel Lezcano, tglx; +Cc: linux-kernel, linux-snps-arc

On Friday 17 June 2016 03:39 PM, Daniel Lezcano wrote:
> 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/arc/kernel/time.c | 69 ++++++++++++++++++++++++++++++--------------------

[...]

>  	evt->cpumask = cpumask_of(smp_processor_id());
> @@ -347,24 +355,31 @@ static void __init arc_clockevent_setup(struct device_node *node)
>  	/* Needs apriori irq_set_percpu_devid() done in intc map function */
>  	ret = request_percpu_irq(arc_timer_irq, timer_irq_handler,
>  				 "Timer0 (per-cpu-tick)", evt);
> -	if (ret)
> -		panic("clockevent: unable to request irq\n");
> +	if (ret) {
> +		pr_err("clockevent: unable to request irq\n");
> +		returnr ret;

oops I missed the typo here !
Daniel can u squash this to ur patch !

-Vineet

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/arc: Convert init function to return error
  2016-06-24  4:06       ` Vineet Gupta
@ 2016-06-24  6:41         ` Daniel Lezcano
  2016-06-24  7:52           ` Vineet Gupta
  0 siblings, 1 reply; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-24  6:41 UTC (permalink / raw)
  To: Vineet Gupta, tglx; +Cc: linux-kernel, linux-snps-arc

On 06/24/2016 06:06 AM, Vineet Gupta wrote:
> On Friday 17 June 2016 03:39 PM, Daniel Lezcano wrote:
>> 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/arc/kernel/time.c | 69 ++++++++++++++++++++++++++++++--------------------
>
> [...]
>
>>   	evt->cpumask = cpumask_of(smp_processor_id());
>> @@ -347,24 +355,31 @@ static void __init arc_clockevent_setup(struct device_node *node)
>>   	/* Needs apriori irq_set_percpu_devid() done in intc map function */
>>   	ret = request_percpu_irq(arc_timer_irq, timer_irq_handler,
>>   				 "Timer0 (per-cpu-tick)", evt);
>> -	if (ret)
>> -		panic("clockevent: unable to request irq\n");
>> +	if (ret) {
>> +		pr_err("clockevent: unable to request irq\n");
>> +		returnr ret;
>
> oops I missed the typo here !
> Daniel can u squash this to ur patch !

Yes, no problem.

Do you agree to move the driver to drivers/clocksource, so we can add 
the COMPILE_TEST option ?

Thanks.

   -- Daniel


-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/arc: Convert init function to return error
  2016-06-24  6:41         ` Daniel Lezcano
@ 2016-06-24  7:52           ` Vineet Gupta
  2016-06-24  7:55             ` Daniel Lezcano
  0 siblings, 1 reply; 112+ messages in thread
From: Vineet Gupta @ 2016-06-24  7:52 UTC (permalink / raw)
  To: Daniel Lezcano, tglx; +Cc: linux-kernel, linux-snps-arc

On Friday 24 June 2016 12:11 PM, Daniel Lezcano wrote:
> Do you agree to move the driver to drivers/clocksource, so we can add the
> COMPILE_TEST option ?

Sure, this will require some common header adjustments etc. After the current
fire-drill I'm pulled into ATM, I'll work on it next week'ish !

-Vineet

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V3] clocksource/drivers/arc: Convert init function to return error
  2016-06-24  7:52           ` Vineet Gupta
@ 2016-06-24  7:55             ` Daniel Lezcano
  0 siblings, 0 replies; 112+ messages in thread
From: Daniel Lezcano @ 2016-06-24  7:55 UTC (permalink / raw)
  To: Vineet Gupta, tglx; +Cc: linux-kernel, linux-snps-arc

On 06/24/2016 09:52 AM, Vineet Gupta wrote:
> On Friday 24 June 2016 12:11 PM, Daniel Lezcano wrote:
>> Do you agree to move the driver to drivers/clocksource, so we can add the
>> COMPILE_TEST option ?
>
> Sure, this will require some common header adjustments etc. After the current
> fire-drill I'm pulled into ATM, I'll work on it next week'ish !

Great, thanks !


-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 112+ messages in thread

* Re: [PATCH V2 13/63] clocksource/drivers/bcm2835_timer: Convert init function to return error
  2016-06-16 21:26 ` [PATCH V2 13/63] clocksource/drivers/bcm2835_timer: " Daniel Lezcano
@ 2016-06-26  3:10   ` Eric Anholt
  0 siblings, 0 replies; 112+ messages in thread
From: Eric Anholt @ 2016-06-26  3:10 UTC (permalink / raw)
  To: Daniel Lezcano, daniel.lezcano, tglx
  Cc: linux-kernel, Stephen Warren, Lee Jones,
	moderated list:BROADCOM BCM2835...,
	moderated list:BROADCOM BCM2835...

[-- Attachment #1: Type: text/plain, Size: 760 bytes --]

Daniel Lezcano <daniel.lezcano@linaro.org> writes:

> 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>

For the bcm2835 changes here and in 63/63:

Acked-by: Eric Anholt <eric@anholt.net>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 112+ messages in thread

end of thread, other threads:[~2016-06-26  4:26 UTC | newest]

Thread overview: 112+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [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

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).