Skip to content

Commit d0380e6

Browse files
KAGA-KOKOtorvalds
authored andcommitted
early_printk: consolidate random copies of identical code
The early console implementations are the same all over the place. Move the print function to kernel/printk and get rid of the copies. [[email protected]: arch/mips/kernel/early_printk.c needs kernel.h for va_list] [[email protected]: sh4: make the bios early console support depend on EARLY_PRINTK] Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Paul Gortmaker <[email protected]> Cc: Russell King <[email protected]> Acked-by: Mike Frysinger <[email protected]> Cc: Michal Simek <[email protected]> Cc: Ralf Baechle <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Paul Mundt <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Chris Metcalf <[email protected]> Cc: Richard Weinberger <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Tested-by: Paul Gortmaker <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 07c65f4 commit d0380e6

File tree

13 files changed

+63
-109
lines changed

13 files changed

+63
-109
lines changed

arch/arm/kernel/early_printk.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,17 @@ static void early_console_write(struct console *con, const char *s, unsigned n)
2929
early_write(s, n);
3030
}
3131

32-
static struct console early_console = {
32+
static struct console early_console_dev = {
3333
.name = "earlycon",
3434
.write = early_console_write,
3535
.flags = CON_PRINTBUFFER | CON_BOOT,
3636
.index = -1,
3737
};
3838

39-
asmlinkage void early_printk(const char *fmt, ...)
40-
{
41-
char buf[512];
42-
int n;
43-
va_list ap;
44-
45-
va_start(ap, fmt);
46-
n = vscnprintf(buf, sizeof(buf), fmt, ap);
47-
early_write(buf, n);
48-
va_end(ap);
49-
}
50-
5139
static int __init setup_early_printk(char *buf)
5240
{
53-
register_console(&early_console);
41+
early_console = &early_console_dev;
42+
register_console(&early_console_dev);
5443
return 0;
5544
}
5645

arch/blackfin/kernel/early_printk.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ extern struct console *bfin_earlyserial_init(unsigned int port,
2525
extern struct console *bfin_jc_early_init(void);
2626
#endif
2727

28-
static struct console *early_console;
29-
3028
/* Default console */
3129
#define DEFAULT_PORT 0
3230
#define DEFAULT_CFLAG CS8|B57600

arch/microblaze/kernel/early_printk.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <asm/setup.h>
2222
#include <asm/prom.h>
2323

24-
static u32 early_console_initialized;
2524
static u32 base_addr;
2625

2726
#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
@@ -109,27 +108,11 @@ static struct console early_serial_uart16550_console = {
109108
};
110109
#endif /* CONFIG_SERIAL_8250_CONSOLE */
111110

112-
static struct console *early_console;
113-
114-
void early_printk(const char *fmt, ...)
115-
{
116-
char buf[512];
117-
int n;
118-
va_list ap;
119-
120-
if (early_console_initialized) {
121-
va_start(ap, fmt);
122-
n = vscnprintf(buf, 512, fmt, ap);
123-
early_console->write(early_console, buf, n);
124-
va_end(ap);
125-
}
126-
}
127-
128111
int __init setup_early_printk(char *opt)
129112
{
130113
int version = 0;
131114

132-
if (early_console_initialized)
115+
if (early_console)
133116
return 1;
134117

135118
base_addr = of_early_console(&version);
@@ -159,7 +142,6 @@ int __init setup_early_printk(char *opt)
159142
}
160143

161144
register_console(early_console);
162-
early_console_initialized = 1;
163145
return 0;
164146
}
165147
return 1;
@@ -169,7 +151,7 @@ int __init setup_early_printk(char *opt)
169151
* only for early console because of performance degression */
170152
void __init remap_early_printk(void)
171153
{
172-
if (!early_console_initialized || !early_console)
154+
if (!early_console)
173155
return;
174156
pr_info("early_printk_console remapping from 0x%x to ", base_addr);
175157
base_addr = (u32) ioremap(base_addr, PAGE_SIZE);
@@ -194,9 +176,9 @@ void __init remap_early_printk(void)
194176

195177
void __init disable_early_printk(void)
196178
{
197-
if (!early_console_initialized || !early_console)
179+
if (!early_console)
198180
return;
199181
pr_warn("disabling early console\n");
200182
unregister_console(early_console);
201-
early_console_initialized = 0;
183+
early_console = NULL;
202184
}

arch/mips/kernel/early_printk.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
* Copyright (C) 2007 MIPS Technologies, Inc.
88
* written by Ralf Baechle ([email protected])
99
*/
10+
#include <linux/kernel.h>
1011
#include <linux/console.h>
12+
#include <linux/printk.h>
1113
#include <linux/init.h>
1214

1315
#include <asm/setup.h>
@@ -24,20 +26,18 @@ static void early_console_write(struct console *con, const char *s, unsigned n)
2426
}
2527
}
2628

27-
static struct console early_console = {
29+
static struct console early_console_prom = {
2830
.name = "early",
2931
.write = early_console_write,
3032
.flags = CON_PRINTBUFFER | CON_BOOT,
3133
.index = -1
3234
};
3335

34-
static int early_console_initialized __initdata;
35-
3636
void __init setup_early_printk(void)
3737
{
38-
if (early_console_initialized)
38+
if (early_console)
3939
return;
40-
early_console_initialized = 1;
40+
early_console = &early_console_prom;
4141

42-
register_console(&early_console);
42+
register_console(&early_console_prom);
4343
}

arch/powerpc/kernel/udbg.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,13 @@ static struct console udbg_console = {
156156
.index = 0,
157157
};
158158

159-
static int early_console_initialized;
160-
161159
/*
162160
* Called by setup_system after ppc_md->probe and ppc_md->early_init.
163161
* Call it again after setting udbg_putc in ppc_md->setup_arch.
164162
*/
165163
void __init register_early_udbg_console(void)
166164
{
167-
if (early_console_initialized)
165+
if (early_console)
168166
return;
169167

170168
if (!udbg_putc)
@@ -174,7 +172,7 @@ void __init register_early_udbg_console(void)
174172
printk(KERN_INFO "early console immortal !\n");
175173
udbg_console.flags &= ~CON_BOOT;
176174
}
177-
early_console_initialized = 1;
175+
early_console = &udbg_console;
178176
register_console(&udbg_console);
179177
}
180178

arch/sh/kernel/sh_bios.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ void sh_bios_vbr_reload(void)
104104
);
105105
}
106106

107+
#ifdef CONFIG_EARLY_PRINTK
107108
/*
108109
* Print a string through the BIOS
109110
*/
@@ -144,8 +145,6 @@ static struct console bios_console = {
144145
.index = -1,
145146
};
146147

147-
static struct console *early_console;
148-
149148
static int __init setup_early_printk(char *buf)
150149
{
151150
int keep_early = 0;
@@ -170,3 +169,4 @@ static int __init setup_early_printk(char *buf)
170169
return 0;
171170
}
172171
early_param("earlyprintk", setup_early_printk);
172+
#endif

arch/tile/kernel/early_printk.c

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/init.h>
1818
#include <linux/string.h>
1919
#include <linux/irqflags.h>
20+
#include <linux/printk.h>
2021
#include <asm/setup.h>
2122
#include <hv/hypervisor.h>
2223

@@ -33,25 +34,8 @@ static struct console early_hv_console = {
3334
};
3435

3536
/* Direct interface for emergencies */
36-
static struct console *early_console = &early_hv_console;
37-
static int early_console_initialized;
3837
static int early_console_complete;
3938

40-
static void early_vprintk(const char *fmt, va_list ap)
41-
{
42-
char buf[512];
43-
int n = vscnprintf(buf, sizeof(buf), fmt, ap);
44-
early_console->write(early_console, buf, n);
45-
}
46-
47-
void early_printk(const char *fmt, ...)
48-
{
49-
va_list ap;
50-
va_start(ap, fmt);
51-
early_vprintk(fmt, ap);
52-
va_end(ap);
53-
}
54-
5539
void early_panic(const char *fmt, ...)
5640
{
5741
va_list ap;
@@ -69,14 +53,13 @@ static int __initdata keep_early;
6953

7054
static int __init setup_early_printk(char *str)
7155
{
72-
if (early_console_initialized)
56+
if (early_console)
7357
return 1;
7458

7559
if (str != NULL && strncmp(str, "keep", 4) == 0)
7660
keep_early = 1;
7761

7862
early_console = &early_hv_console;
79-
early_console_initialized = 1;
8063
register_console(early_console);
8164

8265
return 0;
@@ -85,20 +68,20 @@ static int __init setup_early_printk(char *str)
8568
void __init disable_early_printk(void)
8669
{
8770
early_console_complete = 1;
88-
if (!early_console_initialized || !early_console)
71+
if (!early_console)
8972
return;
9073
if (!keep_early) {
9174
early_printk("disabling early console\n");
9275
unregister_console(early_console);
93-
early_console_initialized = 0;
76+
early_console = NULL;
9477
} else {
9578
early_printk("keeping early console\n");
9679
}
9780
}
9881

9982
void warn_early_printk(void)
10083
{
101-
if (early_console_complete || early_console_initialized)
84+
if (early_console_complete || early_console)
10285
return;
10386
early_printk("\
10487
Machine shutting down before console output is fully initialized.\n\

arch/um/kernel/early_printk.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void early_console_write(struct console *con, const char *s, unsigned int
1616
um_early_printk(s, n);
1717
}
1818

19-
static struct console early_console = {
19+
static struct console early_console_dev = {
2020
.name = "earlycon",
2121
.write = early_console_write,
2222
.flags = CON_BOOT,
@@ -25,8 +25,10 @@ static struct console early_console = {
2525

2626
static int __init setup_early_printk(char *buf)
2727
{
28-
register_console(&early_console);
29-
28+
if (!early_console) {
29+
early_console = &early_console_dev;
30+
register_console(&early_console_dev);
31+
}
3032
return 0;
3133
}
3234

arch/unicore32/kernel/early_printk.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,17 @@ static struct console early_ocd_console = {
3333
.index = -1,
3434
};
3535

36-
/* Direct interface for emergencies */
37-
static struct console *early_console = &early_ocd_console;
38-
39-
static int __initdata keep_early;
40-
4136
static int __init setup_early_printk(char *buf)
4237
{
43-
if (!buf)
38+
int keep_early;
39+
40+
if (!buf || early_console)
4441
return 0;
4542

4643
if (strstr(buf, "keep"))
4744
keep_early = 1;
4845

49-
if (!strncmp(buf, "ocd", 3))
50-
early_console = &early_ocd_console;
46+
early_console = &early_ocd_console;
5147

5248
if (keep_early)
5349
early_console->flags &= ~CON_BOOT;

arch/x86/kernel/early_printk.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,25 +169,9 @@ static struct console early_serial_console = {
169169
.index = -1,
170170
};
171171

172-
/* Direct interface for emergencies */
173-
static struct console *early_console = &early_vga_console;
174-
static int __initdata early_console_initialized;
175-
176-
asmlinkage void early_printk(const char *fmt, ...)
177-
{
178-
char buf[512];
179-
int n;
180-
va_list ap;
181-
182-
va_start(ap, fmt);
183-
n = vscnprintf(buf, sizeof(buf), fmt, ap);
184-
early_console->write(early_console, buf, n);
185-
va_end(ap);
186-
}
187-
188172
static inline void early_console_register(struct console *con, int keep_early)
189173
{
190-
if (early_console->index != -1) {
174+
if (con->index != -1) {
191175
printk(KERN_CRIT "ERROR: earlyprintk= %s already used\n",
192176
con->name);
193177
return;
@@ -207,9 +191,8 @@ static int __init setup_early_printk(char *buf)
207191
if (!buf)
208192
return 0;
209193

210-
if (early_console_initialized)
194+
if (early_console)
211195
return 0;
212-
early_console_initialized = 1;
213196

214197
keep = (strstr(buf, "keep") != NULL);
215198

include/linux/console.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct console {
141141
for (con = console_drivers; con != NULL; con = con->next)
142142

143143
extern int console_set_on_cmdline;
144+
extern struct console *early_console;
144145

145146
extern int add_preferred_console(char *name, int idx, char *options);
146147
extern int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options);

include/linux/printk.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,14 @@ int no_printk(const char *fmt, ...)
9595
return 0;
9696
}
9797

98+
#ifdef CONFIG_EARLY_PRINTK
9899
extern asmlinkage __printf(1, 2)
99100
void early_printk(const char *fmt, ...);
101+
void early_vprintk(const char *fmt, va_list ap);
102+
#else
103+
static inline __printf(1, 2) __cold
104+
void early_printk(const char *s, ...) { }
105+
#endif
100106

101107
#ifdef CONFIG_PRINTK
102108
asmlinkage __printf(5, 0)

0 commit comments

Comments
 (0)