Skip to content

Commit 4d2076f

Browse files
committed
compiler_types: Move lock checking attributes to compiler-capability-analysis.h
The conditional definition of lock checking macros and attributes is about to become more complex. Factor them out into their own header for better readability, and to make it obvious which features are supported by which mode (currently only Sparse). This is the first step towards generalizing towards "capability analysis". No functional change intended. Signed-off-by: Marco Elver <[email protected]>
1 parent 2014c95 commit 4d2076f

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Macros and attributes for compiler-based static capability analysis.
4+
*/
5+
6+
#ifndef _LINUX_COMPILER_CAPABILITY_ANALYSIS_H
7+
#define _LINUX_COMPILER_CAPABILITY_ANALYSIS_H
8+
9+
#ifdef __CHECKER__
10+
11+
/* Sparse context/lock checking support. */
12+
# define __must_hold(x) __attribute__((context(x,1,1)))
13+
# define __acquires(x) __attribute__((context(x,0,1)))
14+
# define __cond_acquires(x) __attribute__((context(x,0,-1)))
15+
# define __releases(x) __attribute__((context(x,1,0)))
16+
# define __acquire(x) __context__(x,1)
17+
# define __release(x) __context__(x,-1)
18+
# define __cond_lock(x, c) ((c) ? ({ __acquire(x); 1; }) : 0)
19+
20+
#else /* !__CHECKER__ */
21+
22+
# define __must_hold(x)
23+
# define __acquires(x)
24+
# define __cond_acquires(x)
25+
# define __releases(x)
26+
# define __acquire(x) (void)0
27+
# define __release(x) (void)0
28+
# define __cond_lock(x, c) (c)
29+
30+
#endif /* __CHECKER__ */
31+
32+
#endif /* _LINUX_COMPILER_CAPABILITY_ANALYSIS_H */

include/linux/compiler_types.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
# define BTF_TYPE_TAG(value) /* nothing */
2525
#endif
2626

27+
#include <linux/compiler-capability-analysis.h>
28+
2729
/* sparse defines __CHECKER__; see Documentation/dev-tools/sparse.rst */
2830
#ifdef __CHECKER__
2931
/* address spaces */
@@ -34,14 +36,6 @@
3436
# define __rcu __attribute__((noderef, address_space(__rcu)))
3537
static inline void __chk_user_ptr(const volatile void __user *ptr) { }
3638
static inline void __chk_io_ptr(const volatile void __iomem *ptr) { }
37-
/* context/locking */
38-
# define __must_hold(x) __attribute__((context(x,1,1)))
39-
# define __acquires(x) __attribute__((context(x,0,1)))
40-
# define __cond_acquires(x) __attribute__((context(x,0,-1)))
41-
# define __releases(x) __attribute__((context(x,1,0)))
42-
# define __acquire(x) __context__(x,1)
43-
# define __release(x) __context__(x,-1)
44-
# define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
4539
/* other */
4640
# define __force __attribute__((force))
4741
# define __nocast __attribute__((nocast))
@@ -62,14 +56,6 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { }
6256

6357
# define __chk_user_ptr(x) (void)0
6458
# define __chk_io_ptr(x) (void)0
65-
/* context/locking */
66-
# define __must_hold(x)
67-
# define __acquires(x)
68-
# define __cond_acquires(x)
69-
# define __releases(x)
70-
# define __acquire(x) (void)0
71-
# define __release(x) (void)0
72-
# define __cond_lock(x,c) (c)
7359
/* other */
7460
# define __force
7561
# define __nocast

0 commit comments

Comments
 (0)