[NET] netconsole: Simplify boot/module option setup logic
[deliverable/linux.git] / drivers / net / netconsole.c
index bf58db29e2ed6342bd707931ccd598a3c376b07c..e56aa6c9743f6934d8eb4408aa4ba3c65c97efef 100644 (file)
  ****************************************************************/
 
 #include <linux/mm.h>
-#include <linux/tty.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/console.h>
-#include <linux/tty_driver.h>
 #include <linux/moduleparam.h>
 #include <linux/string.h>
-#include <linux/sysrq.h>
-#include <linux/smp.h>
 #include <linux/netpoll.h>
 
 MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
 MODULE_DESCRIPTION("Console driver for network interfaces");
 MODULE_LICENSE("GPL");
 
-static char config[256];
-module_param_string(netconsole, config, 256, 0);
+#define MAX_PARAM_LENGTH       256
+#define MAX_PRINT_CHUNK                1000
+
+static char config[MAX_PARAM_LENGTH];
+module_param_string(netconsole, config, MAX_PARAM_LENGTH, 0);
 MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]\n");
 
+#ifndef        MODULE
+static int __init option_setup(char *opt)
+{
+       strlcpy(config, opt, MAX_PARAM_LENGTH);
+       return 1;
+}
+__setup("netconsole=", option_setup);
+#endif /* MODULE */
+
 static struct netpoll np = {
-       .name = "netconsole",
-       .dev_name = "eth0",
-       .local_port = 6665,
-       .remote_port = 6666,
-       .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
-       .drop = netpoll_queue,
+       .name           = "netconsole",
+       .dev_name       = "eth0",
+       .local_port     = 6665,
+       .remote_port    = 6666,
+       .remote_mac     = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
 };
-static int configured = 0;
-
-#define MAX_PRINT_CHUNK 1000
 
 static void write_msg(struct console *con, const char *msg, unsigned int len)
 {
        int frag, left;
        unsigned long flags;
 
-       if (!np.dev)
-               return;
-
        local_irq_save(flags);
 
-       for(left = len; left; ) {
+       for (left = len; left;) {
                frag = min(left, MAX_PRINT_CHUNK);
                netpoll_send_udp(&np, msg, frag);
                msg += frag;
@@ -87,38 +88,36 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
 }
 
 static struct console netconsole = {
-       .name = "netcon",
-       .flags = CON_ENABLED | CON_PRINTBUFFER,
-       .write = write_msg
+       .name   = "netcon",
+       .flags  = CON_ENABLED | CON_PRINTBUFFER,
+       .write  = write_msg,
 };
 
-static int option_setup(char *opt)
+static int __init init_netconsole(void)
 {
-       configured = !netpoll_parse_options(&np, opt);
-       return 1;
-}
-
-__setup("netconsole=", option_setup);
+       int err = 0;
 
-static int init_netconsole(void)
-{
-       if(strlen(config))
-               option_setup(config);
-
-       if(!configured) {
-               printk("netconsole: not configured, aborting\n");
-               return 0;
+       if (!strnlen(config, MAX_PARAM_LENGTH)) {
+               printk(KERN_INFO "netconsole: not configured, aborting\n");
+               goto out;
        }
 
-       if(netpoll_setup(&np))
-               return -EINVAL;
+       err = netpoll_parse_options(&np, config);
+       if (err)
+               goto out;
+
+       err = netpoll_setup(&np);
+       if (err)
+               goto out;
 
        register_console(&netconsole);
        printk(KERN_INFO "netconsole: network logging started\n");
-       return 0;
+
+out:
+       return err;
 }
 
-static void cleanup_netconsole(void)
+static void __exit cleanup_netconsole(void)
 {
        unregister_console(&netconsole);
        netpoll_cleanup(&np);
This page took 0.037319 seconds and 5 git commands to generate.