linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/9] clocksource/drivers/rockchip_timer: Convert init function to return error
       [not found] <1464770093-12667-1-git-send-email-daniel.lezcano@linaro.org>
@ 2016-06-01  8:34 ` Daniel Lezcano
  2016-06-01  8:34 ` [PATCH 4/9] clocksource/drivers/mkt_timer: " Daniel Lezcano
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Daniel Lezcano @ 2016-06-01  8:34 UTC (permalink / raw)
  To: 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 | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/rockchip_timer.c b/drivers/clocksource/rockchip_timer.c
index b991b28..36b0209 100644
--- a/drivers/clocksource/rockchip_timer.c
+++ b/drivers/clocksource/rockchip_timer.c
@@ -106,17 +106,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)
+static int __init rk_timer_init(struct device_node *np)
 {
 	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;
 	}
 
 	pclk = of_clk_get_by_name(np, "pclk");
@@ -169,7 +169,7 @@ static void __init rk_timer_init(struct device_node *np)
 
 	clockevents_config_and_register(ce, bc_timer.freq, 1, UINT_MAX);
 
-	return;
+	return 0;
 
 out_irq:
 	clk_disable_unprepare(timer_clk);
@@ -177,6 +177,8 @@ out_timer_clk:
 	clk_disable_unprepare(pclk);
 out_unmap:
 	iounmap(bc_timer.base);
+
+	return ret;
 }
 
-CLOCKSOURCE_OF_DECLARE(rk_timer, "rockchip,rk3288-timer", rk_timer_init);
+CLOCKSOURCE_OF_DECLARE_RET(rk_timer, "rockchip,rk3288-timer", rk_timer_init);
-- 
1.9.1

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

* [PATCH 4/9] clocksource/drivers/mkt_timer: Convert init function to return error
       [not found] <1464770093-12667-1-git-send-email-daniel.lezcano@linaro.org>
  2016-06-01  8:34 ` [PATCH 3/9] clocksource/drivers/rockchip_timer: Convert init function to return error Daniel Lezcano
@ 2016-06-01  8:34 ` Daniel Lezcano
  2016-06-01  8:34 ` [PATCH 5/9] clocksource/drivers/exynos_mct: " Daniel Lezcano
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Daniel Lezcano @ 2016-06-01  8:34 UTC (permalink / raw)
  To: 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/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] 10+ messages in thread

* [PATCH 5/9] clocksource/drivers/exynos_mct: Convert init function to return error
       [not found] <1464770093-12667-1-git-send-email-daniel.lezcano@linaro.org>
  2016-06-01  8:34 ` [PATCH 3/9] clocksource/drivers/rockchip_timer: Convert init function to return error Daniel Lezcano
  2016-06-01  8:34 ` [PATCH 4/9] clocksource/drivers/mkt_timer: " Daniel Lezcano
@ 2016-06-01  8:34 ` Daniel Lezcano
  2016-06-06 10:51   ` Krzysztof Kozlowski
  2016-06-01  8:34 ` [PATCH 7/9] clocksource/drivers/cadence_ttc: " Daniel Lezcano
  2016-06-01  8:34 ` [PATCH 8/9] clocksource/drivers/st_lpc: " Daniel Lezcano
  4 siblings, 1 reply; 10+ messages in thread
From: Daniel Lezcano @ 2016-06-01  8:34 UTC (permalink / raw)
  To: 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/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] 10+ messages in thread

* [PATCH 7/9] clocksource/drivers/cadence_ttc: Convert init function to return error
       [not found] <1464770093-12667-1-git-send-email-daniel.lezcano@linaro.org>
                   ` (2 preceding siblings ...)
  2016-06-01  8:34 ` [PATCH 5/9] clocksource/drivers/exynos_mct: " Daniel Lezcano
@ 2016-06-01  8:34 ` Daniel Lezcano
  2016-06-01 14:36   ` Sören Brinkmann
  2016-06-01  8:34 ` [PATCH 8/9] clocksource/drivers/st_lpc: " Daniel Lezcano
  4 siblings, 1 reply; 10+ messages in thread
From: Daniel Lezcano @ 2016-06-01  8:34 UTC (permalink / raw)
  To: 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/cadence_ttc_timer.c | 82 +++++++++++++++++++--------------
 1 file changed, 48 insertions(+), 34 deletions(-)

diff --git a/drivers/clocksource/cadence_ttc_timer.c b/drivers/clocksource/cadence_ttc_timer.c
index 9be6018..aa36cbf 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,9 +345,13 @@ 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");
+		return err;
+	}
 
 	ttccs->ttc.base_addr = base;
 	ttccs->cs.name = "ttc_clocksource";
@@ -368,14 +372,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 +407,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 +462,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,20 +479,14 @@ 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;
-
-	initialized = 1;
-
 	/*
 	 * Get the 1st Triple Timer Counter (TTC) block from the device tree
 	 * and use it. Note that the event timer uses the interrupt and it's the
@@ -488,13 +495,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 +511,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 +519,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@%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] 10+ messages in thread

* [PATCH 8/9] clocksource/drivers/st_lpc: Convert init function to return error
       [not found] <1464770093-12667-1-git-send-email-daniel.lezcano@linaro.org>
                   ` (3 preceding siblings ...)
  2016-06-01  8:34 ` [PATCH 7/9] clocksource/drivers/cadence_ttc: " Daniel Lezcano
@ 2016-06-01  8:34 ` Daniel Lezcano
  4 siblings, 0 replies; 10+ messages in thread
From: Daniel Lezcano @ 2016-06-01  8:34 UTC (permalink / raw)
  To: 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/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] 10+ messages in thread

* [PATCH 7/9] clocksource/drivers/cadence_ttc: Convert init function to return error
  2016-06-01  8:34 ` [PATCH 7/9] clocksource/drivers/cadence_ttc: " Daniel Lezcano
@ 2016-06-01 14:36   ` Sören Brinkmann
  2016-06-01 14:43     ` Daniel Lezcano
  0 siblings, 1 reply; 10+ messages in thread
From: Sören Brinkmann @ 2016-06-01 14:36 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Daniel,

On Wed, 2016-06-01 at 10:34:50 +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/cadence_ttc_timer.c | 82 +++++++++++++++++++--------------
>  1 file changed, 48 insertions(+), 34 deletions(-)
> 
[...]
>  	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;

So far we handle this as warning only and move on, as the notifier is
only needed when frequency scaling is enabled. And even then, the effect
is usually just that timing is off.

> +	}
> +
>  	ttcce->ttc.freq = clk_get_rate(ttcce->ttc.clk);
>  
>  	ttcce->ttc.base_addr = base;
> @@ -451,13 +462,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,20 +479,14 @@ 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;
> -
> -	initialized = 1;
> -

This also changes behavior. We have multiple of these timer modules in
our HW and we don't want them all to be used for time keeping. This
construct made sure that we only use the first timer for which init is
called leaving the others for non-OS purposes.

	S?ren

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

* [PATCH 7/9] clocksource/drivers/cadence_ttc: Convert init function to return error
  2016-06-01 14:36   ` Sören Brinkmann
@ 2016-06-01 14:43     ` Daniel Lezcano
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Lezcano @ 2016-06-01 14:43 UTC (permalink / raw)
  To: linux-arm-kernel

On 06/01/2016 04:36 PM, S?ren Brinkmann wrote:
> Hi Daniel,

Hi Soren,

[ ... ]

>> +	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;
>
> So far we handle this as warning only and move on, as the notifier is
> only needed when frequency scaling is enabled. And even then, the effect
> is usually just that timing is off.

Ok, I will fix it.

[ ... ]

>> -	static int initialized;
>> -	int clksel;
>> +	int clksel, ret;
>>   	u32 timer_width = 16;
>>
>> -	if (initialized)
>> -		return;
>> -
>> -	initialized = 1;
>> -
>
> This also changes behavior. We have multiple of these timer modules in
> our HW and we don't want them all to be used for time keeping. This
> construct made sure that we only use the first timer for which init is
> called leaving the others for non-OS purposes.

Ha, yes. My bad, this change was not supposed to be here.

Thanks for spotting this.

   -- 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] 10+ messages in thread

* [PATCH 5/9] clocksource/drivers/exynos_mct: Convert init function to return error
  2016-06-01  8:34 ` [PATCH 5/9] clocksource/drivers/exynos_mct: " Daniel Lezcano
@ 2016-06-06 10:51   ` Krzysztof Kozlowski
  2016-06-06 11:23     ` Daniel Lezcano
  0 siblings, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2016-06-06 10:51 UTC (permalink / raw)
  To: linux-arm-kernel

On 06/01/2016 10:34 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.

I don't see the benefits of this change alone. You are replacing one
non-return code to another always-return-success code. The effect is
exactly the same. It would make sense to change it to CLOCKSOURCE_OF_RET
along with proper error handling.

Best regards,
Krzysztof

> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
>  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);
> 

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

* [PATCH 5/9] clocksource/drivers/exynos_mct: Convert init function to return error
  2016-06-06 10:51   ` Krzysztof Kozlowski
@ 2016-06-06 11:23     ` Daniel Lezcano
  2016-06-06 11:28       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Lezcano @ 2016-06-06 11:23 UTC (permalink / raw)
  To: linux-arm-kernel

On 06/06/2016 12:51 PM, Krzysztof Kozlowski wrote:
> On 06/01/2016 10:34 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.
>
> I don't see the benefits of this change alone. You are replacing one
> non-return code to another always-return-success code. The effect is
> exactly the same. It would make sense to change it to CLOCKSOURCE_OF_RET
> along with proper error handling.
>

Hi Krzysztof,

I can understand you expect an error handling but, as stated in the 
changelog, proper error handling will be done later. Currently, there 
are roughly 80 drivers to changes the init function to return a value in 
order change the CLOCKSOURCE_OF_DECLARE macro. That is a quite important 
number and changing also the internals will introduce bugs.

So the series (and there is a huge one coming right after this one), 
will focus only on changing the init function to return a value, so we 
can swap the clocksource table and rename CLOCKSOURCE_OF_DECLARE_RET 
without the '_RET'. I want this to be done before the next PR in order 
to prevent to have a double clksrc table.

If error handling is already taken into account and is trivial, I try to 
do the change, otherwise I let the function to return a success value.

Regarding the important number of drivers, if you have time to change 
the init function in the exynos_mct, that will be more than welcome :)

   -- 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] 10+ messages in thread

* [PATCH 5/9] clocksource/drivers/exynos_mct: Convert init function to return error
  2016-06-06 11:23     ` Daniel Lezcano
@ 2016-06-06 11:28       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2016-06-06 11:28 UTC (permalink / raw)
  To: linux-arm-kernel

On 06/06/2016 01:23 PM, Daniel Lezcano wrote:
> On 06/06/2016 12:51 PM, Krzysztof Kozlowski wrote:
>> On 06/01/2016 10:34 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.
>>
>> I don't see the benefits of this change alone. You are replacing one
>> non-return code to another always-return-success code. The effect is
>> exactly the same. It would make sense to change it to CLOCKSOURCE_OF_RET
>> along with proper error handling.
>>
> 
> Hi Krzysztof,
> 
> I can understand you expect an error handling but, as stated in the
> changelog, proper error handling will be done later. Currently, there
> are roughly 80 drivers to changes the init function to return a value in
> order change the CLOCKSOURCE_OF_DECLARE macro. That is a quite important
> number and changing also the internals will introduce bugs.
> 
> So the series (and there is a huge one coming right after this one),
> will focus only on changing the init function to return a value, so we
> can swap the clocksource table and rename CLOCKSOURCE_OF_DECLARE_RET
> without the '_RET'. I want this to be done before the next PR in order
> to prevent to have a double clksrc table.
> 
> If error handling is already taken into account and is trivial, I try to
> do the change, otherwise I let the function to return a success value.
> 
> Regarding the important number of drivers, if you have time to change
> the init function in the exynos_mct, that will be more than welcome :)

Ah, okay, you are planning to get rid of CLOCKSOURCE_OF_DECLARE. I
didn't receive the cover letter so the big picture remained hidden. Now
it looks good:

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

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

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

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1464770093-12667-1-git-send-email-daniel.lezcano@linaro.org>
2016-06-01  8:34 ` [PATCH 3/9] clocksource/drivers/rockchip_timer: Convert init function to return error Daniel Lezcano
2016-06-01  8:34 ` [PATCH 4/9] clocksource/drivers/mkt_timer: " Daniel Lezcano
2016-06-01  8:34 ` [PATCH 5/9] clocksource/drivers/exynos_mct: " Daniel Lezcano
2016-06-06 10:51   ` Krzysztof Kozlowski
2016-06-06 11:23     ` Daniel Lezcano
2016-06-06 11:28       ` Krzysztof Kozlowski
2016-06-01  8:34 ` [PATCH 7/9] clocksource/drivers/cadence_ttc: " Daniel Lezcano
2016-06-01 14:36   ` Sören Brinkmann
2016-06-01 14:43     ` Daniel Lezcano
2016-06-01  8:34 ` [PATCH 8/9] clocksource/drivers/st_lpc: " Daniel Lezcano

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