Skip to content

Commit

Permalink
phy: marvell/micrel: Fix Unpossible condition
Browse files Browse the repository at this point in the history
commit 2b2427d ("phy: micrel: Add ethtool statistics counters")
from Dec 30, 2015, leads to the following static checker
warning:

        drivers/net/phy/micrel.c:609 kszphy_get_stat()
        warn: unsigned 'val' is never less than zero.

drivers/net/phy/micrel.c
   602  static u64 kszphy_get_stat(struct phy_device *phydev, int i)
   603  {
   604          struct kszphy_hw_stat stat = kszphy_hw_stats[i];
   605          struct kszphy_priv *priv = phydev->priv;
   606          u64 val;
   607
   608          val = phy_read(phydev, stat.reg);
   609          if (val < 0) {
                    ^^^^^^^
Unpossible!

   610                  val = UINT64_MAX;
   611          } else {
   612                  val = val & ((1 << stat.bits) - 1);
   613                  priv->stats[i] += val;
   614                  val = priv->stats[i];
   615          }
   616
   617          return val;
   618  }

The same problem exists in the Marvell driver. Fix both.

Fixes: 2b2427d ("phy: micrel: Add ethtool statistics counters")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reported-by: Julia.Lawall <julia.lawall@lip6.fr>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Andrew Lunn authored and David S. Miller committed Feb 20, 2016
1 parent 2f86017 commit 321b4d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions drivers/net/phy/marvell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,8 +1065,8 @@ static u64 marvell_get_stat(struct phy_device *phydev, int i)
{
struct marvell_hw_stat stat = marvell_hw_stats[i];
struct marvell_priv *priv = phydev->priv;
int err, oldpage;
u64 val;
int err, oldpage, val;
u64 ret;

oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
Expand All @@ -1076,16 +1076,16 @@ static u64 marvell_get_stat(struct phy_device *phydev, int i)

val = phy_read(phydev, stat.reg);
if (val < 0) {
val = UINT64_MAX;
ret = UINT64_MAX;
} else {
val = val & ((1 << stat.bits) - 1);
priv->stats[i] += val;
val = priv->stats[i];
ret = priv->stats[i];
}

phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);

return val;
return ret;
}

static void marvell_get_stats(struct phy_device *phydev,
Expand Down
9 changes: 5 additions & 4 deletions drivers/net/phy/micrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,18 +612,19 @@ static u64 kszphy_get_stat(struct phy_device *phydev, int i)
{
struct kszphy_hw_stat stat = kszphy_hw_stats[i];
struct kszphy_priv *priv = phydev->priv;
u64 val;
int val;
u64 ret;

val = phy_read(phydev, stat.reg);
if (val < 0) {
val = UINT64_MAX;
ret = UINT64_MAX;
} else {
val = val & ((1 << stat.bits) - 1);
priv->stats[i] += val;
val = priv->stats[i];
ret = priv->stats[i];
}

return val;
return ret;
}

static void kszphy_get_stats(struct phy_device *phydev,
Expand Down

0 comments on commit 321b4d4

Please sign in to comment.