aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers/mconsole_kern.c
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2007-10-16 04:26:57 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:43:05 -0400
commitae2587e41254e48e670346aefa332d7469d86352 (patch)
treec5e8ba8f3bff3a269f8c88a2a9e4c657226e378e /arch/um/drivers/mconsole_kern.c
parent6aa802ce6acc9b1f0b34114b3f7c21c84872cc3a (diff)
uml: style fixes pass 2
Formatting changes in the files which have been changed in the course of removing CHOOSE_MODE. These include: copyright updates header file trimming style fixes adding severity to printks These changes should be entirely non-functional. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um/drivers/mconsole_kern.c')
-rw-r--r--arch/um/drivers/mconsole_kern.c250
1 files changed, 127 insertions, 123 deletions
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index 3591c3806670..5f6dbb148218 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -1,43 +1,35 @@
1/* 1/*
2 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) 2 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org)
3 * Copyright (C) 2001 - 2003 Jeff Dike (jdike@addtoit.com) 3 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 * Licensed under the GPL 4 * Licensed under the GPL
5 */ 5 */
6 6
7#include "linux/kernel.h" 7#include "linux/console.h"
8#include "linux/slab.h"
9#include "linux/init.h"
10#include "linux/notifier.h"
11#include "linux/reboot.h"
12#include "linux/utsname.h"
13#include "linux/ctype.h" 8#include "linux/ctype.h"
14#include "linux/interrupt.h" 9#include "linux/interrupt.h"
15#include "linux/sysrq.h" 10#include "linux/list.h"
16#include "linux/workqueue.h" 11#include "linux/mm.h"
17#include "linux/module.h" 12#include "linux/module.h"
18#include "linux/file.h" 13#include "linux/notifier.h"
19#include "linux/fs.h" 14#include "linux/reboot.h"
20#include "linux/namei.h"
21#include "linux/proc_fs.h" 15#include "linux/proc_fs.h"
16#include "linux/slab.h"
22#include "linux/syscalls.h" 17#include "linux/syscalls.h"
23#include "linux/list.h" 18#include "linux/utsname.h"
24#include "linux/mm.h" 19#include "linux/workqueue.h"
25#include "linux/console.h"
26#include "asm/irq.h"
27#include "asm/uaccess.h" 20#include "asm/uaccess.h"
21#include "init.h"
22#include "irq_kern.h"
23#include "irq_user.h"
28#include "kern_util.h" 24#include "kern_util.h"
29#include "kern.h"
30#include "mconsole.h" 25#include "mconsole.h"
31#include "mconsole_kern.h" 26#include "mconsole_kern.h"
32#include "irq_user.h"
33#include "init.h"
34#include "os.h" 27#include "os.h"
35#include "irq_kern.h"
36 28
37static int do_unlink_socket(struct notifier_block *notifier, 29static int do_unlink_socket(struct notifier_block *notifier,
38 unsigned long what, void *data) 30 unsigned long what, void *data)
39{ 31{
40 return(mconsole_unlink_socket()); 32 return mconsole_unlink_socket();
41} 33}
42 34
43 35
@@ -58,10 +50,9 @@ static void mc_work_proc(struct work_struct *unused)
58 struct mconsole_entry *req; 50 struct mconsole_entry *req;
59 unsigned long flags; 51 unsigned long flags;
60 52
61 while(!list_empty(&mc_requests)){ 53 while (!list_empty(&mc_requests)) {
62 local_irq_save(flags); 54 local_irq_save(flags);
63 req = list_entry(mc_requests.next, struct mconsole_entry, 55 req = list_entry(mc_requests.next, struct mconsole_entry, list);
64 list);
65 list_del(&req->list); 56 list_del(&req->list);
66 local_irq_restore(flags); 57 local_irq_restore(flags);
67 req->request.cmd->handler(&req->request); 58 req->request.cmd->handler(&req->request);
@@ -79,12 +70,12 @@ static irqreturn_t mconsole_interrupt(int irq, void *dev_id)
79 static struct mc_request req; /* that's OK */ 70 static struct mc_request req; /* that's OK */
80 71
81 fd = (long) dev_id; 72 fd = (long) dev_id;
82 while (mconsole_get_request(fd, &req)){ 73 while (mconsole_get_request(fd, &req)) {
83 if(req.cmd->context == MCONSOLE_INTR) 74 if (req.cmd->context == MCONSOLE_INTR)
84 (*req.cmd->handler)(&req); 75 (*req.cmd->handler)(&req);
85 else { 76 else {
86 new = kmalloc(sizeof(*new), GFP_NOWAIT); 77 new = kmalloc(sizeof(*new), GFP_NOWAIT);
87 if(new == NULL) 78 if (new == NULL)
88 mconsole_reply(&req, "Out of memory", 1, 0); 79 mconsole_reply(&req, "Out of memory", 1, 0);
89 else { 80 else {
90 new->request = req; 81 new->request = req;
@@ -93,10 +84,10 @@ static irqreturn_t mconsole_interrupt(int irq, void *dev_id)
93 } 84 }
94 } 85 }
95 } 86 }
96 if(!list_empty(&mc_requests)) 87 if (!list_empty(&mc_requests))
97 schedule_work(&mconsole_work); 88 schedule_work(&mconsole_work);
98 reactivate_fd(fd, MCONSOLE_IRQ); 89 reactivate_fd(fd, MCONSOLE_IRQ);
99 return(IRQ_HANDLED); 90 return IRQ_HANDLED;
100} 91}
101 92
102void mconsole_version(struct mc_request *req) 93void mconsole_version(struct mc_request *req)
@@ -104,8 +95,8 @@ void mconsole_version(struct mc_request *req)
104 char version[256]; 95 char version[256];
105 96
106 sprintf(version, "%s %s %s %s %s", utsname()->sysname, 97 sprintf(version, "%s %s %s %s %s", utsname()->sysname,
107 utsname()->nodename, utsname()->release, 98 utsname()->nodename, utsname()->release, utsname()->version,
108 utsname()->version, utsname()->machine); 99 utsname()->machine);
109 mconsole_reply(req, version, 0, 0); 100 mconsole_reply(req, version, 0, 0);
110} 101}
111 102
@@ -117,7 +108,7 @@ void mconsole_log(struct mc_request *req)
117 ptr += strlen("log "); 108 ptr += strlen("log ");
118 109
119 len = req->len - (ptr - req->request.data); 110 len = req->len - (ptr - req->request.data);
120 printk("%.*s", len, ptr); 111 printk(KERN_WARNING "%.*s", len, ptr);
121 mconsole_reply(req, "", 0, 0); 112 mconsole_reply(req, "", 0, 0);
122} 113}
123 114
@@ -136,17 +127,17 @@ void mconsole_proc(struct mc_request *req)
136 char *ptr = req->request.data, *buf; 127 char *ptr = req->request.data, *buf;
137 128
138 ptr += strlen("proc"); 129 ptr += strlen("proc");
139 while(isspace(*ptr)) ptr++; 130 while (isspace(*ptr)) ptr++;
140 131
141 proc = get_fs_type("proc"); 132 proc = get_fs_type("proc");
142 if(proc == NULL){ 133 if (proc == NULL) {
143 mconsole_reply(req, "procfs not registered", 1, 0); 134 mconsole_reply(req, "procfs not registered", 1, 0);
144 goto out; 135 goto out;
145 } 136 }
146 137
147 super = (*proc->get_sb)(proc, 0, NULL, NULL); 138 super = (*proc->get_sb)(proc, 0, NULL, NULL);
148 put_filesystem(proc); 139 put_filesystem(proc);
149 if(super == NULL){ 140 if (super == NULL) {
150 mconsole_reply(req, "Failed to get procfs superblock", 1, 0); 141 mconsole_reply(req, "Failed to get procfs superblock", 1, 0);
151 goto out; 142 goto out;
152 } 143 }
@@ -161,29 +152,29 @@ void mconsole_proc(struct mc_request *req)
161 * if commenting out these two calls + the below read cycle. To 152 * if commenting out these two calls + the below read cycle. To
162 * make UML crash again, it was enough to readd either one.*/ 153 * make UML crash again, it was enough to readd either one.*/
163 err = link_path_walk(ptr, &nd); 154 err = link_path_walk(ptr, &nd);
164 if(err){ 155 if (err) {
165 mconsole_reply(req, "Failed to look up file", 1, 0); 156 mconsole_reply(req, "Failed to look up file", 1, 0);
166 goto out_kill; 157 goto out_kill;
167 } 158 }
168 159
169 file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); 160 file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
170 if(IS_ERR(file)){ 161 if (IS_ERR(file)) {
171 mconsole_reply(req, "Failed to open file", 1, 0); 162 mconsole_reply(req, "Failed to open file", 1, 0);
172 goto out_kill; 163 goto out_kill;
173 } 164 }
174 /*END*/ 165 /*END*/
175 166
176 buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 167 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
177 if(buf == NULL){ 168 if (buf == NULL) {
178 mconsole_reply(req, "Failed to allocate buffer", 1, 0); 169 mconsole_reply(req, "Failed to allocate buffer", 1, 0);
179 goto out_fput; 170 goto out_fput;
180 } 171 }
181 172
182 if((file->f_op != NULL) && (file->f_op->read != NULL)){ 173 if ((file->f_op != NULL) && (file->f_op->read != NULL)) {
183 do { 174 do {
184 n = (*file->f_op->read)(file, buf, PAGE_SIZE - 1, 175 n = (*file->f_op->read)(file, buf, PAGE_SIZE - 1,
185 &file->f_pos); 176 &file->f_pos);
186 if(n >= 0){ 177 if (n >= 0) {
187 buf[n] = '\0'; 178 buf[n] = '\0';
188 mconsole_reply(req, buf, 0, (n > 0)); 179 mconsole_reply(req, buf, 0, (n > 0));
189 } 180 }
@@ -192,7 +183,7 @@ void mconsole_proc(struct mc_request *req)
192 1, 0); 183 1, 0);
193 goto out_free; 184 goto out_free;
194 } 185 }
195 } while(n > 0); 186 } while (n > 0);
196 } 187 }
197 else mconsole_reply(req, "", 0, 0); 188 else mconsole_reply(req, "", 0, 0);
198 189
@@ -216,18 +207,19 @@ void mconsole_proc(struct mc_request *req)
216 char *ptr = req->request.data; 207 char *ptr = req->request.data;
217 208
218 ptr += strlen("proc"); 209 ptr += strlen("proc");
219 while(isspace(*ptr)) ptr++; 210 while (isspace(*ptr))
211 ptr++;
220 snprintf(path, sizeof(path), "/proc/%s", ptr); 212 snprintf(path, sizeof(path), "/proc/%s", ptr);
221 213
222 fd = sys_open(path, 0, 0); 214 fd = sys_open(path, 0, 0);
223 if (fd < 0) { 215 if (fd < 0) {
224 mconsole_reply(req, "Failed to open file", 1, 0); 216 mconsole_reply(req, "Failed to open file", 1, 0);
225 printk("open %s: %d\n",path,fd); 217 printk(KERN_ERR "open %s: %d\n",path,fd);
226 goto out; 218 goto out;
227 } 219 }
228 220
229 buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 221 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
230 if(buf == NULL){ 222 if (buf == NULL) {
231 mconsole_reply(req, "Failed to allocate buffer", 1, 0); 223 mconsole_reply(req, "Failed to allocate buffer", 1, 0);
232 goto out_close; 224 goto out_close;
233 } 225 }
@@ -238,7 +230,7 @@ void mconsole_proc(struct mc_request *req)
238 mconsole_reply(req, "Read of file failed", 1, 0); 230 mconsole_reply(req, "Read of file failed", 1, 0);
239 goto out_free; 231 goto out_free;
240 } 232 }
241 /*Begin the file content on his own line.*/ 233 /* Begin the file content on his own line. */
242 if (first_chunk) { 234 if (first_chunk) {
243 mconsole_reply(req, "\n", 0, 1); 235 mconsole_reply(req, "\n", 0, 1);
244 first_chunk = 0; 236 first_chunk = 0;
@@ -350,12 +342,12 @@ static struct mc_device *mconsole_find_dev(char *name)
350 struct list_head *ele; 342 struct list_head *ele;
351 struct mc_device *dev; 343 struct mc_device *dev;
352 344
353 list_for_each(ele, &mconsole_devices){ 345 list_for_each(ele, &mconsole_devices) {
354 dev = list_entry(ele, struct mc_device, list); 346 dev = list_entry(ele, struct mc_device, list);
355 if(!strncmp(name, dev->name, strlen(dev->name))) 347 if (!strncmp(name, dev->name, strlen(dev->name)))
356 return(dev); 348 return dev;
357 } 349 }
358 return(NULL); 350 return NULL;
359} 351}
360 352
361#define UNPLUGGED_PER_PAGE \ 353#define UNPLUGGED_PER_PAGE \
@@ -377,15 +369,15 @@ static int mem_config(char *str, char **error_out)
377 int err = -EINVAL, i, add; 369 int err = -EINVAL, i, add;
378 char *ret; 370 char *ret;
379 371
380 if(str[0] != '='){ 372 if (str[0] != '=') {
381 *error_out = "Expected '=' after 'mem'"; 373 *error_out = "Expected '=' after 'mem'";
382 goto out; 374 goto out;
383 } 375 }
384 376
385 str++; 377 str++;
386 if(str[0] == '-') 378 if (str[0] == '-')
387 add = 0; 379 add = 0;
388 else if(str[0] == '+'){ 380 else if (str[0] == '+') {
389 add = 1; 381 add = 1;
390 } 382 }
391 else { 383 else {
@@ -395,7 +387,7 @@ static int mem_config(char *str, char **error_out)
395 387
396 str++; 388 str++;
397 diff = memparse(str, &ret); 389 diff = memparse(str, &ret);
398 if(*ret != '\0'){ 390 if (*ret != '\0') {
399 *error_out = "Failed to parse memory increment"; 391 *error_out = "Failed to parse memory increment";
400 goto out; 392 goto out;
401 } 393 }
@@ -403,17 +395,17 @@ static int mem_config(char *str, char **error_out)
403 diff /= PAGE_SIZE; 395 diff /= PAGE_SIZE;
404 396
405 down(&plug_mem_mutex); 397 down(&plug_mem_mutex);
406 for(i = 0; i < diff; i++){ 398 for (i = 0; i < diff; i++) {
407 struct unplugged_pages *unplugged; 399 struct unplugged_pages *unplugged;
408 void *addr; 400 void *addr;
409 401
410 if(add){ 402 if (add) {
411 if(list_empty(&unplugged_pages)) 403 if (list_empty(&unplugged_pages))
412 break; 404 break;
413 405
414 unplugged = list_entry(unplugged_pages.next, 406 unplugged = list_entry(unplugged_pages.next,
415 struct unplugged_pages, list); 407 struct unplugged_pages, list);
416 if(unplug_index > 0) 408 if (unplug_index > 0)
417 addr = unplugged->pages[--unplug_index]; 409 addr = unplugged->pages[--unplug_index];
418 else { 410 else {
419 list_del(&unplugged->list); 411 list_del(&unplugged->list);
@@ -428,11 +420,11 @@ static int mem_config(char *str, char **error_out)
428 struct page *page; 420 struct page *page;
429 421
430 page = alloc_page(GFP_ATOMIC); 422 page = alloc_page(GFP_ATOMIC);
431 if(page == NULL) 423 if (page == NULL)
432 break; 424 break;
433 425
434 unplugged = page_address(page); 426 unplugged = page_address(page);
435 if(unplug_index == UNPLUGGED_PER_PAGE){ 427 if (unplug_index == UNPLUGGED_PER_PAGE) {
436 list_add(&unplugged->list, &unplugged_pages); 428 list_add(&unplugged->list, &unplugged_pages);
437 unplug_index = 0; 429 unplug_index = 0;
438 } 430 }
@@ -444,9 +436,9 @@ static int mem_config(char *str, char **error_out)
444 struct unplugged_pages, 436 struct unplugged_pages,
445 list); 437 list);
446 err = os_drop_memory(addr, PAGE_SIZE); 438 err = os_drop_memory(addr, PAGE_SIZE);
447 if(err){ 439 if (err) {
448 printk("Failed to release memory - " 440 printk(KERN_ERR "Failed to release "
449 "errno = %d\n", err); 441 "memory - errno = %d\n", err);
450 *error_out = "Failed to release memory"; 442 *error_out = "Failed to release memory";
451 goto out_unlock; 443 goto out_unlock;
452 } 444 }
@@ -500,10 +492,10 @@ static struct mc_device mem_mc = {
500 492
501static int __init mem_mc_init(void) 493static int __init mem_mc_init(void)
502{ 494{
503 if(can_drop_memory()) 495 if (can_drop_memory())
504 mconsole_register_dev(&mem_mc); 496 mconsole_register_dev(&mem_mc);
505 else printk("Can't release memory to the host - memory hotplug won't " 497 else printk(KERN_ERR "Can't release memory to the host - memory "
506 "be supported\n"); 498 "hotplug won't be supported\n");
507 return 0; 499 return 0;
508} 500}
509 501
@@ -518,7 +510,7 @@ static void mconsole_get_config(int (*get_config)(char *, char *, int,
518 char default_buf[CONFIG_BUF_SIZE], *error, *buf; 510 char default_buf[CONFIG_BUF_SIZE], *error, *buf;
519 int n, size; 511 int n, size;
520 512
521 if(get_config == NULL){ 513 if (get_config == NULL) {
522 mconsole_reply(req, "No get_config routine defined", 1, 0); 514 mconsole_reply(req, "No get_config routine defined", 1, 0);
523 return; 515 return;
524 } 516 }
@@ -527,30 +519,30 @@ static void mconsole_get_config(int (*get_config)(char *, char *, int,
527 size = ARRAY_SIZE(default_buf); 519 size = ARRAY_SIZE(default_buf);
528 buf = default_buf; 520 buf = default_buf;
529 521
530 while(1){ 522 while (1) {
531 n = (*get_config)(name, buf, size, &error); 523 n = (*get_config)(name, buf, size, &error);
532 if(error != NULL){ 524 if (error != NULL) {
533 mconsole_reply(req, error, 1, 0); 525 mconsole_reply(req, error, 1, 0);
534 goto out; 526 goto out;
535 } 527 }
536 528
537 if(n <= size){ 529 if (n <= size) {
538 mconsole_reply(req, buf, 0, 0); 530 mconsole_reply(req, buf, 0, 0);
539 goto out; 531 goto out;
540 } 532 }
541 533
542 if(buf != default_buf) 534 if (buf != default_buf)
543 kfree(buf); 535 kfree(buf);
544 536
545 size = n; 537 size = n;
546 buf = kmalloc(size, GFP_KERNEL); 538 buf = kmalloc(size, GFP_KERNEL);
547 if(buf == NULL){ 539 if (buf == NULL) {
548 mconsole_reply(req, "Failed to allocate buffer", 1, 0); 540 mconsole_reply(req, "Failed to allocate buffer", 1, 0);
549 return; 541 return;
550 } 542 }
551 } 543 }
552 out: 544 out:
553 if(buf != default_buf) 545 if (buf != default_buf)
554 kfree(buf); 546 kfree(buf);
555} 547}
556 548
@@ -561,19 +553,20 @@ void mconsole_config(struct mc_request *req)
561 int err; 553 int err;
562 554
563 ptr += strlen("config"); 555 ptr += strlen("config");
564 while(isspace(*ptr)) ptr++; 556 while (isspace(*ptr))
557 ptr++;
565 dev = mconsole_find_dev(ptr); 558 dev = mconsole_find_dev(ptr);
566 if(dev == NULL){ 559 if (dev == NULL) {
567 mconsole_reply(req, "Bad configuration option", 1, 0); 560 mconsole_reply(req, "Bad configuration option", 1, 0);
568 return; 561 return;
569 } 562 }
570 563
571 name = &ptr[strlen(dev->name)]; 564 name = &ptr[strlen(dev->name)];
572 ptr = name; 565 ptr = name;
573 while((*ptr != '=') && (*ptr != '\0')) 566 while ((*ptr != '=') && (*ptr != '\0'))
574 ptr++; 567 ptr++;
575 568
576 if(*ptr == '='){ 569 if (*ptr == '=') {
577 err = (*dev->config)(name, &error_string); 570 err = (*dev->config)(name, &error_string);
578 mconsole_reply(req, error_string, err, 0); 571 mconsole_reply(req, error_string, err, 0);
579 } 572 }
@@ -588,9 +581,9 @@ void mconsole_remove(struct mc_request *req)
588 int err, start, end, n; 581 int err, start, end, n;
589 582
590 ptr += strlen("remove"); 583 ptr += strlen("remove");
591 while(isspace(*ptr)) ptr++; 584 while (isspace(*ptr)) ptr++;
592 dev = mconsole_find_dev(ptr); 585 dev = mconsole_find_dev(ptr);
593 if(dev == NULL){ 586 if (dev == NULL) {
594 mconsole_reply(req, "Bad remove option", 1, 0); 587 mconsole_reply(req, "Bad remove option", 1, 0);
595 return; 588 return;
596 } 589 }
@@ -599,11 +592,11 @@ void mconsole_remove(struct mc_request *req)
599 592
600 err = 1; 593 err = 1;
601 n = (*dev->id)(&ptr, &start, &end); 594 n = (*dev->id)(&ptr, &start, &end);
602 if(n < 0){ 595 if (n < 0) {
603 err_msg = "Couldn't parse device number"; 596 err_msg = "Couldn't parse device number";
604 goto out; 597 goto out;
605 } 598 }
606 else if((n < start) || (n > end)){ 599 else if ((n < start) || (n > end)) {
607 sprintf(error, "Invalid device number - must be between " 600 sprintf(error, "Invalid device number - must be between "
608 "%d and %d", start, end); 601 "%d and %d", start, end);
609 err_msg = error; 602 err_msg = error;
@@ -612,16 +605,16 @@ void mconsole_remove(struct mc_request *req)
612 605
613 err_msg = NULL; 606 err_msg = NULL;
614 err = (*dev->remove)(n, &err_msg); 607 err = (*dev->remove)(n, &err_msg);
615 switch(err){ 608 switch(err) {
616 case 0: 609 case 0:
617 err_msg = ""; 610 err_msg = "";
618 break; 611 break;
619 case -ENODEV: 612 case -ENODEV:
620 if(err_msg == NULL) 613 if (err_msg == NULL)
621 err_msg = "Device doesn't exist"; 614 err_msg = "Device doesn't exist";
622 break; 615 break;
623 case -EBUSY: 616 case -EBUSY:
624 if(err_msg == NULL) 617 if (err_msg == NULL)
625 err_msg = "Device is currently open"; 618 err_msg = "Device is currently open";
626 break; 619 break;
627 default: 620 default:
@@ -647,19 +640,19 @@ static void console_write(struct console *console, const char *string,
647 struct list_head *ele; 640 struct list_head *ele;
648 int n; 641 int n;
649 642
650 if(list_empty(&clients)) 643 if (list_empty(&clients))
651 return; 644 return;
652 645
653 while(1){ 646 while (1) {
654 n = min((size_t) len, ARRAY_SIZE(console_buf) - console_index); 647 n = min((size_t) len, ARRAY_SIZE(console_buf) - console_index);
655 strncpy(&console_buf[console_index], string, n); 648 strncpy(&console_buf[console_index], string, n);
656 console_index += n; 649 console_index += n;
657 string += n; 650 string += n;
658 len -= n; 651 len -= n;
659 if(len == 0) 652 if (len == 0)
660 return; 653 return;
661 654
662 list_for_each(ele, &clients){ 655 list_for_each(ele, &clients) {
663 struct mconsole_output *entry; 656 struct mconsole_output *entry;
664 657
665 entry = list_entry(ele, struct mconsole_output, list); 658 entry = list_entry(ele, struct mconsole_output, list);
@@ -717,12 +710,13 @@ void mconsole_sysrq(struct mc_request *req)
717 char *ptr = req->request.data; 710 char *ptr = req->request.data;
718 711
719 ptr += strlen("sysrq"); 712 ptr += strlen("sysrq");
720 while(isspace(*ptr)) ptr++; 713 while (isspace(*ptr)) ptr++;
721 714
722 /* With 'b', the system will shut down without a chance to reply, 715 /*
716 * With 'b', the system will shut down without a chance to reply,
723 * so in this case, we reply first. 717 * so in this case, we reply first.
724 */ 718 */
725 if(*ptr == 'b') 719 if (*ptr == 'b')
726 mconsole_reply(req, "", 0, 0); 720 mconsole_reply(req, "", 0, 0);
727 721
728 with_console(req, sysrq_proc, ptr); 722 with_console(req, sysrq_proc, ptr);
@@ -742,7 +736,8 @@ static void stack_proc(void *arg)
742 switch_to(from, to, from); 736 switch_to(from, to, from);
743} 737}
744 738
745/* Mconsole stack trace 739/*
740 * Mconsole stack trace
746 * Added by Allan Graves, Jeff Dike 741 * Added by Allan Graves, Jeff Dike
747 * Dumps a stacks registers to the linux console. 742 * Dumps a stacks registers to the linux console.
748 * Usage stack <pid>. 743 * Usage stack <pid>.
@@ -754,17 +749,21 @@ void mconsole_stack(struct mc_request *req)
754 struct task_struct *from = NULL; 749 struct task_struct *from = NULL;
755 struct task_struct *to = NULL; 750 struct task_struct *to = NULL;
756 751
757 /* Would be nice: 752 /*
753 * Would be nice:
758 * 1) Send showregs output to mconsole. 754 * 1) Send showregs output to mconsole.
759 * 2) Add a way to stack dump all pids. 755 * 2) Add a way to stack dump all pids.
760 */ 756 */
761 757
762 ptr += strlen("stack"); 758 ptr += strlen("stack");
763 while(isspace(*ptr)) ptr++; 759 while (isspace(*ptr))
760 ptr++;
764 761
765 /* Should really check for multiple pids or reject bad args here */ 762 /*
763 * Should really check for multiple pids or reject bad args here
764 */
766 /* What do the arguments in mconsole_reply mean? */ 765 /* What do the arguments in mconsole_reply mean? */
767 if(sscanf(ptr, "%d", &pid_requested) == 0){ 766 if (sscanf(ptr, "%d", &pid_requested) == 0) {
768 mconsole_reply(req, "Please specify a pid", 1, 0); 767 mconsole_reply(req, "Please specify a pid", 1, 0);
769 return; 768 return;
770 } 769 }
@@ -772,14 +771,15 @@ void mconsole_stack(struct mc_request *req)
772 from = current; 771 from = current;
773 772
774 to = find_task_by_pid(pid_requested); 773 to = find_task_by_pid(pid_requested);
775 if((to == NULL) || (pid_requested == 0)) { 774 if ((to == NULL) || (pid_requested == 0)) {
776 mconsole_reply(req, "Couldn't find that pid", 1, 0); 775 mconsole_reply(req, "Couldn't find that pid", 1, 0);
777 return; 776 return;
778 } 777 }
779 with_console(req, stack_proc, to); 778 with_console(req, stack_proc, to);
780} 779}
781 780
782/* Changed by mconsole_setup, which is __setup, and called before SMP is 781/*
782 * Changed by mconsole_setup, which is __setup, and called before SMP is
783 * active. 783 * active.
784 */ 784 */
785static char *notify_socket = NULL; 785static char *notify_socket = NULL;
@@ -791,13 +791,14 @@ static int __init mconsole_init(void)
791 int err; 791 int err;
792 char file[256]; 792 char file[256];
793 793
794 if(umid_file_name("mconsole", file, sizeof(file))) return(-1); 794 if (umid_file_name("mconsole", file, sizeof(file)))
795 return -1;
795 snprintf(mconsole_socket_name, sizeof(file), "%s", file); 796 snprintf(mconsole_socket_name, sizeof(file), "%s", file);
796 797
797 sock = os_create_unix_socket(file, sizeof(file), 1); 798 sock = os_create_unix_socket(file, sizeof(file), 1);
798 if (sock < 0){ 799 if (sock < 0) {
799 printk("Failed to initialize management console\n"); 800 printk(KERN_ERR "Failed to initialize management console\n");
800 return(1); 801 return 1;
801 } 802 }
802 803
803 register_reboot_notifier(&reboot_notifier); 804 register_reboot_notifier(&reboot_notifier);
@@ -805,14 +806,14 @@ static int __init mconsole_init(void)
805 err = um_request_irq(MCONSOLE_IRQ, sock, IRQ_READ, mconsole_interrupt, 806 err = um_request_irq(MCONSOLE_IRQ, sock, IRQ_READ, mconsole_interrupt,
806 IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM, 807 IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
807 "mconsole", (void *)sock); 808 "mconsole", (void *)sock);
808 if (err){ 809 if (err) {
809 printk("Failed to get IRQ for management console\n"); 810 printk(KERN_ERR "Failed to get IRQ for management console\n");
810 return(1); 811 return 1;
811 } 812 }
812 813
813 if(notify_socket != NULL){ 814 if (notify_socket != NULL) {
814 notify_socket = kstrdup(notify_socket, GFP_KERNEL); 815 notify_socket = kstrdup(notify_socket, GFP_KERNEL);
815 if(notify_socket != NULL) 816 if (notify_socket != NULL)
816 mconsole_notify(notify_socket, MCONSOLE_SOCKET, 817 mconsole_notify(notify_socket, MCONSOLE_SOCKET,
817 mconsole_socket_name, 818 mconsole_socket_name,
818 strlen(mconsole_socket_name) + 1); 819 strlen(mconsole_socket_name) + 1);
@@ -820,9 +821,9 @@ static int __init mconsole_init(void)
820 "string\n"); 821 "string\n");
821 } 822 }
822 823
823 printk("mconsole (version %d) initialized on %s\n", 824 printk(KERN_INFO "mconsole (version %d) initialized on %s\n",
824 MCONSOLE_VERSION, mconsole_socket_name); 825 MCONSOLE_VERSION, mconsole_socket_name);
825 return(0); 826 return 0;
826} 827}
827 828
828__initcall(mconsole_init); 829__initcall(mconsole_init);
@@ -833,10 +834,10 @@ static int write_proc_mconsole(struct file *file, const char __user *buffer,
833 char *buf; 834 char *buf;
834 835
835 buf = kmalloc(count + 1, GFP_KERNEL); 836 buf = kmalloc(count + 1, GFP_KERNEL);
836 if(buf == NULL) 837 if (buf == NULL)
837 return(-ENOMEM); 838 return -ENOMEM;
838 839
839 if(copy_from_user(buf, buffer, count)){ 840 if (copy_from_user(buf, buffer, count)) {
840 count = -EFAULT; 841 count = -EFAULT;
841 goto out; 842 goto out;
842 } 843 }
@@ -846,24 +847,26 @@ static int write_proc_mconsole(struct file *file, const char __user *buffer,
846 mconsole_notify(notify_socket, MCONSOLE_USER_NOTIFY, buf, count); 847 mconsole_notify(notify_socket, MCONSOLE_USER_NOTIFY, buf, count);
847 out: 848 out:
848 kfree(buf); 849 kfree(buf);
849 return(count); 850 return count;
850} 851}
851 852
852static int create_proc_mconsole(void) 853static int create_proc_mconsole(void)
853{ 854{
854 struct proc_dir_entry *ent; 855 struct proc_dir_entry *ent;
855 856
856 if(notify_socket == NULL) return(0); 857 if (notify_socket == NULL)
858 return 0;
857 859
858 ent = create_proc_entry("mconsole", S_IFREG | 0200, NULL); 860 ent = create_proc_entry("mconsole", S_IFREG | 0200, NULL);
859 if(ent == NULL){ 861 if (ent == NULL) {
860 printk(KERN_INFO "create_proc_mconsole : create_proc_entry failed\n"); 862 printk(KERN_INFO "create_proc_mconsole : create_proc_entry "
861 return(0); 863 "failed\n");
864 return 0;
862 } 865 }
863 866
864 ent->read_proc = NULL; 867 ent->read_proc = NULL;
865 ent->write_proc = write_proc_mconsole; 868 ent->write_proc = write_proc_mconsole;
866 return(0); 869 return 0;
867} 870}
868 871
869static DEFINE_SPINLOCK(notify_spinlock); 872static DEFINE_SPINLOCK(notify_spinlock);
@@ -884,12 +887,12 @@ __initcall(create_proc_mconsole);
884 887
885static int mconsole_setup(char *str) 888static int mconsole_setup(char *str)
886{ 889{
887 if(!strncmp(str, NOTIFY, strlen(NOTIFY))){ 890 if (!strncmp(str, NOTIFY, strlen(NOTIFY))) {
888 str += strlen(NOTIFY); 891 str += strlen(NOTIFY);
889 notify_socket = str; 892 notify_socket = str;
890 } 893 }
891 else printk(KERN_ERR "mconsole_setup : Unknown option - '%s'\n", str); 894 else printk(KERN_ERR "mconsole_setup : Unknown option - '%s'\n", str);
892 return(1); 895 return 1;
893} 896}
894 897
895__setup("mconsole", mconsole_setup); 898__setup("mconsole", mconsole_setup);
@@ -907,11 +910,12 @@ static int notify_panic(struct notifier_block *self, unsigned long unused1,
907{ 910{
908 char *message = ptr; 911 char *message = ptr;
909 912
910 if(notify_socket == NULL) return(0); 913 if (notify_socket == NULL)
914 return 0;
911 915
912 mconsole_notify(notify_socket, MCONSOLE_PANIC, message, 916 mconsole_notify(notify_socket, MCONSOLE_PANIC, message,
913 strlen(message) + 1); 917 strlen(message) + 1);
914 return(0); 918 return 0;
915} 919}
916 920
917static struct notifier_block panic_exit_notifier = { 921static struct notifier_block panic_exit_notifier = {
@@ -924,14 +928,14 @@ static int add_notifier(void)
924{ 928{
925 atomic_notifier_chain_register(&panic_notifier_list, 929 atomic_notifier_chain_register(&panic_notifier_list,
926 &panic_exit_notifier); 930 &panic_exit_notifier);
927 return(0); 931 return 0;
928} 932}
929 933
930__initcall(add_notifier); 934__initcall(add_notifier);
931 935
932char *mconsole_notify_socket(void) 936char *mconsole_notify_socket(void)
933{ 937{
934 return(notify_socket); 938 return notify_socket;
935} 939}
936 940
937EXPORT_SYMBOL(mconsole_notify_socket); 941EXPORT_SYMBOL(mconsole_notify_socket);