omap: i2c: add a timeout to the busy waiting
[safe/jmp/linux-2.6] / drivers / net / netconsole.c
index 69ef1eb..a361dea 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/console.h>
 #include <linux/moduleparam.h>
 #include <linux/string.h>
@@ -53,7 +54,7 @@ MODULE_LICENSE("GPL");
 
 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");
+MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]");
 
 #ifndef        MODULE
 static int __init option_setup(char *opt)
@@ -294,30 +295,25 @@ static ssize_t show_remote_port(struct netconsole_target *nt, char *buf)
 
 static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
-                       HIPQUAD(nt->np.local_ip));
+       return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip);
 }
 
 static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
-                       HIPQUAD(nt->np.remote_ip));
+       return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip);
 }
 
 static ssize_t show_local_mac(struct netconsole_target *nt, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
-                       nt->np.local_mac[0], nt->np.local_mac[1],
-                       nt->np.local_mac[2], nt->np.local_mac[3],
-                       nt->np.local_mac[4], nt->np.local_mac[5]);
+       struct net_device *dev = nt->np.dev;
+       static const u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+       return snprintf(buf, PAGE_SIZE, "%pM\n", dev ? dev->dev_addr : bcast);
 }
 
 static ssize_t show_remote_mac(struct netconsole_target *nt, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
-                       nt->np.remote_mac[0], nt->np.remote_mac[1],
-                       nt->np.remote_mac[2], nt->np.remote_mac[3],
-                       nt->np.remote_mac[4], nt->np.remote_mac[5]);
+       return snprintf(buf, PAGE_SIZE, "%pM\n", nt->np.remote_mac);
 }
 
 /*
@@ -441,7 +437,7 @@ static ssize_t store_local_ip(struct netconsole_target *nt,
                return -EINVAL;
        }
 
-       nt->np.local_ip = ntohl(in_aton(buf));
+       nt->np.local_ip = in_aton(buf);
 
        return strnlen(buf, count);
 }
@@ -457,7 +453,7 @@ static ssize_t store_remote_ip(struct netconsole_target *nt,
                return -EINVAL;
        }
 
-       nt->np.remote_ip = ntohl(in_aton(buf));
+       nt->np.remote_ip = in_aton(buf);
 
        return strnlen(buf, count);
 }
@@ -598,7 +594,7 @@ static struct config_item *make_netconsole_target(struct config_group *group,
        nt = kzalloc(sizeof(*nt), GFP_KERNEL);
        if (!nt) {
                printk(KERN_ERR "netconsole: failed to allocate memory\n");
-               return NULL;
+               return ERR_PTR(-ENOMEM);
        }
 
        nt->np.name = "netconsole";
@@ -669,7 +665,7 @@ static int netconsole_netdev_event(struct notifier_block *this,
        struct netconsole_target *nt;
        struct net_device *dev = ptr;
 
-       if (!(event == NETDEV_CHANGEADDR || event == NETDEV_CHANGENAME))
+       if (!(event == NETDEV_CHANGENAME || event == NETDEV_UNREGISTER))
                goto done;
 
        spin_lock_irqsave(&target_list_lock, flags);
@@ -677,13 +673,18 @@ static int netconsole_netdev_event(struct notifier_block *this,
                netconsole_target_get(nt);
                if (nt->np.dev == dev) {
                        switch (event) {
-                       case NETDEV_CHANGEADDR:
-                               memcpy(nt->np.local_mac, dev->dev_addr, ETH_ALEN);
-                               break;
-
                        case NETDEV_CHANGENAME:
                                strlcpy(nt->np.dev_name, dev->name, IFNAMSIZ);
                                break;
+                       case NETDEV_UNREGISTER:
+                               if (!nt->enabled)
+                                       break;
+                               netpoll_cleanup(&nt->np);
+                               nt->enabled = 0;
+                               printk(KERN_INFO "netconsole: network logging stopped"
+                                       ", interface %s unregistered\n",
+                                       dev->name);
+                               break;
                        }
                }
                netconsole_target_put(nt);
@@ -734,7 +735,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
 
 static struct console netconsole = {
        .name   = "netcon",
-       .flags  = CON_ENABLED | CON_PRINTBUFFER,
+       .flags  = CON_ENABLED,
        .write  = write_msg,
 };
 
@@ -753,6 +754,9 @@ static int __init init_netconsole(void)
                                err = PTR_ERR(nt);
                                goto fail;
                        }
+                       /* Dump existing printks when we register */
+                       netconsole.flags |= CON_PRINTBUFFER;
+
                        spin_lock_irqsave(&target_list_lock, flags);
                        list_add(&nt->list, &target_list);
                        spin_unlock_irqrestore(&target_list_lock, flags);