Skip to content

Commit 2ef2538

Browse files
author
Daniel Lezcano
committed
clocksource/drivers/sp804: Convert init function to return error
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>
1 parent 5318650 commit 2ef2538

2 files changed

Lines changed: 63 additions & 35 deletions

File tree

‎drivers/clocksource/timer-sp804.c‎

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void __init sp804_timer_disable(void __iomem *base)
7777
writel(0, base + TIMER_CTRL);
7878
}
7979

80-
void __init __sp804_clocksource_and_sched_clock_init(void __iomem *base,
80+
int __init __sp804_clocksource_and_sched_clock_init(void __iomem *base,
8181
const char *name,
8282
struct clk *clk,
8383
int use_sched_clock)
@@ -89,14 +89,13 @@ void __init __sp804_clocksource_and_sched_clock_init(void __iomem *base,
8989
if (IS_ERR(clk)) {
9090
pr_err("sp804: clock not found: %d\n",
9191
(int)PTR_ERR(clk));
92-
return;
92+
return PTR_ERR(clk);
9393
}
9494
}
9595

9696
rate = sp804_get_clock_rate(clk);
97-
9897
if (rate < 0)
99-
return;
98+
return -EINVAL;
10099

101100
/* setup timer 0 as free-running clocksource */
102101
writel(0, base + TIMER_CTRL);
@@ -112,6 +111,8 @@ void __init __sp804_clocksource_and_sched_clock_init(void __iomem *base,
112111
sched_clock_base = base;
113112
sched_clock_register(sp804_read, 32, rate);
114113
}
114+
115+
return 0;
115116
}
116117

117118

@@ -186,7 +187,7 @@ static struct irqaction sp804_timer_irq = {
186187
.dev_id = &sp804_clockevent,
187188
};
188189

189-
void __init __sp804_clockevents_init(void __iomem *base, unsigned int irq, struct clk *clk, const char *name)
190+
int __init __sp804_clockevents_init(void __iomem *base, unsigned int irq, struct clk *clk, const char *name)
190191
{
191192
struct clock_event_device *evt = &sp804_clockevent;
192193
long rate;
@@ -196,12 +197,12 @@ void __init __sp804_clockevents_init(void __iomem *base, unsigned int irq, struc
196197
if (IS_ERR(clk)) {
197198
pr_err("sp804: %s clock not found: %d\n", name,
198199
(int)PTR_ERR(clk));
199-
return;
200+
return PTR_ERR(clk);
200201
}
201202

202203
rate = sp804_get_clock_rate(clk);
203204
if (rate < 0)
204-
return;
205+
return -EINVAL;
205206

206207
clkevt_base = base;
207208
clkevt_reload = DIV_ROUND_CLOSEST(rate, HZ);
@@ -213,27 +214,31 @@ void __init __sp804_clockevents_init(void __iomem *base, unsigned int irq, struc
213214

214215
setup_irq(irq, &sp804_timer_irq);
215216
clockevents_config_and_register(evt, rate, 0xf, 0xffffffff);
217+
218+
return 0;
216219
}
217220

218-
static void __init sp804_of_init(struct device_node *np)
221+
static int __init sp804_of_init(struct device_node *np)
219222
{
220223
static bool initialized = false;
221224
void __iomem *base;
222-
int irq;
225+
int irq, ret = -EINVAL;
223226
u32 irq_num = 0;
224227
struct clk *clk1, *clk2;
225228
const char *name = of_get_property(np, "compatible", NULL);
226229

227230
base = of_iomap(np, 0);
228-
if (WARN_ON(!base))
229-
return;
231+
if (!base)
232+
return -ENXIO;
230233

231234
/* Ensure timers are disabled */
232235
writel(0, base + TIMER_CTRL);
233236
writel(0, base + TIMER_2_BASE + TIMER_CTRL);
234237

235-
if (initialized || !of_device_is_available(np))
238+
if (initialized || !of_device_is_available(np)) {
239+
ret = -EINVAL;
236240
goto err;
241+
}
237242

238243
clk1 = of_clk_get(np, 0);
239244
if (IS_ERR(clk1))
@@ -256,55 +261,78 @@ static void __init sp804_of_init(struct device_node *np)
256261

257262
of_property_read_u32(np, "arm,sp804-has-irq", &irq_num);
258263
if (irq_num == 2) {
259-
__sp804_clockevents_init(base + TIMER_2_BASE, irq, clk2, name);
260-
__sp804_clocksource_and_sched_clock_init(base, name, clk1, 1);
264+
265+
ret = __sp804_clockevents_init(base + TIMER_2_BASE, irq, clk2, name);
266+
if (ret)
267+
goto err;
268+
269+
ret = __sp804_clocksource_and_sched_clock_init(base, name, clk1, 1);
270+
if (ret)
271+
goto err;
261272
} else {
262-
__sp804_clockevents_init(base, irq, clk1 , name);
263-
__sp804_clocksource_and_sched_clock_init(base + TIMER_2_BASE,
264-
name, clk2, 1);
273+
274+
ret = __sp804_clockevents_init(base, irq, clk1 , name);
275+
if (ret)
276+
goto err;
277+
278+
ret =__sp804_clocksource_and_sched_clock_init(base + TIMER_2_BASE,
279+
name, clk2, 1);
280+
if (ret)
281+
goto err;
265282
}
266283
initialized = true;
267284

268-
return;
285+
return 0;
269286
err:
270287
iounmap(base);
288+
return ret;
271289
}
272-
CLOCKSOURCE_OF_DECLARE(sp804, "arm,sp804", sp804_of_init);
290+
CLOCKSOURCE_OF_DECLARE_RET(sp804, "arm,sp804", sp804_of_init);
273291

274-
static void __init integrator_cp_of_init(struct device_node *np)
292+
static int __init integrator_cp_of_init(struct device_node *np)
275293
{
276294
static int init_count = 0;
277295
void __iomem *base;
278-
int irq;
296+
int irq, ret = -EINVAL;
279297
const char *name = of_get_property(np, "compatible", NULL);
280298
struct clk *clk;
281299

282300
base = of_iomap(np, 0);
283-
if (WARN_ON(!base))
284-
return;
301+
if (!base) {
302+
pr_err("Failed to iomap");
303+
return -ENXIO;
304+
}
305+
285306
clk = of_clk_get(np, 0);
286-
if (WARN_ON(IS_ERR(clk)))
287-
return;
307+
if (IS_ERR(clk)) {
308+
pr_err("Failed to get clock");
309+
return PTR_ERR(clk);
310+
}
288311

289312
/* Ensure timer is disabled */
290313
writel(0, base + TIMER_CTRL);
291314

292315
if (init_count == 2 || !of_device_is_available(np))
293316
goto err;
294317

295-
if (!init_count)
296-
__sp804_clocksource_and_sched_clock_init(base, name, clk, 0);
297-
else {
318+
if (!init_count) {
319+
ret = __sp804_clocksource_and_sched_clock_init(base, name, clk, 0);
320+
if (ret)
321+
goto err;
322+
} else {
298323
irq = irq_of_parse_and_map(np, 0);
299324
if (irq <= 0)
300325
goto err;
301326

302-
__sp804_clockevents_init(base, irq, clk, name);
327+
ret = __sp804_clockevents_init(base, irq, clk, name);
328+
if (ret)
329+
goto err;
303330
}
304331

305332
init_count++;
306-
return;
333+
return 0;
307334
err:
308335
iounmap(base);
336+
return ret;
309337
}
310-
CLOCKSOURCE_OF_DECLARE(intcp, "arm,integrator-cp-timer", integrator_cp_of_init);
338+
CLOCKSOURCE_OF_DECLARE_RET(intcp, "arm,integrator-cp-timer", integrator_cp_of_init);

‎include/clocksource/timer-sp804.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
struct clk;
55

6-
void __sp804_clocksource_and_sched_clock_init(void __iomem *,
7-
const char *, struct clk *, int);
8-
void __sp804_clockevents_init(void __iomem *, unsigned int,
9-
struct clk *, const char *);
6+
int __sp804_clocksource_and_sched_clock_init(void __iomem *,
7+
const char *, struct clk *, int);
8+
int __sp804_clockevents_init(void __iomem *, unsigned int,
9+
struct clk *, const char *);
1010
void sp804_timer_disable(void __iomem *);
1111

1212
static inline void sp804_clocksource_init(void __iomem *base, const char *name)

0 commit comments

Comments
 (0)