summaryrefslogtreecommitdiffstats
path: root/debian/patches-rt/0342-local_lock-Provide-INIT_LOCAL_LOCK.patch
blob: 1f4b60d12d010ec65404e5db4d50a2b588d104bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Fri, 21 Oct 2022 15:55:39 +0200
Subject: [PATCH 342/353] local_lock: Provide INIT_LOCAL_LOCK().
Origin: https://git.kernel.org/cgit/linux/kernel/git/rt/linux-stable-rt.git/commit?id=41193143552afd68eb43331c8f06b53b09ac8cce

The original code was using INIT_LOCAL_LOCK() and I tried to sneak
around it and forgot that this code also needs to compile on !RT
platforms.

Provide INIT_LOCAL_LOCK() to initialize properly on RT and do nothing on
!RT. Let random.c use which is the only user so far and oes not compile
on !RT otherwise.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/all/YzcEIU17EIZ7ZIF5@linutronix.de/
Signed-off-by: Daniel Wagner <wagi@monom.org>
---
 drivers/char/random.c     | 4 ++--
 include/linux/locallock.h | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index be2b7520ade9..c72dcfbff608 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -235,7 +235,7 @@ struct crng {
 
 static DEFINE_PER_CPU(struct crng, crngs) = {
 	.generation = ULONG_MAX,
-	.lock.lock = __SPIN_LOCK_UNLOCKED(crngs.lock.lock),
+	.lock =  INIT_LOCAL_LOCK(crngs.lock),
 };
 
 /* Used by crng_reseed() and crng_make_state() to extract a new seed from the input pool. */
@@ -514,7 +514,7 @@ struct batch_ ##type {								\
 };										\
 										\
 static DEFINE_PER_CPU(struct batch_ ##type, batched_entropy_ ##type) = {	\
-	.lock.lock = __SPIN_LOCK_UNLOCKED(batched_entropy_ ##type.lock.lock),	\
+	.lock = INIT_LOCAL_LOCK(batched_entropy_ ##type.lock),			\
 	.position = UINT_MAX							\
 };										\
 										\
diff --git a/include/linux/locallock.h b/include/linux/locallock.h
index 81c89d87723b..7964ee6b998c 100644
--- a/include/linux/locallock.h
+++ b/include/linux/locallock.h
@@ -23,6 +23,8 @@ struct local_irq_lock {
 	unsigned long		flags;
 };
 
+#define INIT_LOCAL_LOCK(lvar)			{ .lock = __SPIN_LOCK_UNLOCKED((lvar).lock.lock) }
+
 #define DEFINE_LOCAL_IRQ_LOCK(lvar)					\
 	DEFINE_PER_CPU(struct local_irq_lock, lvar) = {			\
 		.lock = __SPIN_LOCK_UNLOCKED((lvar).lock) }
@@ -241,6 +243,9 @@ static inline int __local_unlock_irqrestore(struct local_irq_lock *lv,
 
 #else /* PREEMPT_RT_BASE */
 
+struct local_irq_lock { };
+#define INIT_LOCAL_LOCK(lvar)			{ }
+
 #define DEFINE_LOCAL_IRQ_LOCK(lvar)		__typeof__(const int) lvar
 #define DECLARE_LOCAL_IRQ_LOCK(lvar)		extern __typeof__(const int) lvar