Skip to content

Commit 3d5a965

Browse files
committed
clocksource: make CLOCKSOURCE_OF_DECLARE type safe
This ensures that a function pointer passed into CLOCKSOURCE_OF_DECLARE takes the same arguments that we use for calling that function later. Also fix the extraneous semicolon at end of the CLOCKSOURCE_OF_DECLARE definition. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Rob Herring <rob.herring@calxeda.com>
1 parent da4a686 commit 3d5a965

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎drivers/clocksource/clksrc-of.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <linux/init.h>
1818
#include <linux/of.h>
19+
#include <linux/clocksource.h>
1920

2021
extern struct of_device_id __clksrc_of_table[];
2122

@@ -26,7 +27,7 @@ void __init clocksource_of_init(void)
2627
{
2728
struct device_node *np;
2829
const struct of_device_id *match;
29-
void (*init_func)(struct device_node *);
30+
clocksource_of_init_fn init_func;
3031

3132
for_each_matching_node_and_match(np, __clksrc_of_table, &match) {
3233
init_func = match->data;

‎drivers/clocksource/vt8500_timer.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,4 @@ static void __init vt8500_timer_init(struct device_node *np)
165165
4, 0xf0000000);
166166
}
167167

168-
CLOCKSOURCE_OF_DECLARE(vt8500, "via,vt8500-timer", vt8500_timer_init)
168+
CLOCKSOURCE_OF_DECLARE(vt8500, "via,vt8500-timer", vt8500_timer_init);

‎include/linux/clocksource.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,23 @@ extern int clocksource_mmio_init(void __iomem *, const char *,
332332

333333
extern int clocksource_i8253_init(void);
334334

335+
struct device_node;
336+
typedef void(*clocksource_of_init_fn)(struct device_node *);
335337
#ifdef CONFIG_CLKSRC_OF
336338
extern void clocksource_of_init(void);
337339

338340
#define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \
339341
static const struct of_device_id __clksrc_of_table_##name \
340342
__used __section(__clksrc_of_table) \
341-
= { .compatible = compat, .data = fn };
343+
= { .compatible = compat, \
344+
.data = (fn == (clocksource_of_init_fn)NULL) ? fn : fn }
342345
#else
343346
static inline void clocksource_of_init(void) {}
344-
#define CLOCKSOURCE_OF_DECLARE(name, compat, fn)
347+
#define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \
348+
static const struct of_device_id __clksrc_of_table_##name \
349+
__attribute__((unused)) \
350+
= { .compatible = compat, \
351+
.data = (fn == (clocksource_of_init_fn)NULL) ? fn : fn }
345352
#endif
346353

347354
#endif /* _LINUX_CLOCKSOURCE_H */

0 commit comments

Comments
 (0)