* [Patch net-next] phy: marvell/micrel: Fix Unpossible condition
@ 2016-02-19 23:35 Andrew Lunn
2016-02-20 4:42 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Lunn @ 2016-02-19 23:35 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Andrew Lunn
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>
---
drivers/net/phy/marvell.c | 10 +++++-----
drivers/net/phy/micrel.c | 9 +++++----
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 1dcbd3ff9e38..d0168f1a1bf0 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -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,
@@ -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,
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)
{
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,
--
2.7.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Patch net-next] phy: marvell/micrel: Fix Unpossible condition
2016-02-19 23:35 [Patch net-next] phy: marvell/micrel: Fix Unpossible condition Andrew Lunn
@ 2016-02-20 4:42 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-02-20 4:42 UTC (permalink / raw)
To: andrew; +Cc: netdev
From: Andrew Lunn <andrew@lunn.ch>
Date: Sat, 20 Feb 2016 00:35:29 +0100
> 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.
...
> 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>
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-02-20 4:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-19 23:35 [Patch net-next] phy: marvell/micrel: Fix Unpossible condition Andrew Lunn
2016-02-20 4:42 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).