Skip to content

Commit

Permalink
mptcp: deduplicate error paths on endpoint creation
Browse files Browse the repository at this point in the history
When endpoint creation fails, we need to free the newly allocated
entry and eventually destroy the paired mptcp listener socket.

Consolidate such action in a single point let all the errors path
reach it.

Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Paolo Abeni authored and David S. Miller committed Nov 21, 2022
1 parent 7a7160e commit 976d302
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,16 +1003,12 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
return err;

msk = mptcp_sk(entry->lsk->sk);
if (!msk) {
err = -EINVAL;
goto out;
}
if (!msk)
return -EINVAL;

ssock = __mptcp_nmpc_socket(msk);
if (!ssock) {
err = -EINVAL;
goto out;
}
if (!ssock)
return -EINVAL;

mptcp_info2sockaddr(&entry->addr, &addr, entry->addr.family);
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
Expand All @@ -1022,20 +1018,16 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
err = kernel_bind(ssock, (struct sockaddr *)&addr, addrlen);
if (err) {
pr_warn("kernel_bind error, err=%d", err);
goto out;
return err;
}

err = kernel_listen(ssock, backlog);
if (err) {
pr_warn("kernel_listen error, err=%d", err);
goto out;
return err;
}

return 0;

out:
sock_release(entry->lsk);
return err;
}

int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
Expand Down Expand Up @@ -1327,7 +1319,7 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
return -EINVAL;
}

entry = kmalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
entry = kzalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
if (!entry) {
GENL_SET_ERR_MSG(info, "can't allocate addr");
return -ENOMEM;
Expand All @@ -1338,22 +1330,21 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
if (ret) {
GENL_SET_ERR_MSG(info, "create listen socket error");
kfree(entry);
return ret;
goto out_free;
}
}
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
if (ret < 0) {
GENL_SET_ERR_MSG(info, "too many addresses or duplicate one");
if (entry->lsk)
sock_release(entry->lsk);
kfree(entry);
return ret;
goto out_free;
}

mptcp_nl_add_subflow_or_signal_addr(sock_net(skb->sk));

return 0;

out_free:
__mptcp_pm_release_addr_entry(entry);
return ret;
}

int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
Expand Down

0 comments on commit 976d302

Please sign in to comment.