Skip to content

Commit 2747b93

Browse files
Sebastian Andrzej SiewiorPeter Zijlstra
authored andcommitted
locking: Detect includes rwlock.h outside of spinlock.h
From: Michael S. Tsirkin <[email protected]> The check for __LINUX_SPINLOCK_H within rwlock.h (and other files) detects the direct include of the header file if it is at the very beginning of the include section. If it is listed later then chances are high that spinlock.h was already included (including rwlock.h) and the additional listing of rwlock.h will not cause any failure. On PREEMPT_RT this additional rwlock.h will lead to compile failures since it uses a different rwlock implementation. Add __LINUX_INSIDE_SPINLOCK_H to spinlock.h and check for this instead of __LINUX_SPINLOCK_H to detect wrong includes. This will help detect direct includes of rwlock.h with without PREEMPT_RT enabled. [ bigeasy: add remaining __LINUX_SPINLOCK_H user and rewrite commit description. ] Signed-off-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 501f7f6 commit 2747b93

File tree

6 files changed

+7
-5
lines changed

6 files changed

+7
-5
lines changed

include/linux/rwlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __LINUX_RWLOCK_H
22
#define __LINUX_RWLOCK_H
33

4-
#ifndef __LINUX_SPINLOCK_H
4+
#ifndef __LINUX_INSIDE_SPINLOCK_H
55
# error "please don't include this file directly"
66
#endif
77

include/linux/spinlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#ifndef __LINUX_SPINLOCK_H
33
#define __LINUX_SPINLOCK_H
4+
#define __LINUX_INSIDE_SPINLOCK_H
45

56
/*
67
* include/linux/spinlock.h - generic spinlock/rwlock declarations
@@ -492,4 +493,5 @@ int __alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *lock_mask,
492493

493494
void free_bucket_spinlocks(spinlock_t *locks);
494495

496+
#undef __LINUX_INSIDE_SPINLOCK_H
495497
#endif /* __LINUX_SPINLOCK_H */

include/linux/spinlock_api_smp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __LINUX_SPINLOCK_API_SMP_H
22
#define __LINUX_SPINLOCK_API_SMP_H
33

4-
#ifndef __LINUX_SPINLOCK_H
4+
#ifndef __LINUX_INSIDE_SPINLOCK_H
55
# error "please don't include this file directly"
66
#endif
77

include/linux/spinlock_api_up.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __LINUX_SPINLOCK_API_UP_H
22
#define __LINUX_SPINLOCK_API_UP_H
33

4-
#ifndef __LINUX_SPINLOCK_H
4+
#ifndef __LINUX_INSIDE_SPINLOCK_H
55
# error "please don't include this file directly"
66
#endif
77

include/linux/spinlock_rt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef __LINUX_SPINLOCK_RT_H
33
#define __LINUX_SPINLOCK_RT_H
44

5-
#ifndef __LINUX_SPINLOCK_H
5+
#ifndef __LINUX_INSIDE_SPINLOCK_H
66
#error Do not include directly. Use spinlock.h
77
#endif
88

include/linux/spinlock_up.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __LINUX_SPINLOCK_UP_H
22
#define __LINUX_SPINLOCK_UP_H
33

4-
#ifndef __LINUX_SPINLOCK_H
4+
#ifndef __LINUX_INSIDE_SPINLOCK_H
55
# error "please don't include this file directly"
66
#endif
77

0 commit comments

Comments
 (0)