diff options
author | Andrew Lunn <andrew@lunn.ch> | 2016-02-19 18:35:29 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-02-19 23:41:37 -0500 |
commit | 321b4d4bd12f90e7497c9ab057aafcc2649aa902 (patch) | |
tree | 303d777fcba3f7aedecce0b5d3c059f2997e9229 /drivers/net/phy/micrel.c | |
parent | 2f86017748d96723372864c597d08d11c09dd759 (diff) |
phy: marvell/micrel: Fix Unpossible condition
commit 2b2427d06426 ("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: 2b2427d06426 ("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>
Diffstat (limited to 'drivers/net/phy/micrel.c')
-rw-r--r-- | drivers/net/phy/micrel.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 03833dbfca67..48219c83fb00 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c | |||
@@ -612,18 +612,19 @@ static u64 kszphy_get_stat(struct phy_device *phydev, int i) | |||
612 | { | 612 | { |
613 | struct kszphy_hw_stat stat = kszphy_hw_stats[i]; | 613 | struct kszphy_hw_stat stat = kszphy_hw_stats[i]; |
614 | struct kszphy_priv *priv = phydev->priv; | 614 | struct kszphy_priv *priv = phydev->priv; |
615 | u64 val; | 615 | int val; |
616 | u64 ret; | ||
616 | 617 | ||
617 | val = phy_read(phydev, stat.reg); | 618 | val = phy_read(phydev, stat.reg); |
618 | if (val < 0) { | 619 | if (val < 0) { |
619 | val = UINT64_MAX; | 620 | ret = UINT64_MAX; |
620 | } else { | 621 | } else { |
621 | val = val & ((1 << stat.bits) - 1); | 622 | val = val & ((1 << stat.bits) - 1); |
622 | priv->stats[i] += val; | 623 | priv->stats[i] += val; |
623 | val = priv->stats[i]; | 624 | ret = priv->stats[i]; |
624 | } | 625 | } |
625 | 626 | ||
626 | return val; | 627 | return ret; |
627 | } | 628 | } |
628 | 629 | ||
629 | static void kszphy_get_stats(struct phy_device *phydev, | 630 | static void kszphy_get_stats(struct phy_device *phydev, |