[backfire] backport r31262
[openwrt-10.03/.git] / package / switch / src / switch-robo.c
index 481bb76a5b5b21b95769daf018a5761c6cddb8ea..35cf6df393d144679e55de9d62a94772481a6cfc 100644 (file)
@@ -21,7 +21,6 @@
  * 02110-1301, USA.
  */
 
-#include <linux/autoconf.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/if.h>
@@ -307,7 +306,7 @@ static int robo_probe(char *devname)
 {
        __u32 phyid;
        unsigned int i;
-       int err;
+       int err = 1;
 
        printk(KERN_INFO PFX "Probing device %s: ", devname);
        strcpy(robo.ifr.ifr_name, devname);
@@ -337,7 +336,7 @@ static int robo_probe(char *devname)
                    (mii->phy_id != ROBO_PHY_ADDR_BCM63XX) &&
                    (mii->phy_id != ROBO_PHY_ADDR_TG3)) {
                        printk("Invalid phy address (%d)\n", mii->phy_id);
-                       return 1;
+                       goto done;
                }
                robo.use_et = 0;
                /* The robo has a fixed PHY address that is different from the
@@ -350,7 +349,7 @@ static int robo_probe(char *devname)
 
        if (phyid == 0xffffffff || phyid == 0x55210022) {
                printk("No Robo switch in managed mode found, phy_id = 0x%08x\n", phyid);
-               return 1;
+               goto done;
        }
 
        /* Get the device ID */
@@ -367,11 +366,18 @@ static int robo_probe(char *devname)
        robo_switch_reset();
        err = robo_switch_enable();
        if (err)
-               return err;
+               goto done;
+       err = 0;
 
        printk("found a 5%s%x!%s\n", robo.devid & 0xff00 ? "" : "3", robo.devid,
                robo.is_5350 ? " It's a 5350." : "");
-       return 0;
+
+done:
+       if (err) {
+               dev_put(robo.dev);
+               robo.dev = NULL;
+       }
+       return err;
 }
 
 
@@ -500,8 +506,8 @@ static int handle_enable_vlan_write(void *driver, char *buf, int nr)
        robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL0, disable ? 0 :
                (1 << 7) /* 802.1Q VLAN */ | (3 << 5) /* mac check and hash */);
        robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL1, disable ? 0 :
-               (robo.devid == ROBO_DEVICE_ID_5325 ? (1 << 1) : 0) | /* RSV multicast */
-               robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL0) | (1 << 2) | (1 << 3));
+               (robo.devid == ROBO_DEVICE_ID_5325 ? (1 << 1) :
+               0) | (1 << 2) | (1 << 3)); /* RSV multicast */
 
        if (robo.devid != ROBO_DEVICE_ID_5325)
                return 0;
@@ -616,6 +622,8 @@ static int __init robo_init(void)
 static void __exit robo_exit(void)
 {
        switch_unregister_driver(DRIVER_NAME);
+       if (robo.dev)
+               dev_put(robo.dev);
        kfree(robo.device);
 }