From f3360fdf67271331040c9db0502f3083b2e274e6 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Wed, 13 Feb 2013 16:02:20 +0000 Subject: [PATCH] switch: improve error handling in robo_probe() SVN-Revision: 35578 --- package/switch/src/switch-robo.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/package/switch/src/switch-robo.c b/package/switch/src/switch-robo.c index 1372fbd624..e33c30ec4d 100644 --- a/package/switch/src/switch-robo.c +++ b/package/switch/src/switch-robo.c @@ -278,7 +278,7 @@ static int robo_probe(char *devname) { __u32 phyid; unsigned int i; - int err = 1; + int err = -1; struct mii_ioctl_data *mii; printk(KERN_INFO PFX "Probing device '%s'\n", devname); @@ -286,11 +286,13 @@ static int robo_probe(char *devname) if ((robo.dev = dev_get_by_name(&init_net, devname)) == NULL) { printk(KERN_ERR PFX "No such device\n"); - return 1; + err = -ENODEV; + goto err_done; } if (!robo.dev->netdev_ops || !robo.dev->netdev_ops->ndo_do_ioctl) { printk(KERN_ERR PFX "ndo_do_ioctl not implemented in ethernet driver\n"); - return 1; + err = -ENXIO; + goto err_put; } robo.device = devname; @@ -302,7 +304,7 @@ static int robo_probe(char *devname) err = do_ioctl(SIOCGMIIPHY); if (err < 0) { printk(KERN_ERR PFX "error (%i) while accessing MII phy registers with ioctls\n", err); - goto done; + goto err_put; } /* got phy address check for robo address */ @@ -311,7 +313,8 @@ static int robo_probe(char *devname) (mii->phy_id != ROBO_PHY_ADDR_BCM63XX) && (mii->phy_id != ROBO_PHY_ADDR_TG3)) { printk(KERN_ERR PFX "Invalid phy address (%d)\n", mii->phy_id); - goto done; + err = -ENODEV; + goto err_put; } phyid = mdio_read(ROBO_PHY_ADDR, 0x2) | @@ -319,7 +322,8 @@ static int robo_probe(char *devname) if (phyid == 0xffffffff || phyid == 0x55210022) { printk(KERN_ERR PFX "No Robo switch in managed mode found, phy_id = 0x%08x\n", phyid); - goto done; + err = -ENODEV; + goto err_put; } /* Get the device ID */ @@ -336,17 +340,16 @@ static int robo_probe(char *devname) robo_switch_reset(); err = robo_switch_enable(); if (err) - goto done; - err = 0; + goto err_put; printk(KERN_INFO PFX "found a 5%s%x!%s at %s\n", robo.devid & 0xff00 ? "" : "3", robo.devid, robo.is_5350 ? " It's a 5350." : "", devname); -done: - if (err) { - dev_put(robo.dev); - robo.dev = NULL; - } + return 0; +err_put: + dev_put(robo.dev); + robo.dev = NULL; +err_done: return err; } -- 2.25.1