[lvc-project] [PATCH v1] net/ethtool/ioctl: ensure that we have phy ops before using them
Daniil Tatianin
d-tatianin at yandex-team.ru
Mon Nov 14 11:15:32 MSK 2022
ops->get_ethtool_phy_stats was getting called in an else branch
of ethtool_get_phy_stats() unconditionally without making sure
it was actually present.
Move the check out to the top of the function so that we can early
return if it's not present.
Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.
Signed-off-by: Daniil Tatianin <d-tatianin at yandex-team.ru>
---
net/ethtool/ioctl.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 80d2a00d3097..cd50e83f0977 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -2039,6 +2039,9 @@ static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr)
u64 *data;
int ret, n_stats;
+ if (!(phydev && phy_ops && phy_ops->get_stats) &&
+ !ops->get_ethtool_phy_stats)
+ return -EOPNOTSUPP;
if (!phydev && (!ops->get_ethtool_phy_stats || !ops->get_sset_count))
return -EOPNOTSUPP;
@@ -2063,13 +2066,12 @@ static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr)
if (!data)
return -ENOMEM;
- if (dev->phydev && !ops->get_ethtool_phy_stats &&
- phy_ops && phy_ops->get_stats) {
- ret = phy_ops->get_stats(dev->phydev, &stats, data);
+ if (ops->get_ethtool_phy_stats) {
+ ops->get_ethtool_phy_stats(dev, &stats, data);
+ } else {
+ ret = phy_ops->get_stats(phydev, &stats, data);
if (ret < 0)
goto out;
- } else {
- ops->get_ethtool_phy_stats(dev, &stats, data);
}
} else {
data = NULL;
--
2.25.1
More information about the lvc-project
mailing list