Skip to content

Commit 321b4d4

Browse files
lunndavem330
authored andcommitted
phy: marvell/micrel: Fix Unpossible condition
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 <[email protected]> Reported-by: Julia.Lawall <[email protected]> Signed-off-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2f86017 commit 321b4d4

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

drivers/net/phy/marvell.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,8 @@ static u64 marvell_get_stat(struct phy_device *phydev, int i)
10651065
{
10661066
struct marvell_hw_stat stat = marvell_hw_stats[i];
10671067
struct marvell_priv *priv = phydev->priv;
1068-
int err, oldpage;
1069-
u64 val;
1068+
int err, oldpage, val;
1069+
u64 ret;
10701070

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

10771077
val = phy_read(phydev, stat.reg);
10781078
if (val < 0) {
1079-
val = UINT64_MAX;
1079+
ret = UINT64_MAX;
10801080
} else {
10811081
val = val & ((1 << stat.bits) - 1);
10821082
priv->stats[i] += val;
1083-
val = priv->stats[i];
1083+
ret = priv->stats[i];
10841084
}
10851085

10861086
phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
10871087

1088-
return val;
1088+
return ret;
10891089
}
10901090

10911091
static void marvell_get_stats(struct phy_device *phydev,

drivers/net/phy/micrel.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,18 +612,19 @@ static u64 kszphy_get_stat(struct phy_device *phydev, int i)
612612
{
613613
struct kszphy_hw_stat stat = kszphy_hw_stats[i];
614614
struct kszphy_priv *priv = phydev->priv;
615-
u64 val;
615+
int val;
616+
u64 ret;
616617

617618
val = phy_read(phydev, stat.reg);
618619
if (val < 0) {
619-
val = UINT64_MAX;
620+
ret = UINT64_MAX;
620621
} else {
621622
val = val & ((1 << stat.bits) - 1);
622623
priv->stats[i] += val;
623-
val = priv->stats[i];
624+
ret = priv->stats[i];
624625
}
625626

626-
return val;
627+
return ret;
627628
}
628629

629630
static void kszphy_get_stats(struct phy_device *phydev,

0 commit comments

Comments
 (0)