diff options
author | Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> | 2005-09-23 00:44:22 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-09-23 01:17:37 -0400 |
commit | fac97ae0b1a206e2952baf1f9eb46305d673adc6 (patch) | |
tree | d44e4d9d414c4fbef057e4991dbb60a4c31baa5d | |
parent | 79ae2cb856ed6a8c48f455d52d5ed5960c671e67 (diff) |
[PATCH] uml: replace printk with "stack-friendly" printf - to report console failure
User get *a lot* confused when consoles don't work but we don't report
anything. And, as reported in the comment, using printk to report "your
console doesn't work" isn't likely to go that far.
Fix the problem on the base of this: stack consumption by host printf(). Use
kernel sprintf() and os_write_file, using a wild guess that one page will be
enough for the message, to preallocate the buffer with kmalloc().
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Cc: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | arch/um/drivers/chan_kern.c | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c index 244e54a2153b..16e7dc89f61d 100644 --- a/arch/um/drivers/chan_kern.c +++ b/arch/um/drivers/chan_kern.c | |||
@@ -19,18 +19,44 @@ | |||
19 | #include "line.h" | 19 | #include "line.h" |
20 | #include "os.h" | 20 | #include "os.h" |
21 | 21 | ||
22 | #ifdef CONFIG_NOCONFIG_CHAN | 22 | /* XXX: could well be moved to somewhere else, if needed. */ |
23 | static int my_printf(const char * fmt, ...) | ||
24 | __attribute__ ((format (printf, 1, 2))); | ||
25 | |||
26 | static int my_printf(const char * fmt, ...) | ||
27 | { | ||
28 | /* Yes, can be called on atomic context.*/ | ||
29 | char *buf = kmalloc(4096, GFP_ATOMIC); | ||
30 | va_list args; | ||
31 | int r; | ||
32 | |||
33 | if (!buf) { | ||
34 | /* We print directly fmt. | ||
35 | * Yes, yes, yes, feel free to complain. */ | ||
36 | r = strlen(fmt); | ||
37 | } else { | ||
38 | va_start(args, fmt); | ||
39 | r = vsprintf(buf, fmt, args); | ||
40 | va_end(args); | ||
41 | fmt = buf; | ||
42 | } | ||
23 | 43 | ||
24 | /* The printk's here are wrong because we are complaining that there is no | 44 | if (r) |
25 | * output device, but printk is printing to that output device. The user will | 45 | r = os_write_file(1, fmt, r); |
26 | * never see the error. printf would be better, except it can't run on a | 46 | return r; |
27 | * kernel stack because it will overflow it. | 47 | |
28 | * Use printk for now since that will avoid crashing. | 48 | } |
29 | */ | 49 | |
50 | #ifdef CONFIG_NOCONFIG_CHAN | ||
51 | /* Despite its name, there's no added trailing newline. */ | ||
52 | static int my_puts(const char * buf) | ||
53 | { | ||
54 | return os_write_file(1, buf, strlen(buf)); | ||
55 | } | ||
30 | 56 | ||
31 | static void *not_configged_init(char *str, int device, struct chan_opts *opts) | 57 | static void *not_configged_init(char *str, int device, struct chan_opts *opts) |
32 | { | 58 | { |
33 | printk(KERN_ERR "Using a channel type which is configured out of " | 59 | my_puts("Using a channel type which is configured out of " |
34 | "UML\n"); | 60 | "UML\n"); |
35 | return(NULL); | 61 | return(NULL); |
36 | } | 62 | } |
@@ -38,27 +64,27 @@ static void *not_configged_init(char *str, int device, struct chan_opts *opts) | |||
38 | static int not_configged_open(int input, int output, int primary, void *data, | 64 | static int not_configged_open(int input, int output, int primary, void *data, |
39 | char **dev_out) | 65 | char **dev_out) |
40 | { | 66 | { |
41 | printk(KERN_ERR "Using a channel type which is configured out of " | 67 | my_puts("Using a channel type which is configured out of " |
42 | "UML\n"); | 68 | "UML\n"); |
43 | return(-ENODEV); | 69 | return(-ENODEV); |
44 | } | 70 | } |
45 | 71 | ||
46 | static void not_configged_close(int fd, void *data) | 72 | static void not_configged_close(int fd, void *data) |
47 | { | 73 | { |
48 | printk(KERN_ERR "Using a channel type which is configured out of " | 74 | my_puts("Using a channel type which is configured out of " |
49 | "UML\n"); | 75 | "UML\n"); |
50 | } | 76 | } |
51 | 77 | ||
52 | static int not_configged_read(int fd, char *c_out, void *data) | 78 | static int not_configged_read(int fd, char *c_out, void *data) |
53 | { | 79 | { |
54 | printk(KERN_ERR "Using a channel type which is configured out of " | 80 | my_puts("Using a channel type which is configured out of " |
55 | "UML\n"); | 81 | "UML\n"); |
56 | return(-EIO); | 82 | return(-EIO); |
57 | } | 83 | } |
58 | 84 | ||
59 | static int not_configged_write(int fd, const char *buf, int len, void *data) | 85 | static int not_configged_write(int fd, const char *buf, int len, void *data) |
60 | { | 86 | { |
61 | printk(KERN_ERR "Using a channel type which is configured out of " | 87 | my_puts("Using a channel type which is configured out of " |
62 | "UML\n"); | 88 | "UML\n"); |
63 | return(-EIO); | 89 | return(-EIO); |
64 | } | 90 | } |
@@ -66,7 +92,7 @@ static int not_configged_write(int fd, const char *buf, int len, void *data) | |||
66 | static int not_configged_console_write(int fd, const char *buf, int len, | 92 | static int not_configged_console_write(int fd, const char *buf, int len, |
67 | void *data) | 93 | void *data) |
68 | { | 94 | { |
69 | printk(KERN_ERR "Using a channel type which is configured out of " | 95 | my_puts("Using a channel type which is configured out of " |
70 | "UML\n"); | 96 | "UML\n"); |
71 | return(-EIO); | 97 | return(-EIO); |
72 | } | 98 | } |
@@ -74,14 +100,14 @@ static int not_configged_console_write(int fd, const char *buf, int len, | |||
74 | static int not_configged_window_size(int fd, void *data, unsigned short *rows, | 100 | static int not_configged_window_size(int fd, void *data, unsigned short *rows, |
75 | unsigned short *cols) | 101 | unsigned short *cols) |
76 | { | 102 | { |
77 | printk(KERN_ERR "Using a channel type which is configured out of " | 103 | my_puts("Using a channel type which is configured out of " |
78 | "UML\n"); | 104 | "UML\n"); |
79 | return(-ENODEV); | 105 | return(-ENODEV); |
80 | } | 106 | } |
81 | 107 | ||
82 | static void not_configged_free(void *data) | 108 | static void not_configged_free(void *data) |
83 | { | 109 | { |
84 | printf(KERN_ERR "Using a channel type which is configured out of " | 110 | my_puts("Using a channel type which is configured out of " |
85 | "UML\n"); | 111 | "UML\n"); |
86 | } | 112 | } |
87 | 113 | ||
@@ -457,7 +483,7 @@ static struct chan *parse_chan(char *str, int pri, int device, | |||
457 | } | 483 | } |
458 | } | 484 | } |
459 | if(ops == NULL){ | 485 | if(ops == NULL){ |
460 | printk(KERN_ERR "parse_chan couldn't parse \"%s\"\n", | 486 | my_printf("parse_chan couldn't parse \"%s\"\n", |
461 | str); | 487 | str); |
462 | return(NULL); | 488 | return(NULL); |
463 | } | 489 | } |