[NET]: Conversions from kmalloc+memset to k(z|c)alloc.
[linux-3.10.git] / net / decnet / dn_neigh.c
index f32dba9..ff0ebe9 100644 (file)
@@ -24,7 +24,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/net.h>
 #include <linux/module.h>
 #include <linux/socket.h>
@@ -95,7 +94,7 @@ static struct neigh_ops dn_phase3_ops = {
 struct neigh_table dn_neigh_table = {
        .family =                       PF_DECnet,
        .entry_size =                   sizeof(struct dn_neigh),
-       .key_len =                      sizeof(dn_address),
+       .key_len =                      sizeof(__le16),
        .hash =                         dn_neigh_hash,
        .constructor =                  dn_neigh_construct,
        .id =                           "dn_neigh_cache",
@@ -123,7 +122,7 @@ struct neigh_table dn_neigh_table = {
 
 static u32 dn_neigh_hash(const void *pkey, const struct net_device *dev)
 {
-       return jhash_2words(*(dn_address *)pkey, 0, dn_neigh_table.hash_rnd);
+       return jhash_2words(*(__u16 *)pkey, 0, dn_neigh_table.hash_rnd);
 }
 
 static int dn_neigh_construct(struct neighbour *neigh)
@@ -148,12 +147,12 @@ static int dn_neigh_construct(struct neighbour *neigh)
 
        __neigh_parms_put(neigh->parms);
        neigh->parms = neigh_parms_clone(parms);
-       rcu_read_unlock();
 
        if (dn_db->use_long)
                neigh->ops = &dn_long_ops;
        else
                neigh->ops = &dn_short_ops;
+       rcu_read_unlock();
 
        if (dn->flags & DN_NDFLAG_P3)
                neigh->ops = &dn_phase3_ops;
@@ -249,14 +248,14 @@ static int dn_long_output(struct sk_buff *skb)
        data = skb_push(skb, sizeof(struct dn_long_packet) + 3);
        lp = (struct dn_long_packet *)(data+3);
 
-       *((unsigned short *)data) = dn_htons(skb->len - 2);
+       *((__le16 *)data) = dn_htons(skb->len - 2);
        *(data + 2) = 1 | DN_RT_F_PF; /* Padding */
 
        lp->msgflg   = DN_RT_PKT_LONG|(cb->rt_flags&(DN_RT_F_IE|DN_RT_F_RQR|DN_RT_F_RTS));
        lp->d_area   = lp->d_subarea = 0;
-       dn_dn2eth(lp->d_id, dn_ntohs(cb->dst));
+       dn_dn2eth(lp->d_id, cb->dst);
        lp->s_area   = lp->s_subarea = 0;
-       dn_dn2eth(lp->s_id, dn_ntohs(cb->src));
+       dn_dn2eth(lp->s_id, cb->src);
        lp->nl2      = 0;
        lp->visit_ct = cb->hops & 0x3f;
        lp->s_class  = 0;
@@ -293,7 +292,7 @@ static int dn_short_output(struct sk_buff *skb)
         }
 
        data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
-       *((unsigned short *)data) = dn_htons(skb->len - 2);
+       *((__le16 *)data) = dn_htons(skb->len - 2);
        sp = (struct dn_short_packet *)(data+2);
 
        sp->msgflg     = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS));
@@ -335,7 +334,7 @@ static int dn_phase3_output(struct sk_buff *skb)
        }
 
        data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
-       *((unsigned short *)data) = dn_htons(skb->len - 2);
+       *((__le16 *)data) = dn_htons(skb->len - 2);
        sp = (struct dn_short_packet *)(data + 2);
 
        sp->msgflg   = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS));
@@ -373,9 +372,9 @@ int dn_neigh_router_hello(struct sk_buff *skb)
        struct neighbour *neigh;
        struct dn_neigh *dn;
        struct dn_dev *dn_db;
-       dn_address src;
+       __le16 src;
 
-       src = dn_htons(dn_eth2dn(msg->id));
+       src = dn_eth2dn(msg->id);
 
        neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
 
@@ -408,11 +407,14 @@ int dn_neigh_router_hello(struct sk_buff *skb)
                        }
                }
 
-               if (!dn_db->router) {
-                       dn_db->router = neigh_clone(neigh);
-               } else {
-                       if (msg->priority > ((struct dn_neigh *)dn_db->router)->priority)
-                               neigh_release(xchg(&dn_db->router, neigh_clone(neigh)));
+               /* Only use routers in our area */
+               if ((dn_ntohs(src)>>10) == (dn_ntohs((decnet_address))>>10)) {
+                       if (!dn_db->router) {
+                               dn_db->router = neigh_clone(neigh);
+                       } else {
+                               if (msg->priority > ((struct dn_neigh *)dn_db->router)->priority)
+                                       neigh_release(xchg(&dn_db->router, neigh_clone(neigh)));
+                       }
                }
                write_unlock(&neigh->lock);
                neigh_release(neigh);
@@ -430,9 +432,9 @@ int dn_neigh_endnode_hello(struct sk_buff *skb)
        struct endnode_hello_message *msg = (struct endnode_hello_message *)skb->data;
        struct neighbour *neigh;
        struct dn_neigh *dn;
-       dn_address src;
+       __le16 src;
 
-       src = dn_htons(dn_eth2dn(msg->id));
+       src = dn_eth2dn(msg->id);
 
        neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
 
@@ -490,7 +492,6 @@ struct elist_cb_state {
 static void neigh_elist_cb(struct neighbour *neigh, void *_info)
 {
        struct elist_cb_state *s = _info;
-       struct dn_dev *dn_db;
        struct dn_neigh *dn;
 
        if (neigh->dev != s->dev)
@@ -500,10 +501,6 @@ static void neigh_elist_cb(struct neighbour *neigh, void *_info)
        if (!(dn->flags & (DN_NDFLAG_R1|DN_NDFLAG_R2)))
                return;
 
-       dn_db = (struct dn_dev *) s->dev->dn_ptr;
-       if (dn_db->parms.forwarding == 1 && (dn->flags & DN_NDFLAG_R2))
-               return;
-
        if (s->t == s->n)
                s->rs = dn_find_slot(s->ptr, s->n, dn->priority);
        else
@@ -583,12 +580,11 @@ static int dn_neigh_seq_open(struct inode *inode, struct file *file)
 {
        struct seq_file *seq;
        int rc = -ENOMEM;
-       struct neigh_seq_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
+       struct neigh_seq_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
 
        if (!s)
                goto out;
 
-       memset(s, 0, sizeof(*s));
        rc = seq_open(file, &dn_neigh_seq_ops);
        if (rc)
                goto out_kfree;