Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / net / wanrouter / wanmain.c
index de4cc97..258daa8 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>      /* support for loadable modules */
 #include <linux/slab.h>                /* kmalloc(), kfree() */
+#include <linux/smp_lock.h>
 #include <linux/mm.h>
 #include <linux/string.h>      /* inline mem*, str* functions */
 
 #include <linux/vmalloc.h>     /* vmalloc, vfree */
 #include <asm/uaccess.h>        /* copy_to/from_user */
 #include <linux/init.h>         /* __initfunc et al. */
-#include <net/syncppp.h>
 
 #define KMEM_SAFETYZONE 8
 
+#define DEV_TO_SLAVE(dev)      (*((struct net_device **)netdev_priv(dev)))
+
 /*
  *     Function Prototypes
  */
@@ -85,8 +87,10 @@ static int wanrouter_device_del_if(struct wan_device *wandev,
 
 static struct wan_device *wanrouter_find_device(char *name);
 static int wanrouter_delete_interface(struct wan_device *wandev, char *name);
-static void lock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags);
-static void unlock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags);
+static void lock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags)
+       __acquires(lock);
+static void unlock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags)
+       __releases(lock);
 
 
 
@@ -512,7 +516,7 @@ static int wanrouter_device_shutdown(struct wan_device *wandev)
                if (err)
                        return err;
                /* The above function deallocates the current dev
-                * structure. Therefore, we cannot use dev->priv
+                * structure. Therefore, we cannot use netdev_priv(dev)
                 * as the next element: wandev->dev points to the
                 * next element */
                dev = wandev->dev;
@@ -590,10 +594,6 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
                err = -EPROTONOSUPPORT;
                goto out;
        } else {
-               dev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
-               err = -ENOBUFS;
-               if (dev == NULL)
-                       goto out;
                err = wandev->new_if(wandev, dev, cnf);
        }
 
@@ -623,10 +623,9 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
                                        wandev->dev = dev;
                                } else {
                                        for (slave=wandev->dev;
-                                        *((struct net_device **)slave->priv);
-                                slave = *((struct net_device **)slave->priv));
-
-                                    *((struct net_device **)slave->priv) = dev;
+                                            DEV_TO_SLAVE(slave);
+                                            slave = DEV_TO_SLAVE(slave))
+                                               DEV_TO_SLAVE(slave) = dev;
                                }
                                ++wandev->ndev;
 
@@ -637,15 +636,9 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
                }
                if (wandev->del_if)
                        wandev->del_if(wandev, dev);
+               free_netdev(dev);
        }
 
-       /* This code has moved from del_if() function */
-       kfree(dev->priv);
-       dev->priv = NULL;
-
-       /* Sync PPP is disabled */
-       if (cnf->config_id != WANCONFIG_MPPP)
-               kfree(dev);
 out:
        kfree(cnf);
        return err;
@@ -735,7 +728,7 @@ static int wanrouter_delete_interface(struct wan_device *wandev, char *name)
        dev = wandev->dev;
        prev = NULL;
        while (dev && strcmp(name, dev->name)) {
-               struct net_device **slave = dev->priv;
+               struct net_device **slave = netdev_priv(dev);
                prev = dev;
                dev = *slave;
        }
@@ -752,12 +745,12 @@ static int wanrouter_delete_interface(struct wan_device *wandev, char *name)
 
        lock_adapter_irq(&wandev->lock, &smp_flags);
        if (prev) {
-               struct net_device **prev_slave = prev->priv;
-               struct net_device **slave = dev->priv;
+               struct net_device **prev_slave = netdev_priv(prev);
+               struct net_device **slave = netdev_priv(dev);
 
                *prev_slave = *slave;
        } else {
-               struct net_device **slave = dev->priv;
+               struct net_device **slave = netdev_priv(dev);
                wandev->dev = *slave;
        }
        --wandev->ndev;
@@ -765,11 +758,6 @@ static int wanrouter_delete_interface(struct wan_device *wandev, char *name)
 
        printk(KERN_INFO "%s: unregistering '%s'\n", wandev->name, dev->name);
 
-       /* Due to new interface linking method using dev->priv,
-        * this code has moved from del_if() function.*/
-       kfree(dev->priv);
-       dev->priv=NULL;
-
        unregister_netdev(dev);
 
        free_netdev(dev);
@@ -778,12 +766,14 @@ static int wanrouter_delete_interface(struct wan_device *wandev, char *name)
 }
 
 static void lock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags)
+       __acquires(lock)
 {
        spin_lock_irqsave(lock, *smp_flags);
 }
 
 
 static void unlock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags)
+       __releases(lock)
 {
        spin_unlock_irqrestore(lock, *smp_flags);
 }