[PATCH mptcp-next] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm

Geliang Tang posted 1 patch 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/multipath-tcp/mptcp_net-next tags/patchew/3f7656f9232ac4a36017babc0eabf5059c283a63.1734313517.git.tanggeliang@kylinos.cn
There is a newer version of this series
net/mptcp/pm_userspace.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH mptcp-next] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm
Posted by Geliang Tang 2 weeks ago
From: Geliang Tang <tanggeliang@kylinos.cn>

In mptcp_userspace_pm_get_sock(), a more general way to check if
MPTCP_PM_ATTR_TOKEN exists in 'info' is to use

        GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN)

instead of directly reading info->attrs[MPTCP_PM_ATTR_TOKEN] and
then checking if it's NULL.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/pm_userspace.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 740a10d669f8..cc2b7c50d4d6 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -175,14 +175,15 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk,
 
 static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info)
 {
-	struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
 	struct mptcp_sock *msk;
+	struct nlattr *token;
 
-	if (!token) {
+	if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN)) {
 		GENL_SET_ERR_MSG(info, "missing required token");
 		return NULL;
 	}
 
+	token = info->attrs[MPTCP_PM_ATTR_TOKEN];
 	msk = mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token));
 	if (!msk) {
 		NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
-- 
2.45.2