netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Danielle Ratson <danieller@nvidia.com>
To: <netdev@vger.kernel.org>
Cc: <davem@davemloft.net>, <kuba@kernel.org>, <jiri@nvidia.com>,
	<andrew@lunn.ch>, <f.fainelli@gmail.com>, <mkubecek@suse.cz>,
	<mlxsw@nvidia.com>, <idosch@nvidia.com>,
	Danielle Ratson <danieller@nvidia.com>
Subject: [PATCH net-next v4 1/8] ethtool: Validate master slave configuration before rtnl_lock()
Date: Tue, 2 Feb 2021 20:06:05 +0200	[thread overview]
Message-ID: <20210202180612.325099-2-danieller@nvidia.com> (raw)
In-Reply-To: <20210202180612.325099-1-danieller@nvidia.com>

Create a new function for input validations to be called before
rtnl_lock() and move the master slave validation to that function.

This would be a cleanup for next patch that would add another validation
to the new function.

Signed-off-by: Danielle Ratson <danieller@nvidia.com>
---
 net/ethtool/linkmodes.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c
index c5bcb9abc8b9..bb8a3351fb72 100644
--- a/net/ethtool/linkmodes.c
+++ b/net/ethtool/linkmodes.c
@@ -325,6 +325,21 @@ static bool ethnl_validate_master_slave_cfg(u8 cfg)
 	return false;
 }
 
+static int ethnl_check_linkmodes(struct genl_info *info, struct nlattr **tb)
+{
+	const struct nlattr *master_slave_cfg;
+
+	master_slave_cfg = tb[ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG];
+	if (master_slave_cfg &&
+	    !ethnl_validate_master_slave_cfg(nla_get_u8(master_slave_cfg))) {
+		NL_SET_ERR_MSG_ATTR(info->extack, master_slave_cfg,
+				    "master/slave value is invalid");
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
 static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb,
 				  struct ethtool_link_ksettings *ksettings,
 				  bool *mod)
@@ -336,19 +351,11 @@ static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb,
 
 	master_slave_cfg = tb[ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG];
 	if (master_slave_cfg) {
-		u8 cfg = nla_get_u8(master_slave_cfg);
-
 		if (lsettings->master_slave_cfg == MASTER_SLAVE_CFG_UNSUPPORTED) {
 			NL_SET_ERR_MSG_ATTR(info->extack, master_slave_cfg,
 					    "master/slave configuration not supported by device");
 			return -EOPNOTSUPP;
 		}
-
-		if (!ethnl_validate_master_slave_cfg(cfg)) {
-			NL_SET_ERR_MSG_ATTR(info->extack, master_slave_cfg,
-					    "master/slave value is invalid");
-			return -EOPNOTSUPP;
-		}
 	}
 
 	*mod = false;
@@ -386,6 +393,10 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info)
 	bool mod = false;
 	int ret;
 
+	ret = ethnl_check_linkmodes(info, tb);
+	if (ret < 0)
+		return ret;
+
 	ret = ethnl_parse_header_dev_get(&req_info,
 					 tb[ETHTOOL_A_LINKMODES_HEADER],
 					 genl_info_net(info), info->extack,
-- 
2.26.2


  reply	other threads:[~2021-02-02 18:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 18:06 [PATCH net-next v4 0/8] Support setting lanes via ethtool Danielle Ratson
2021-02-02 18:06 ` Danielle Ratson [this message]
2021-02-02 18:06 ` [PATCH net-next v4 2/8] ethtool: Extend link modes settings uAPI with lanes Danielle Ratson
2021-02-02 18:06 ` [PATCH net-next v4 3/8] ethtool: Get link mode in use instead of speed and duplex parameters Danielle Ratson
2021-02-22  9:41   ` Eric Dumazet
2021-02-22 13:11     ` Danielle Ratson
2021-02-22 13:39     ` Andrew Lunn
2021-02-02 18:06 ` [PATCH net-next v4 4/8] ethtool: Expose the number of lanes in use Danielle Ratson
2021-02-02 18:06 ` [PATCH net-next v4 5/8] mlxsw: ethtool: Remove max lanes filtering Danielle Ratson
2021-02-02 18:06 ` [PATCH net-next v4 6/8] mlxsw: ethtool: Add support for setting lanes when autoneg is off Danielle Ratson
2021-02-02 18:06 ` [PATCH net-next v4 7/8] mlxsw: ethtool: Pass link mode in use to ethtool Danielle Ratson
2021-02-02 18:06 ` [PATCH net-next v4 8/8] net: selftests: Add lanes setting test Danielle Ratson
2021-02-02 19:54 ` [PATCH net-next v4 0/8] Support setting lanes via ethtool Edwin Peer
2021-02-04  4:00 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210202180612.325099-2-danieller@nvidia.com \
    --to=danieller@nvidia.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=idosch@nvidia.com \
    --cc=jiri@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=mkubecek@suse.cz \
    --cc=mlxsw@nvidia.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).