of: Always use 'struct device.of_node' to get device node pointer.
[safe/jmp/linux-2.6] / drivers / net / hamradio / bpqether.c
index 5105548..14f01d1 100644 (file)
@@ -61,6 +61,7 @@
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/net.h>
+#include <linux/slab.h>
 #include <net/ax25.h>
 #include <linux/inet.h>
 #include <linux/netdevice.h>
@@ -167,10 +168,7 @@ static inline struct net_device *bpq_get_ax25_dev(struct net_device *dev)
 
 static inline int dev_is_ethdev(struct net_device *dev)
 {
-       return (
-                       dev->type == ARPHRD_ETHER
-                       && strncmp(dev->name, "dummy", 5)
-       );
+       return (dev->type == ARPHRD_ETHER && strncmp(dev->name, "dummy", 5));
 }
 
 /* ------------------------------------------------------------------------ */
@@ -186,7 +184,7 @@ static int bpq_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_ty
        struct ethhdr *eth;
        struct bpqdev *bpq;
 
-       if (dev_net(dev) != &init_net)
+       if (!net_eq(dev_net(dev), &init_net))
                goto drop;
 
        if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
@@ -247,11 +245,11 @@ drop:
 /*
  *     Send an AX.25 frame via an ethernet interface
  */
-static int bpq_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t bpq_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-       struct sk_buff *newskb;
        unsigned char *ptr;
        struct bpqdev *bpq;
+       struct net_device *orig_dev;
        int size;
 
        /*
@@ -260,39 +258,35 @@ static int bpq_xmit(struct sk_buff *skb, struct net_device *dev)
         */
        if (!netif_running(dev)) {
                kfree_skb(skb);
-               return -ENODEV;
+               return NETDEV_TX_OK;
        }
 
-       skb_pull(skb, 1);
+       skb_pull(skb, 1);                       /* Drop KISS byte */
        size = skb->len;
 
        /*
-        * The AX.25 code leaves enough room for the ethernet header, but
-        * sendto() does not.
+        * We're about to mess with the skb which may still shared with the
+        * generic networking code so unshare and ensure it's got enough
+        * space for the BPQ headers.
         */
-       if (skb_headroom(skb) < AX25_BPQ_HEADER_LEN) {  /* Ough! */
-               if ((newskb = skb_realloc_headroom(skb, AX25_BPQ_HEADER_LEN)) == NULL) {
-                       printk(KERN_WARNING "bpqether: out of memory\n");
-                       kfree_skb(skb);
-                       return NETDEV_TX_OK;
-               }
-
-               if (skb->sk != NULL)
-                       skb_set_owner_w(newskb, skb->sk);
-
+       if (skb_cow(skb, AX25_BPQ_HEADER_LEN)) {
+               if (net_ratelimit())
+                       pr_err("bpqether: out of memory\n");
                kfree_skb(skb);
-               skb = newskb;
+
+               return NETDEV_TX_OK;
        }
 
-       ptr = skb_push(skb, 2);
+       ptr = skb_push(skb, 2);                 /* Make space for length */
 
        *ptr++ = (size + 5) % 256;
        *ptr++ = (size + 5) / 256;
 
        bpq = netdev_priv(dev);
 
+       orig_dev = dev;
        if ((dev = bpq_get_ether_dev(dev)) == NULL) {
-               dev->stats.tx_dropped++;
+               orig_dev->stats.tx_dropped++;
                kfree_skb(skb);
                return NETDEV_TX_OK;
        }
@@ -305,7 +299,7 @@ static int bpq_xmit(struct sk_buff *skb, struct net_device *dev)
   
        dev_queue_xmit(skb);
        netif_wake_queue(dev);
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /*
@@ -558,7 +552,7 @@ static int bpq_device_event(struct notifier_block *this,unsigned long event, voi
 {
        struct net_device *dev = (struct net_device *)ptr;
 
-       if (dev_net(dev) != &init_net)
+       if (!net_eq(dev_net(dev), &init_net))
                return NOTIFY_DONE;
 
        if (!dev_is_ethdev(dev))