All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geliang Tang <geliang@kernel.org>
To: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>, mptcp@lists.linux.dev
Cc: Paolo Abeni <pabeni@redhat.com>
Subject: Re: [PATCH mptcp-net v2 3/3] mptcp: pm: avoid code duplication to lookup endp
Date: Fri, 25 Oct 2024 18:47:17 +0800	[thread overview]
Message-ID: <7e60e4ce41620c58c79c916d3480d2cf46f82834.camel@kernel.org> (raw)
In-Reply-To: <42e959952d1a9a15e19e51bd17b129d1938364c5.camel@kernel.org>

On Fri, 2024-10-25 at 18:37 +0800, Geliang Tang wrote:
> Hi Matt,
> 
> Thanks for this patch.
> 
> On Fri, 2024-10-25 at 11:32 +0200, Matthieu Baerts (NGI0) wrote:
> > From: Geliang Tang <tanggeliang@kylinos.cn>
> > 
> > The helper __lookup_addr_rcu() can be used in
> > mptcp_pm_nl_get_local_id()
> > and mptcp_pm_nl_is_backup() to simplify the code, and avoid code
> > duplication.
> > 
> > Co-developed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> > Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > ---
> > Notes:
> >  - This is also for -next.
> > ---
> >  net/mptcp/pm_netlink.c | 20 ++++++--------------
> >  1 file changed, 6 insertions(+), 14 deletions(-)
> > 
> > diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
> > index
> > f38e1ccd34e95cd88b179a8b50e6965731542871..7c6e664b236d1659a554d003c
> > 78
> > c72ec91895ba5 100644
> > --- a/net/mptcp/pm_netlink.c
> > +++ b/net/mptcp/pm_netlink.c
> > @@ -1154,17 +1154,13 @@ int mptcp_pm_nl_get_local_id(struct
> > mptcp_sock *msk, struct mptcp_addr_info *skc
> >  {
> >  	struct mptcp_pm_addr_entry *entry;
> >  	struct pm_nl_pernet *pernet;
> > -	int ret = -1;
> > +	int ret;
> >  
> >  	pernet = pm_nl_get_pernet_from_msk(msk);
> >  
> >  	rcu_read_lock();
> > -	list_for_each_entry_rcu(entry, &pernet->local_addr_list,
> > list) {
> > -		if (mptcp_addresses_equal(&entry->addr, skc,
> > entry-
> > > addr.port)) {
> > -			ret = entry->addr.id;
> > -			break;
> > -		}
> > -	}
> > +	entry = __lookup_addr_rcu(pernet, skc);
> > +	ret = entry ? entry->addr.id : -1;
> >  	rcu_read_unlock();
> >  	if (ret >= 0)
> >  		return ret;
> > @@ -1191,15 +1187,11 @@ bool mptcp_pm_nl_is_backup(struct
> > mptcp_sock
> > *msk, struct mptcp_addr_info *skc)
> >  {
> >  	struct pm_nl_pernet *pernet =
> > pm_nl_get_pernet_from_msk(msk);
> >  	struct mptcp_pm_addr_entry *entry;
> > -	bool backup = false;
> > +	bool backup;
> >  
> >  	rcu_read_lock();
> > -	list_for_each_entry_rcu(entry, &pernet->local_addr_list,
> > list) {
> > -		if (mptcp_addresses_equal(&entry->addr, skc,
> > entry-
> > > addr.port)) {
> > -			backup = !!(entry->flags &
> > MPTCP_PM_ADDR_FLAG_BACKUP);
> > -			break;
> > -		}
> > -	}
> > +	entry = __lookup_addr_rcu(pernet, skc);
> > +	backup = entry && !!(entry->flags &
> > MPTCP_PM_ADDR_FLAG_BACKUP);
> 
> I think we should check whether entry is NULL here too. No?

Sorry, ignore my comment, your code is correct. :)

-Geliang

> 
> -Geliang
> 
> >  	rcu_read_unlock();
> >  
> >  	return backup;
> > 
> 
> 


  parent reply	other threads:[~2024-10-25 10:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25  9:32 [PATCH mptcp-net v2 0/3] mptcp: pm: use _rcu variant under rcu_read_lock Matthieu Baerts (NGI0)
2024-10-25  9:32 ` [PATCH mptcp-net v2 1/3] " Matthieu Baerts (NGI0)
2024-10-25  9:32 ` [PATCH mptcp-net v2 2/3] mptcp: pm: lockless list traversal Matthieu Baerts (NGI0)
2024-10-25 14:25   ` Geliang Tang
2024-10-25 15:26     ` Matthieu Baerts
2024-10-28  2:08       ` Geliang Tang
2024-10-28 11:48         ` Matthieu Baerts
2024-10-29  8:43           ` Geliang Tang
2024-10-31 23:24             ` Mat Martineau
2024-11-06 16:03               ` Matthieu Baerts
2024-10-25 15:17   ` Matthieu Baerts
2024-10-31 22:14     ` Mat Martineau
2024-11-05 18:21   ` Paolo Abeni
2024-11-06 16:23     ` Matthieu Baerts
2024-10-25  9:32 ` [PATCH mptcp-net v2 3/3] mptcp: pm: avoid code duplication to lookup endp Matthieu Baerts (NGI0)
2024-10-25 10:37   ` Geliang Tang
2024-10-25 10:44     ` Matthieu Baerts
2024-10-25 10:47     ` Geliang Tang [this message]
2024-10-25 10:49 ` [PATCH mptcp-net v2 0/3] mptcp: pm: use _rcu variant under rcu_read_lock MPTCP CI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7e60e4ce41620c58c79c916d3480d2cf46f82834.camel@kernel.org \
    --to=geliang@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.