net: dsa: bcm_sf2: fix unmapping registers in case of errors
authorFlorian Fainelli <f.fainelli@gmail.com>
Wed, 26 Nov 2014 02:08:48 +0000 (18:08 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 26 Nov 2014 17:03:56 +0000 (12:03 -0500)
In case we fail to ioremap() one of our registers, we would be leaking
existing mappings, unwind those accordingly on errors.

Fixes: 246d7f773c13 ("net: dsa: add Broadcom SF2 switch driver")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/bcm_sf2.c

index b9625968daacc0eb89c0f7371a3a4e70242f95ce..46632e8b6336e7fc802cd39bed5894843b7635c7 100644 (file)
@@ -404,7 +404,8 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
                *base = of_iomap(dn, i);
                if (*base == NULL) {
                        pr_err("unable to find register: %s\n", reg_names[i]);
-                       return -ENODEV;
+                       ret = -ENOMEM;
+                       goto out_unmap;
                }
                base++;
        }
@@ -484,7 +485,8 @@ out_free_irq0:
 out_unmap:
        base = &priv->core;
        for (i = 0; i < BCM_SF2_REGS_NUM; i++) {
-               iounmap(*base);
+               if (*base)
+                       iounmap(*base);
                base++;
        }
        return ret;