Skip to content

Commit

Permalink
mptcp: define more local variables sk
Browse files Browse the repository at this point in the history
'(struct sock *)msk' is used several times in mptcp_nl_cmd_announce(),
mptcp_nl_cmd_remove() or mptcp_userspace_pm_set_flags() in pm_userspace.c,
it's worth adding a local variable sk to point it.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
geliangtang authored and intel-lab-lkp committed Sep 16, 2023
1 parent 3eddd64 commit 3241fef
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
struct mptcp_pm_addr_entry addr_val;
struct mptcp_sock *msk;
int err = -EINVAL;
struct sock *sk;
u32 token_val;

if (!addr || !token) {
Expand All @@ -167,6 +168,8 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
return err;
}

sk = (struct sock *)msk;

if (!mptcp_pm_is_userspace(msk)) {
GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected");
goto announce_err;
Expand All @@ -190,7 +193,7 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
goto announce_err;
}

lock_sock((struct sock *)msk);
lock_sock(sk);
spin_lock_bh(&msk->pm.lock);

if (mptcp_pm_alloc_anno_list(msk, &addr_val.addr)) {
Expand All @@ -200,11 +203,11 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
}

spin_unlock_bh(&msk->pm.lock);
release_sock((struct sock *)msk);
release_sock(sk);

err = 0;
announce_err:
sock_put((struct sock *)msk);
sock_put(sk);
return err;
}

Expand All @@ -217,6 +220,7 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info)
struct mptcp_sock *msk;
LIST_HEAD(free_list);
int err = -EINVAL;
struct sock *sk;
u32 token_val;
u8 id_val;

Expand All @@ -234,12 +238,14 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info)
return err;
}

sk = (struct sock *)msk;

if (!mptcp_pm_is_userspace(msk)) {
GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected");
goto remove_err;
}

lock_sock((struct sock *)msk);
lock_sock(sk);

list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) {
if (entry->addr.id == id_val) {
Expand All @@ -250,23 +256,23 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info)

if (!match) {
GENL_SET_ERR_MSG(info, "address with specified id not found");
release_sock((struct sock *)msk);
release_sock(sk);
goto remove_err;
}

list_move(&match->list, &free_list);

mptcp_pm_remove_addrs(msk, &free_list);

release_sock((struct sock *)msk);
release_sock(sk);

list_for_each_entry_safe(match, entry, &free_list, list) {
sock_kfree_s((struct sock *)msk, match, sizeof(*match));
sock_kfree_s(sk, match, sizeof(*match));
}

err = 0;
remove_err:
sock_put((struct sock *)msk);
sock_put(sk);
return err;
}

Expand Down Expand Up @@ -485,6 +491,7 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token,
{
struct mptcp_sock *msk;
int ret = -EINVAL;
struct sock *sk;
u32 token_val;

token_val = nla_get_u32(token);
Expand All @@ -493,18 +500,20 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token,
if (!msk)
return ret;

sk = (struct sock *)msk;

if (!mptcp_pm_is_userspace(msk))
goto set_flags_err;

if (loc->addr.family == AF_UNSPEC ||
rem->addr.family == AF_UNSPEC)
goto set_flags_err;

lock_sock((struct sock *)msk);
lock_sock(sk);
ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, &rem->addr, bkup);
release_sock((struct sock *)msk);
release_sock(sk);

set_flags_err:
sock_put((struct sock *)msk);
sock_put(sk);
return ret;
}

0 comments on commit 3241fef

Please sign in to comment.