[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <c02d4d86-6e65-4270-bc46-70acb6eb2d4a@gmail.com>
Date: Thu, 15 Feb 2024 14:05:54 +0100
From: Heiner Kallweit <hkallweit1@...il.com>
To: Andrew Lunn <andrew@...n.ch>,
Russell King - ARM Linux <linux@...linux.org.uk>,
Paolo Abeni <pabeni@...hat.com>, Jakub Kicinski <kuba@...nel.org>,
David Miller <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: [PATCH net-next] ethtool: check for unsupported modes in EEE
advertisement
Let the core check whether userspace returned unsupported modes in the
EEE advertisement bitmap. This allows to remove these checks from
drivers.
Signed-off-by: Heiner Kallweit <hkallweit1@...il.com>
---
net/ethtool/eee.c | 12 ++++++++++++
net/ethtool/ioctl.c | 3 +++
2 files changed, 15 insertions(+)
diff --git a/net/ethtool/eee.c b/net/ethtool/eee.c
index db6faa18f..9596cf888 100644
--- a/net/ethtool/eee.c
+++ b/net/ethtool/eee.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/linkmode.h>
+
#include "netlink.h"
#include "common.h"
#include "bitset.h"
@@ -145,6 +147,7 @@ static int
ethnl_set_eee(struct ethnl_req_info *req_info, struct genl_info *info)
{
struct net_device *dev = req_info->dev;
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(tmp);
struct nlattr **tb = info->attrs;
struct ethtool_keee eee = {};
bool mod = false;
@@ -166,6 +169,15 @@ ethnl_set_eee(struct ethnl_req_info *req_info, struct genl_info *info)
}
if (ret < 0)
return ret;
+
+ if (ethtool_eee_use_linkmodes(&eee)) {
+ if (linkmode_andnot(tmp, eee.advertised, eee.supported))
+ return -EINVAL;
+ } else {
+ if (eee.advertised_u32 & ~eee.supported_u32)
+ return -EINVAL;
+ }
+
ethnl_update_bool(&eee.eee_enabled, tb[ETHTOOL_A_EEE_ENABLED], &mod);
ethnl_update_bool(&eee.tx_lpi_enabled, tb[ETHTOOL_A_EEE_TX_LPI_ENABLED],
&mod);
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 1763e8b69..622a2d4fc 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1590,6 +1590,9 @@ static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
if (copy_from_user(&eee, useraddr, sizeof(eee)))
return -EFAULT;
+ if (eee.advertised & ~eee.supported)
+ return -EINVAL;
+
eee_to_keee(&keee, &eee);
ret = dev->ethtool_ops->set_eee(dev, &keee);
if (!ret)
--
2.43.1
Powered by blists - more mailing lists