Skip to content

Commit b4a461e

Browse files
herbertxsergey-senozhatsky
authored andcommitted
printk: Make linux/printk.h self-contained
As it stands if you include printk.h by itself it will fail to compile because it requires definitions from ratelimit.h. However, simply including ratelimit.h from printk.h does not work due to inclusion loops involving sched.h and kernel.h. This patch solves this by moving bits from ratelimit.h into a new header file which can then be included by printk.h without any worries about header loops. The build bot then revealed some intriguing failures arising out of this patch. On s390 there is an inclusion loop with asm/bug.h and linux/kernel.h that triggers a compile failure, because kernel.h will cause asm-generic/bug.h to be included before s390's own asm/bug.h has finished processing. This has been fixed by not including kernel.h in arch/s390/include/asm/bug.h. Signed-off-by: Herbert Xu <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Acked-by: Petr Mladek <[email protected]> Acked-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Sergey Senozhatsky <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent bc885f1 commit b4a461e

File tree

4 files changed

+46
-36
lines changed

4 files changed

+46
-36
lines changed

arch/s390/include/asm/bug.h

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

5-
#include <linux/kernel.h>
5+
#include <linux/compiler.h>
66

77
#ifdef CONFIG_BUG
88

include/linux/printk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/kern_levels.h>
88
#include <linux/linkage.h>
99
#include <linux/cache.h>
10+
#include <linux/ratelimit_types.h>
1011

1112
extern const char linux_banner[];
1213
extern const char linux_proc_banner[];

include/linux/ratelimit.h

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,10 @@
22
#ifndef _LINUX_RATELIMIT_H
33
#define _LINUX_RATELIMIT_H
44

5-
#include <linux/param.h>
5+
#include <linux/ratelimit_types.h>
66
#include <linux/sched.h>
77
#include <linux/spinlock.h>
88

9-
#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)
10-
#define DEFAULT_RATELIMIT_BURST 10
11-
12-
/* issue num suppressed message on exit */
13-
#define RATELIMIT_MSG_ON_RELEASE BIT(0)
14-
15-
struct ratelimit_state {
16-
raw_spinlock_t lock; /* protect the state */
17-
18-
int interval;
19-
int burst;
20-
int printed;
21-
int missed;
22-
unsigned long begin;
23-
unsigned long flags;
24-
};
25-
26-
#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) { \
27-
.lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
28-
.interval = interval_init, \
29-
.burst = burst_init, \
30-
}
31-
32-
#define RATELIMIT_STATE_INIT_DISABLED \
33-
RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST)
34-
35-
#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \
36-
\
37-
struct ratelimit_state name = \
38-
RATELIMIT_STATE_INIT(name, interval_init, burst_init) \
39-
409
static inline void ratelimit_state_init(struct ratelimit_state *rs,
4110
int interval, int burst)
4211
{
@@ -73,9 +42,6 @@ ratelimit_set_flags(struct ratelimit_state *rs, unsigned long flags)
7342

7443
extern struct ratelimit_state printk_ratelimit_state;
7544

76-
extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
77-
#define __ratelimit(state) ___ratelimit(state, __func__)
78-
7945
#ifdef CONFIG_PRINTK
8046

8147
#define WARN_ON_RATELIMIT(condition, state) ({ \

include/linux/ratelimit_types.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_RATELIMIT_TYPES_H
3+
#define _LINUX_RATELIMIT_TYPES_H
4+
5+
#include <linux/bits.h>
6+
#include <linux/param.h>
7+
#include <linux/spinlock_types.h>
8+
9+
#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)
10+
#define DEFAULT_RATELIMIT_BURST 10
11+
12+
/* issue num suppressed message on exit */
13+
#define RATELIMIT_MSG_ON_RELEASE BIT(0)
14+
15+
struct ratelimit_state {
16+
raw_spinlock_t lock; /* protect the state */
17+
18+
int interval;
19+
int burst;
20+
int printed;
21+
int missed;
22+
unsigned long begin;
23+
unsigned long flags;
24+
};
25+
26+
#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) { \
27+
.lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
28+
.interval = interval_init, \
29+
.burst = burst_init, \
30+
}
31+
32+
#define RATELIMIT_STATE_INIT_DISABLED \
33+
RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST)
34+
35+
#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \
36+
\
37+
struct ratelimit_state name = \
38+
RATELIMIT_STATE_INIT(name, interval_init, burst_init) \
39+
40+
extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
41+
#define __ratelimit(state) ___ratelimit(state, __func__)
42+
43+
#endif /* _LINUX_RATELIMIT_TYPES_H */

0 commit comments

Comments
 (0)