[PATCH v2] timer: Mask illegal set of flags in do_init_timer()
From: Qianli Zhao
Date: Thu Aug 13 2020 - 11:03:24 EST
From: Qianli Zhao <zhaoqianli@xxxxxxxxxx>
do_init_timer() can specify flags of timer_list,
only TIMER_DEFFERABLE, TIMER_PINNED, TIMER_IRQSAFE are legal
do a sanity check, mask and warning illegal set of flags
Signed-off-by: Qianli Zhao <zhaoqianli@xxxxxxxxxx>
---
V2:
- update changelog
- mask and warning illegal set
---
include/linux/timer.h | 1 +
kernel/time/timer.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 07910ae..d10bc7e 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -67,6 +67,7 @@ struct timer_list {
#define TIMER_DEFERRABLE 0x00080000
#define TIMER_PINNED 0x00100000
#define TIMER_IRQSAFE 0x00200000
+#define TIMER_INIT_FLAGS (TIMER_DEFERRABLE | TIMER_PINNED | TIMER_IRQSAFE)
#define TIMER_ARRAYSHIFT 22
#define TIMER_ARRAYMASK 0xFFC00000
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 026ac01..f7398ab 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -789,6 +789,8 @@ static void do_init_timer(struct timer_list *timer,
{
timer->entry.pprev = NULL;
timer->function = func;
+ if (WARN_ON(flags & ~TIMER_INIT_FLAGS))
+ flags &= TIMER_INIT_FLAGS;
timer->flags = flags | raw_smp_processor_id();
lockdep_init_map(&timer->lockdep_map, name, key, 0);
}
--
2.7.4