Skip to content

Commit d7932e6

Browse files
vladimirolteangregkh
authored andcommitted
net: dsa: fix error code getting shifted with 4 in dsa_slave_get_sset_count
[ Upstream commit b94cbc9 ] DSA implements a bunch of 'standardized' ethtool statistics counters, namely tx_packets, tx_bytes, rx_packets, rx_bytes. So whatever the hardware driver returns in .get_sset_count(), we need to add 4 to that. That is ok, except that .get_sset_count() can return a negative error code, for example: b53_get_sset_count -> phy_ethtool_get_sset_count -> return -EIO -EIO is -5, and with 4 added to it, it becomes -1, aka -EPERM. One can imagine that certain error codes may even become positive, although based on code inspection I did not see instances of that. Check the error code first, if it is negative return it as-is. Based on a similar patch for dsa_master_get_strings from Dan Carpenter: https://patchwork.kernel.org/project/netdevbpf/patch/YJaSe3RPgn7gKxZv@mwanda/ Fixes: 91da11f ("net: Distributed Switch Architecture protocol support") Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d5b0a15 commit d7932e6

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎net/dsa/slave.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -746,13 +746,15 @@ static int dsa_slave_get_sset_count(struct net_device *dev, int sset)
746746
struct dsa_switch *ds = dp->ds;
747747

748748
if (sset == ETH_SS_STATS) {
749-
int count;
749+
int count = 0;
750750

751-
count = 4;
752-
if (ds->ops->get_sset_count)
753-
count += ds->ops->get_sset_count(ds, dp->index, sset);
751+
if (ds->ops->get_sset_count) {
752+
count = ds->ops->get_sset_count(ds, dp->index, sset);
753+
if (count < 0)
754+
return count;
755+
}
754756

755-
return count;
757+
return count + 4;
756758
}
757759

758760
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)