tracing: consolidate documents
[safe/jmp/linux-2.6] / net / netrom / nr_route.c
index b3b9097..e943c16 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/socket.h>
 #include <linux/in.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/timer.h>
 #include <linux/string.h>
 #include <linux/sockios.h>
@@ -87,8 +86,9 @@ static void nr_remove_neigh(struct nr_neigh *);
  *     Add a new route to a node, and in the process add the node and the
  *     neighbour if it is new.
  */
-static int nr_add_node(ax25_address *nr, const char *mnemonic, ax25_address *ax25,
-       ax25_digi *ax25_digi, struct net_device *dev, int quality, int obs_count)
+static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
+       ax25_address *ax25, ax25_digi *ax25_digi, struct net_device *dev,
+       int quality, int obs_count)
 {
        struct nr_node  *nr_node;
        struct nr_neigh *nr_neigh;
@@ -155,14 +155,15 @@ static int nr_add_node(ax25_address *nr, const char *mnemonic, ax25_address *ax2
                atomic_set(&nr_neigh->refcount, 1);
 
                if (ax25_digi != NULL && ax25_digi->ndigi > 0) {
-                       if ((nr_neigh->digipeat = kmalloc(sizeof(*ax25_digi), GFP_KERNEL)) == NULL) {
+                       nr_neigh->digipeat = kmemdup(ax25_digi,
+                                                    sizeof(*ax25_digi),
+                                                    GFP_KERNEL);
+                       if (nr_neigh->digipeat == NULL) {
                                kfree(nr_neigh);
                                if (nr_node)
                                        nr_node_put(nr_node);
                                return -ENOMEM;
                        }
-                       memcpy(nr_neigh->digipeat, ax25_digi,
-                                       sizeof(*ax25_digi));
                }
 
                spin_lock_bh(&nr_neigh_list_lock);
@@ -405,7 +406,8 @@ static int nr_del_node(ax25_address *callsign, ax25_address *neighbour, struct n
 /*
  *     Lock a neighbour with a quality.
  */
-static int nr_add_neigh(ax25_address *callsign, ax25_digi *ax25_digi, struct net_device *dev, unsigned int quality)
+static int __must_check nr_add_neigh(ax25_address *callsign,
+       ax25_digi *ax25_digi, struct net_device *dev, unsigned int quality)
 {
        struct nr_neigh *nr_neigh;
 
@@ -432,11 +434,12 @@ static int nr_add_neigh(ax25_address *callsign, ax25_digi *ax25_digi, struct net
        atomic_set(&nr_neigh->refcount, 1);
 
        if (ax25_digi != NULL && ax25_digi->ndigi > 0) {
-               if ((nr_neigh->digipeat = kmalloc(sizeof(*ax25_digi), GFP_KERNEL)) == NULL) {
+               nr_neigh->digipeat = kmemdup(ax25_digi, sizeof(*ax25_digi),
+                                            GFP_KERNEL);
+               if (nr_neigh->digipeat == NULL) {
                        kfree(nr_neigh);
                        return -ENOMEM;
                }
-               memcpy(nr_neigh->digipeat, ax25_digi, sizeof(*ax25_digi));
        }
 
        spin_lock_bh(&nr_neigh_list_lock);
@@ -577,7 +580,7 @@ static struct net_device *nr_ax25_dev_get(char *devname)
 {
        struct net_device *dev;
 
-       if ((dev = dev_get_by_name(devname)) == NULL)
+       if ((dev = dev_get_by_name(&init_net, devname)) == NULL)
                return NULL;
 
        if ((dev->flags & IFF_UP) && dev->type == ARPHRD_AX25)
@@ -595,7 +598,7 @@ struct net_device *nr_dev_first(void)
        struct net_device *dev, *first = NULL;
 
        read_lock(&dev_base_lock);
-       for (dev = dev_base; dev != NULL; dev = dev->next) {
+       for_each_netdev(&init_net, dev) {
                if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM)
                        if (first == NULL || strncmp(dev->name, first->name, 3) < 0)
                                first = dev;
@@ -615,12 +618,13 @@ struct net_device *nr_dev_get(ax25_address *addr)
        struct net_device *dev;
 
        read_lock(&dev_base_lock);
-       for (dev = dev_base; dev != NULL; dev = dev->next) {
+       for_each_netdev(&init_net, dev) {
                if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM && ax25cmp(addr, (ax25_address *)dev->dev_addr) == 0) {
                        dev_hold(dev);
                        goto out;
                }
        }
+       dev = NULL;
 out:
        read_unlock(&dev_base_lock);
        return dev;
@@ -725,15 +729,17 @@ void nr_link_failed(ax25_cb *ax25, int reason)
        struct nr_node  *nr_node = NULL;
 
        spin_lock_bh(&nr_neigh_list_lock);
-       nr_neigh_for_each(s, node, &nr_neigh_list)
+       nr_neigh_for_each(s, node, &nr_neigh_list) {
                if (s->ax25 == ax25) {
                        nr_neigh_hold(s);
                        nr_neigh = s;
                        break;
                }
+       }
        spin_unlock_bh(&nr_neigh_list_lock);
 
-       if (nr_neigh == NULL) return;
+       if (nr_neigh == NULL)
+               return;
 
        nr_neigh->ax25 = NULL;
        ax25_cb_put(ax25);
@@ -743,11 +749,13 @@ void nr_link_failed(ax25_cb *ax25, int reason)
                return;
        }
        spin_lock_bh(&nr_node_list_lock);
-       nr_node_for_each(nr_node, node, &nr_node_list)
+       nr_node_for_each(nr_node, node, &nr_node_list) {
                nr_node_lock(nr_node);
-               if (nr_node->which < nr_node->count && nr_node->routes[nr_node->which].neighbour == nr_neigh)
+               if (nr_node->which < nr_node->count &&
+                   nr_node->routes[nr_node->which].neighbour == nr_neigh)
                        nr_node->which++;
                nr_node_unlock(nr_node);
+       }
        spin_unlock_bh(&nr_node_list_lock);
        nr_neigh_put(nr_neigh);
 }
@@ -771,9 +779,13 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
        nr_src  = (ax25_address *)(skb->data + 0);
        nr_dest = (ax25_address *)(skb->data + 7);
 
-       if (ax25 != NULL)
-               nr_add_node(nr_src, "", &ax25->dest_addr, ax25->digipeat,
-                           ax25->ax25_dev->dev, 0, sysctl_netrom_obsolescence_count_initialiser);
+       if (ax25 != NULL) {
+               ret = nr_add_node(nr_src, "", &ax25->dest_addr, ax25->digipeat,
+                                 ax25->ax25_dev->dev, 0,
+                                 sysctl_netrom_obsolescence_count_initialiser);
+               if (ret)
+                       return ret;
+       }
 
        if ((dev = nr_dev_get(nr_dest)) != NULL) {      /* Its for me */
                if (ax25 == NULL)                       /* Its from me */
@@ -838,6 +850,7 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
        ret = (nr_neigh->ax25 != NULL);
        nr_node_unlock(nr_node);
        nr_node_put(nr_node);
+
        return ret;
 }
 
@@ -848,8 +861,8 @@ static void *nr_node_start(struct seq_file *seq, loff_t *pos)
        struct nr_node *nr_node;
        struct hlist_node *node;
        int i = 1;
-       spin_lock_bh(&nr_node_list_lock);
+
+       spin_lock_bh(&nr_node_list_lock);
        if (*pos == 0)
                return SEQ_START_TOKEN;
 
@@ -866,8 +879,8 @@ static void *nr_node_next(struct seq_file *seq, void *v, loff_t *pos)
 {
        struct hlist_node *node;
        ++*pos;
-       
-       node = (v == SEQ_START_TOKEN)  
+
+       node = (v == SEQ_START_TOKEN)
                ? nr_node_list.first
                : ((struct nr_node *)v)->node_node.next;
 
@@ -909,7 +922,7 @@ static int nr_node_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations nr_node_seqops = {
+static const struct seq_operations nr_node_seqops = {
        .start = nr_node_start,
        .next = nr_node_next,
        .stop = nr_node_stop,
@@ -921,7 +934,7 @@ static int nr_node_info_open(struct inode *inode, struct file *file)
        return seq_open(file, &nr_node_seqops);
 }
 
-struct file_operations nr_nodes_fops = {
+const struct file_operations nr_nodes_fops = {
        .owner = THIS_MODULE,
        .open = nr_node_info_open,
        .read = seq_read,
@@ -950,8 +963,8 @@ static void *nr_neigh_next(struct seq_file *seq, void *v, loff_t *pos)
 {
        struct hlist_node *node;
        ++*pos;
-       
-       node = (v == SEQ_START_TOKEN)  
+
+       node = (v == SEQ_START_TOKEN)
                ? nr_neigh_list.first
                : ((struct nr_neigh *)v)->neigh_node.next;
 
@@ -984,7 +997,7 @@ static int nr_neigh_show(struct seq_file *seq, void *v)
 
                if (nr_neigh->digipeat != NULL) {
                        for (i = 0; i < nr_neigh->digipeat->ndigi; i++)
-                               seq_printf(seq, " %s", 
+                               seq_printf(seq, " %s",
                                           ax2asc(buf, &nr_neigh->digipeat->calls[i]));
                }
 
@@ -993,7 +1006,7 @@ static int nr_neigh_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations nr_neigh_seqops = {
+static const struct seq_operations nr_neigh_seqops = {
        .start = nr_neigh_start,
        .next = nr_neigh_next,
        .stop = nr_neigh_stop,
@@ -1005,7 +1018,7 @@ static int nr_neigh_info_open(struct inode *inode, struct file *file)
        return seq_open(file, &nr_neigh_seqops);
 }
 
-struct file_operations nr_neigh_fops = {
+const struct file_operations nr_neigh_fops = {
        .owner = THIS_MODULE,
        .open = nr_neigh_info_open,
        .read = seq_read,