bnx2: Fix compiler warning in bnx2_disable_forced_2g5().
authorMichael Chan <mchan@broadcom.com>
Tue, 8 Jun 2010 07:21:30 +0000 (07:21 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 12 Jun 2010 01:37:07 +0000 (18:37 -0700)
drivers/net/bnx2.c: In function 'bnx2_disable_forced_2g5':
drivers/net/bnx2.c:1489: warning: 'bmcr' may be used uninitialized in this function

We fix it by checking return values from all bnx2_read_phy() and proceeding
to do read-modify-write only if the read operation is successful.

The related bnx2_enable_forced_2g5() is also fixed the same way.

Reported-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bnx2.c

index 949d7a9dcf9269b4ccef78703ffb7e1701767237..522de9f818be937ae0925fb481ab106a1f0b5d8e 100644 (file)
@@ -1446,7 +1446,8 @@ bnx2_test_and_disable_2g5(struct bnx2 *bp)
 static void
 bnx2_enable_forced_2g5(struct bnx2 *bp)
 {
-       u32 bmcr;
+       u32 uninitialized_var(bmcr);
+       int err;
 
        if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
                return;
@@ -1456,22 +1457,28 @@ bnx2_enable_forced_2g5(struct bnx2 *bp)
 
                bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
                               MII_BNX2_BLK_ADDR_SERDES_DIG);
-               bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val);
-               val &= ~MII_BNX2_SD_MISC1_FORCE_MSK;
-               val |= MII_BNX2_SD_MISC1_FORCE | MII_BNX2_SD_MISC1_FORCE_2_5G;
-               bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
+               if (!bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val)) {
+                       val &= ~MII_BNX2_SD_MISC1_FORCE_MSK;
+                       val |= MII_BNX2_SD_MISC1_FORCE |
+                               MII_BNX2_SD_MISC1_FORCE_2_5G;
+                       bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
+               }
 
                bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
                               MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
-               bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
+               err = bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
 
        } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
-               bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
-               bmcr |= BCM5708S_BMCR_FORCE_2500;
+               err = bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
+               if (!err)
+                       bmcr |= BCM5708S_BMCR_FORCE_2500;
        } else {
                return;
        }
 
+       if (err)
+               return;
+
        if (bp->autoneg & AUTONEG_SPEED) {
                bmcr &= ~BMCR_ANENABLE;
                if (bp->req_duplex == DUPLEX_FULL)
@@ -1483,7 +1490,8 @@ bnx2_enable_forced_2g5(struct bnx2 *bp)
 static void
 bnx2_disable_forced_2g5(struct bnx2 *bp)
 {
-       u32 bmcr;
+       u32 uninitialized_var(bmcr);
+       int err;
 
        if (!(bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE))
                return;
@@ -1493,21 +1501,26 @@ bnx2_disable_forced_2g5(struct bnx2 *bp)
 
                bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
                               MII_BNX2_BLK_ADDR_SERDES_DIG);
-               bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val);
-               val &= ~MII_BNX2_SD_MISC1_FORCE;
-               bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
+               if (!bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val)) {
+                       val &= ~MII_BNX2_SD_MISC1_FORCE;
+                       bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
+               }
 
                bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
                               MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
-               bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
+               err = bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
 
        } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
-               bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
-               bmcr &= ~BCM5708S_BMCR_FORCE_2500;
+               err = bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
+               if (!err)
+                       bmcr &= ~BCM5708S_BMCR_FORCE_2500;
        } else {
                return;
        }
 
+       if (err)
+               return;
+
        if (bp->autoneg & AUTONEG_SPEED)
                bmcr |= BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_ANRESTART;
        bnx2_write_phy(bp, bp->mii_bmcr, bmcr);