Commit 976d302f authored by Paolo Abeni's avatar Paolo Abeni Committed by David S. Miller

mptcp: deduplicate error paths on endpoint creation

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: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7a7160ed
...@@ -1003,16 +1003,12 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, ...@@ -1003,16 +1003,12 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
return err; return err;
msk = mptcp_sk(entry->lsk->sk); msk = mptcp_sk(entry->lsk->sk);
if (!msk) { if (!msk)
err = -EINVAL; return -EINVAL;
goto out;
}
ssock = __mptcp_nmpc_socket(msk); ssock = __mptcp_nmpc_socket(msk);
if (!ssock) { if (!ssock)
err = -EINVAL; return -EINVAL;
goto out;
}
mptcp_info2sockaddr(&entry->addr, &addr, entry->addr.family); mptcp_info2sockaddr(&entry->addr, &addr, entry->addr.family);
#if IS_ENABLED(CONFIG_MPTCP_IPV6) #if IS_ENABLED(CONFIG_MPTCP_IPV6)
...@@ -1022,20 +1018,16 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, ...@@ -1022,20 +1018,16 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
err = kernel_bind(ssock, (struct sockaddr *)&addr, addrlen); err = kernel_bind(ssock, (struct sockaddr *)&addr, addrlen);
if (err) { if (err) {
pr_warn("kernel_bind error, err=%d", err); pr_warn("kernel_bind error, err=%d", err);
goto out; return err;
} }
err = kernel_listen(ssock, backlog); err = kernel_listen(ssock, backlog);
if (err) { if (err) {
pr_warn("kernel_listen error, err=%d", err); pr_warn("kernel_listen error, err=%d", err);
goto out; return err;
} }
return 0; return 0;
out:
sock_release(entry->lsk);
return err;
} }
int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
...@@ -1327,7 +1319,7 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info) ...@@ -1327,7 +1319,7 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
return -EINVAL; return -EINVAL;
} }
entry = kmalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT); entry = kzalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
if (!entry) { if (!entry) {
GENL_SET_ERR_MSG(info, "can't allocate addr"); GENL_SET_ERR_MSG(info, "can't allocate addr");
return -ENOMEM; return -ENOMEM;
...@@ -1338,22 +1330,21 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info) ...@@ -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); ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
if (ret) { if (ret) {
GENL_SET_ERR_MSG(info, "create listen socket error"); GENL_SET_ERR_MSG(info, "create listen socket error");
kfree(entry); goto out_free;
return ret;
} }
} }
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry); ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
if (ret < 0) { if (ret < 0) {
GENL_SET_ERR_MSG(info, "too many addresses or duplicate one"); GENL_SET_ERR_MSG(info, "too many addresses or duplicate one");
if (entry->lsk) goto out_free;
sock_release(entry->lsk);
kfree(entry);
return ret;
} }
mptcp_nl_add_subflow_or_signal_addr(sock_net(skb->sk)); mptcp_nl_add_subflow_or_signal_addr(sock_net(skb->sk));
return 0; 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, int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment