Skip to content

Commit 72f47a3

Browse files
Marc Zyngierdlezcano
authored andcommitted
clocksource/drivers/arm_arch_timer: Fix MMIO base address vs callback ordering issue
The MMIO timer base address gets published after we have registered the callbacks and the interrupt handler, which is... a bit dangerous. Fix this by moving the base address publication to the point where we register the timer, and expose a pointer to the timer structure itself rather than a naked value. Reviewed-by: Oliver Upton <oupton@google.com> Reviewed-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20211017124225.3018098-7-maz@kernel.org Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
1 parent ac9ef4f commit 72f47a3

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

drivers/clocksource/arm_arch_timer.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454

5555
static unsigned arch_timers_present __initdata;
5656

57-
static void __iomem *arch_counter_base __ro_after_init;
58-
5957
struct arch_timer {
6058
void __iomem *base;
6159
struct clock_event_device evt;
6260
};
6361

62+
static struct arch_timer *arch_timer_mem __ro_after_init;
63+
6464
#define to_arch_timer(e) container_of(e, struct arch_timer, evt)
6565

6666
static u32 arch_timer_rate __ro_after_init;
@@ -973,9 +973,9 @@ static u64 arch_counter_get_cntvct_mem(void)
973973
u32 vct_lo, vct_hi, tmp_hi;
974974

975975
do {
976-
vct_hi = readl_relaxed(arch_counter_base + CNTVCT_HI);
977-
vct_lo = readl_relaxed(arch_counter_base + CNTVCT_LO);
978-
tmp_hi = readl_relaxed(arch_counter_base + CNTVCT_HI);
976+
vct_hi = readl_relaxed(arch_timer_mem->base + CNTVCT_HI);
977+
vct_lo = readl_relaxed(arch_timer_mem->base + CNTVCT_LO);
978+
tmp_hi = readl_relaxed(arch_timer_mem->base + CNTVCT_HI);
979979
} while (vct_hi != tmp_hi);
980980

981981
return ((u64) vct_hi << 32) | vct_lo;
@@ -1166,25 +1166,25 @@ static int __init arch_timer_mem_register(void __iomem *base, unsigned int irq)
11661166
{
11671167
int ret;
11681168
irq_handler_t func;
1169-
struct arch_timer *t;
11701169

1171-
t = kzalloc(sizeof(*t), GFP_KERNEL);
1172-
if (!t)
1170+
arch_timer_mem = kzalloc(sizeof(*arch_timer_mem), GFP_KERNEL);
1171+
if (!arch_timer_mem)
11731172
return -ENOMEM;
11741173

1175-
t->base = base;
1176-
t->evt.irq = irq;
1177-
__arch_timer_setup(ARCH_TIMER_TYPE_MEM, &t->evt);
1174+
arch_timer_mem->base = base;
1175+
arch_timer_mem->evt.irq = irq;
1176+
__arch_timer_setup(ARCH_TIMER_TYPE_MEM, &arch_timer_mem->evt);
11781177

11791178
if (arch_timer_mem_use_virtual)
11801179
func = arch_timer_handler_virt_mem;
11811180
else
11821181
func = arch_timer_handler_phys_mem;
11831182

1184-
ret = request_irq(irq, func, IRQF_TIMER, "arch_mem_timer", &t->evt);
1183+
ret = request_irq(irq, func, IRQF_TIMER, "arch_mem_timer", &arch_timer_mem->evt);
11851184
if (ret) {
11861185
pr_err("Failed to request mem timer irq\n");
1187-
kfree(t);
1186+
kfree(arch_timer_mem);
1187+
arch_timer_mem = NULL;
11881188
}
11891189

11901190
return ret;
@@ -1442,7 +1442,6 @@ arch_timer_mem_frame_register(struct arch_timer_mem_frame *frame)
14421442
return ret;
14431443
}
14441444

1445-
arch_counter_base = base;
14461445
arch_timers_present |= ARCH_TIMER_TYPE_MEM;
14471446

14481447
return 0;

0 commit comments

Comments
 (0)