diff mbox series

[v7,4/5] mptcp: remove some double-check

Message ID 1625048653-6825-5-git-send-email-liyonglong@chinatelecom.cn (mailing list archive)
State Superseded, archived
Headers show
Series mptcp: fix conflicts when using pm.add_signal in ADD_ADDR/echo and RM_ADDR process | expand

Commit Message

YonglongLi June 30, 2021, 10:24 a.m. UTC
remove some double-check in mptcp_established_options_add_addr() and
mptcp_established_options_rm_addr()

Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
---
 net/mptcp/options.c  | 14 ++------------
 net/mptcp/pm.c       | 21 +++++++++++----------
 net/mptcp/protocol.h |  4 ++--
 3 files changed, 15 insertions(+), 24 deletions(-)

Comments

Geliang Tang June 30, 2021, 10:57 a.m. UTC | #1
As I said in v6, I prefer to keep these double check code, no need to
remove them.

Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:
>
> remove some double-check in mptcp_established_options_add_addr() and
> mptcp_established_options_rm_addr()
>
> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
> ---
>  net/mptcp/options.c  | 14 ++------------
>  net/mptcp/pm.c       | 21 +++++++++++----------
>  net/mptcp/protocol.h |  4 ++--
>  3 files changed, 15 insertions(+), 24 deletions(-)
>
> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> index cceff0a..0711fc1 100644
> --- a/net/mptcp/options.c
> +++ b/net/mptcp/options.c
> @@ -659,7 +659,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>         int len = 0;
>
>         if (!mptcp_pm_should_add_signal(msk) ||
> -           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
> +           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr, &len))
>                 return false;
>
>         if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
> @@ -674,10 +674,6 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>                 drop_other_suboptions = true;
>         }
>
> -       len = mptcp_add_addr_len(msk, opts);
> -       if (remaining < len)
> -               return false;
> -
>         *size = len;
>         if (drop_other_suboptions)
>                 *size -= opt_size;
> @@ -707,13 +703,7 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
>         int i, len;
>
>         if (!mptcp_pm_should_rm_signal(msk) ||
> -           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
> -               return false;
> -
> -       len = mptcp_rm_addr_len(&rm_list);
> -       if (len < 0)
> -               return false;
> -       if (remaining < len)
> +           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, &len)))
>                 return false;
>
>         *size = len;
> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> index 9c5b15c..2311ea5 100644
> --- a/net/mptcp/pm.c
> +++ b/net/mptcp/pm.c
> @@ -255,9 +255,9 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
>
>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>                               unsigned int opt_size, unsigned int remaining,
> -                             struct mptcp_out_options *opts,  u8 *add_addr)
> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len)
>  {
> -       int ret = false, len;
> +       int ret = false;
>
>         spin_lock_bh(&msk->pm.lock);
>
> @@ -276,8 +276,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>                 remaining += opt_size;
>         }
>
> -       len = mptcp_add_addr_len(msk, opts);
> -       if (remaining < len)
> +       *len = mptcp_add_addr_len(msk, opts);
> +       if (remaining < *len)
>                 goto out_unlock;
>
>         if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
> @@ -287,17 +287,18 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>
>         ret = true;
>  out_unlock:
> +       spin_unlock_bh(&msk->pm.lock);
> +
>         if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
>                 mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
>
> -       spin_unlock_bh(&msk->pm.lock);
>         return ret;
>  }
>
>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> -                            struct mptcp_rm_list *rm_list)
> +                            struct mptcp_rm_list *rm_list, int *len)
>  {
> -       int ret = false, len;
> +       int ret = false;
>         u8 rm_addr;
>
>         spin_lock_bh(&msk->pm.lock);
> @@ -307,12 +308,12 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>                 goto out_unlock;
>
>         rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
> -       len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
> -       if (len < 0) {
> +       *len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
> +       if (*len < 0) {
>                 WRITE_ONCE(msk->pm.addr_signal, rm_addr);
>                 goto out_unlock;
>         }
> -       if (remaining < len)
> +       if (remaining < *len)
>                 goto out_unlock;
>
>         *rm_list = msk->pm.rm_list_tx;
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index caa4a60..5d7c9d7 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -770,9 +770,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
>
>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>                               unsigned int opt_size, unsigned int remaining,
> -                             struct mptcp_out_options *opts,  u8 *add_addr);
> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len);
>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> -                            struct mptcp_rm_list *rm_list);
> +                            struct mptcp_rm_list *rm_list, int *len);
>  int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
>
>  void __init mptcp_pm_nl_init(void);
> --
> 1.8.3.1
>
>
YonglongLi July 2, 2021, 6:22 a.m. UTC | #2
Hi Geliang,

I think these double check is unnecessary. the reason to keep them is?
I think keep "!mptcp_pm_should_add_signal(msk)" you said in v6 is reasonable,
It can avoid to get pm.lock in process of sending packets. But the other double
check is useless.

On 2021/6/30 18:57, Geliang Tang wrote:
> As I said in v6, I prefer to keep these double check code, no need to
> remove them.
> 
> Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:
>>
>> remove some double-check in mptcp_established_options_add_addr() and
>> mptcp_established_options_rm_addr()
>>
>> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
>> ---
>>  net/mptcp/options.c  | 14 ++------------
>>  net/mptcp/pm.c       | 21 +++++++++++----------
>>  net/mptcp/protocol.h |  4 ++--
>>  3 files changed, 15 insertions(+), 24 deletions(-)
>>
>> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
>> index cceff0a..0711fc1 100644
>> --- a/net/mptcp/options.c
>> +++ b/net/mptcp/options.c
>> @@ -659,7 +659,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>>         int len = 0;
>>
>>         if (!mptcp_pm_should_add_signal(msk) ||
>> -           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
>> +           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr, &len))
>>                 return false;
>>
>>         if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
>> @@ -674,10 +674,6 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>>                 drop_other_suboptions = true;
>>         }
>>
>> -       len = mptcp_add_addr_len(msk, opts);
>> -       if (remaining < len)
>> -               return false;
>> -
>>         *size = len;
>>         if (drop_other_suboptions)
>>                 *size -= opt_size;
>> @@ -707,13 +703,7 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
>>         int i, len;
>>
>>         if (!mptcp_pm_should_rm_signal(msk) ||
>> -           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
>> -               return false;
>> -
>> -       len = mptcp_rm_addr_len(&rm_list);
>> -       if (len < 0)
>> -               return false;
>> -       if (remaining < len)
>> +           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, &len)))
>>                 return false;
>>
>>         *size = len;
>> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
>> index 9c5b15c..2311ea5 100644
>> --- a/net/mptcp/pm.c
>> +++ b/net/mptcp/pm.c
>> @@ -255,9 +255,9 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
>>
>>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>>                               unsigned int opt_size, unsigned int remaining,
>> -                             struct mptcp_out_options *opts,  u8 *add_addr)
>> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len)
>>  {
>> -       int ret = false, len;
>> +       int ret = false;
>>
>>         spin_lock_bh(&msk->pm.lock);
>>
>> @@ -276,8 +276,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>>                 remaining += opt_size;
>>         }
>>
>> -       len = mptcp_add_addr_len(msk, opts);
>> -       if (remaining < len)
>> +       *len = mptcp_add_addr_len(msk, opts);
>> +       if (remaining < *len)
>>                 goto out_unlock;
>>
>>         if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
>> @@ -287,17 +287,18 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>>
>>         ret = true;
>>  out_unlock:
>> +       spin_unlock_bh(&msk->pm.lock);
>> +
>>         if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
>>                 mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
>>
>> -       spin_unlock_bh(&msk->pm.lock);
>>         return ret;
>>  }
>>
>>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>> -                            struct mptcp_rm_list *rm_list)
>> +                            struct mptcp_rm_list *rm_list, int *len)
>>  {
>> -       int ret = false, len;
>> +       int ret = false;
>>         u8 rm_addr;
>>
>>         spin_lock_bh(&msk->pm.lock);
>> @@ -307,12 +308,12 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>>                 goto out_unlock;
>>
>>         rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
>> -       len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
>> -       if (len < 0) {
>> +       *len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
>> +       if (*len < 0) {
>>                 WRITE_ONCE(msk->pm.addr_signal, rm_addr);
>>                 goto out_unlock;
>>         }
>> -       if (remaining < len)
>> +       if (remaining < *len)
>>                 goto out_unlock;
>>
>>         *rm_list = msk->pm.rm_list_tx;
>> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
>> index caa4a60..5d7c9d7 100644
>> --- a/net/mptcp/protocol.h
>> +++ b/net/mptcp/protocol.h
>> @@ -770,9 +770,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
>>
>>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>>                               unsigned int opt_size, unsigned int remaining,
>> -                             struct mptcp_out_options *opts,  u8 *add_addr);
>> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len);
>>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>> -                            struct mptcp_rm_list *rm_list);
>> +                            struct mptcp_rm_list *rm_list, int *len);
>>  int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
>>
>>  void __init mptcp_pm_nl_init(void);
>> --
>> 1.8.3.1
>>
>>
>
Geliang Tang July 2, 2021, 8:06 a.m. UTC | #3
Yonglong Li <liyonglong@chinatelecom.cn> 于2021年7月2日周五 下午2:22写道:
>
> Hi Geliang,
>
> I think these double check is unnecessary. the reason to keep them is?
> I think keep "!mptcp_pm_should_add_signal(msk)" you said in v6 is reasonable,
> It can avoid to get pm.lock in process of sending packets. But the other double
> check is useless.

The length re-check is for the no-spin-lock optimization too.

These code is no harm for yours, why can't you keep it there. :)

-Geliang


>
> On 2021/6/30 18:57, Geliang Tang wrote:
> > As I said in v6, I prefer to keep these double check code, no need to
> > remove them.
> >
> > Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:
> >>
> >> remove some double-check in mptcp_established_options_add_addr() and
> >> mptcp_established_options_rm_addr()
> >>
> >> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
> >> ---
> >>  net/mptcp/options.c  | 14 ++------------
> >>  net/mptcp/pm.c       | 21 +++++++++++----------
> >>  net/mptcp/protocol.h |  4 ++--
> >>  3 files changed, 15 insertions(+), 24 deletions(-)
> >>
> >> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> >> index cceff0a..0711fc1 100644
> >> --- a/net/mptcp/options.c
> >> +++ b/net/mptcp/options.c
> >> @@ -659,7 +659,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
> >>         int len = 0;
> >>
> >>         if (!mptcp_pm_should_add_signal(msk) ||
> >> -           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
> >> +           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr, &len))
> >>                 return false;
> >>
> >>         if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
> >> @@ -674,10 +674,6 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
> >>                 drop_other_suboptions = true;
> >>         }
> >>
> >> -       len = mptcp_add_addr_len(msk, opts);
> >> -       if (remaining < len)
> >> -               return false;
> >> -
> >>         *size = len;
> >>         if (drop_other_suboptions)
> >>                 *size -= opt_size;
> >> @@ -707,13 +703,7 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
> >>         int i, len;
> >>
> >>         if (!mptcp_pm_should_rm_signal(msk) ||
> >> -           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
> >> -               return false;
> >> -
> >> -       len = mptcp_rm_addr_len(&rm_list);
> >> -       if (len < 0)
> >> -               return false;
> >> -       if (remaining < len)
> >> +           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, &len)))
> >>                 return false;
> >>
> >>         *size = len;
> >> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> >> index 9c5b15c..2311ea5 100644
> >> --- a/net/mptcp/pm.c
> >> +++ b/net/mptcp/pm.c
> >> @@ -255,9 +255,9 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
> >>
> >>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> >>                               unsigned int opt_size, unsigned int remaining,
> >> -                             struct mptcp_out_options *opts,  u8 *add_addr)
> >> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len)
> >>  {
> >> -       int ret = false, len;
> >> +       int ret = false;
> >>
> >>         spin_lock_bh(&msk->pm.lock);
> >>
> >> @@ -276,8 +276,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> >>                 remaining += opt_size;
> >>         }
> >>
> >> -       len = mptcp_add_addr_len(msk, opts);
> >> -       if (remaining < len)
> >> +       *len = mptcp_add_addr_len(msk, opts);
> >> +       if (remaining < *len)
> >>                 goto out_unlock;
> >>
> >>         if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
> >> @@ -287,17 +287,18 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> >>
> >>         ret = true;
> >>  out_unlock:
> >> +       spin_unlock_bh(&msk->pm.lock);
> >> +
> >>         if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
> >>                 mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
> >>
> >> -       spin_unlock_bh(&msk->pm.lock);
> >>         return ret;
> >>  }
> >>
> >>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> >> -                            struct mptcp_rm_list *rm_list)
> >> +                            struct mptcp_rm_list *rm_list, int *len)
> >>  {
> >> -       int ret = false, len;
> >> +       int ret = false;
> >>         u8 rm_addr;
> >>
> >>         spin_lock_bh(&msk->pm.lock);
> >> @@ -307,12 +308,12 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> >>                 goto out_unlock;
> >>
> >>         rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
> >> -       len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
> >> -       if (len < 0) {
> >> +       *len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
> >> +       if (*len < 0) {
> >>                 WRITE_ONCE(msk->pm.addr_signal, rm_addr);
> >>                 goto out_unlock;
> >>         }
> >> -       if (remaining < len)
> >> +       if (remaining < *len)
> >>                 goto out_unlock;
> >>
> >>         *rm_list = msk->pm.rm_list_tx;
> >> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> >> index caa4a60..5d7c9d7 100644
> >> --- a/net/mptcp/protocol.h
> >> +++ b/net/mptcp/protocol.h
> >> @@ -770,9 +770,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
> >>
> >>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> >>                               unsigned int opt_size, unsigned int remaining,
> >> -                             struct mptcp_out_options *opts,  u8 *add_addr);
> >> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len);
> >>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> >> -                            struct mptcp_rm_list *rm_list);
> >> +                            struct mptcp_rm_list *rm_list, int *len);
> >>  int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
> >>
> >>  void __init mptcp_pm_nl_init(void);
> >> --
> >> 1.8.3.1
> >>
> >>
> >
>
> --
> Li YongLong
diff mbox series

Patch

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index cceff0a..0711fc1 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -659,7 +659,7 @@  static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 	int len = 0;
 
 	if (!mptcp_pm_should_add_signal(msk) ||
-	    !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
+	    !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr, &len))
 		return false;
 
 	if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
@@ -674,10 +674,6 @@  static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 		drop_other_suboptions = true;
 	}
 
-	len = mptcp_add_addr_len(msk, opts);
-	if (remaining < len)
-		return false;
-
 	*size = len;
 	if (drop_other_suboptions)
 		*size -= opt_size;
@@ -707,13 +703,7 @@  static bool mptcp_established_options_rm_addr(struct sock *sk,
 	int i, len;
 
 	if (!mptcp_pm_should_rm_signal(msk) ||
-	    !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
-		return false;
-
-	len = mptcp_rm_addr_len(&rm_list);
-	if (len < 0)
-		return false;
-	if (remaining < len)
+	    !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, &len)))
 		return false;
 
 	*size = len;
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 9c5b15c..2311ea5 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -255,9 +255,9 @@  void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
 
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
 			      unsigned int opt_size, unsigned int remaining,
-			      struct mptcp_out_options *opts,  u8 *add_addr)
+			      struct mptcp_out_options *opts,  u8 *add_addr, int *len)
 {
-	int ret = false, len;
+	int ret = false;
 
 	spin_lock_bh(&msk->pm.lock);
 
@@ -276,8 +276,8 @@  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
 		remaining += opt_size;
 	}
 
-	len = mptcp_add_addr_len(msk, opts);
-	if (remaining < len)
+	*len = mptcp_add_addr_len(msk, opts);
+	if (remaining < *len)
 		goto out_unlock;
 
 	if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
@@ -287,17 +287,18 @@  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
 
 	ret = true;
 out_unlock:
+	spin_unlock_bh(&msk->pm.lock);
+
 	if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
 		mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
 
-	spin_unlock_bh(&msk->pm.lock);
 	return ret;
 }
 
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			     struct mptcp_rm_list *rm_list)
+			     struct mptcp_rm_list *rm_list, int *len)
 {
-	int ret = false, len;
+	int ret = false;
 	u8 rm_addr;
 
 	spin_lock_bh(&msk->pm.lock);
@@ -307,12 +308,12 @@  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 		goto out_unlock;
 
 	rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
-	len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
-	if (len < 0) {
+	*len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
+	if (*len < 0) {
 		WRITE_ONCE(msk->pm.addr_signal, rm_addr);
 		goto out_unlock;
 	}
-	if (remaining < len)
+	if (remaining < *len)
 		goto out_unlock;
 
 	*rm_list = msk->pm.rm_list_tx;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index caa4a60..5d7c9d7 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -770,9 +770,9 @@  static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
 
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
 			      unsigned int opt_size, unsigned int remaining,
-			      struct mptcp_out_options *opts,  u8 *add_addr);
+			      struct mptcp_out_options *opts,  u8 *add_addr, int *len);
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			     struct mptcp_rm_list *rm_list);
+			     struct mptcp_rm_list *rm_list, int *len);
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 
 void __init mptcp_pm_nl_init(void);