[PATCH 03/12] timer: Protect lockdep functions with #ifdef

From: Namhyung Kim
Date: Tue Feb 08 2022 - 13:42:32 EST


With upcoming lock tracepoints config, it'd define some of lockdep
functions without enabling CONFIG_LOCKDEP actually. The existing code
assumes those functions will be removed by the preprocessor but it's
not the case anymore. Let's protect the code with #ifdef's explicitly.

Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
kernel/time/timer.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 85f1021ad459..4af95dbf6435 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -794,7 +794,10 @@ static void do_init_timer(struct timer_list *timer,
if (WARN_ON_ONCE(flags & ~TIMER_INIT_FLAGS))
flags &= TIMER_INIT_FLAGS;
timer->flags = flags | raw_smp_processor_id();
+
+#ifdef CONFIG_LOCKDEP
lockdep_init_map(&timer->lockdep_map, name, key, 0);
+#endif
}

/**
@@ -1409,19 +1412,22 @@ static void call_timer_fn(struct timer_list *timer,
struct lockdep_map lockdep_map;

lockdep_copy_map(&lockdep_map, &timer->lockdep_map);
-#endif
+
/*
* Couple the lock chain with the lock chain at
* del_timer_sync() by acquiring the lock_map around the fn()
* call here and in del_timer_sync().
*/
lock_map_acquire(&lockdep_map);
+#endif

trace_timer_expire_entry(timer, baseclk);
fn(timer);
trace_timer_expire_exit(timer);

+#ifdef CONFIG_LOCKDEP
lock_map_release(&lockdep_map);
+#endif

if (count != preempt_count()) {
WARN_ONCE(1, "timer: %pS preempt leak: %08x -> %08x\n",
--
2.35.0.263.gb82422642f-goog