All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Yue Haibing <yuehaibing@huawei.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] lwtunnel: Add lwtunnel_encap_type_check() helper
Date: Wed, 25 Jun 2025 19:52:11 +0100	[thread overview]
Message-ID: <20250625185211.GN1562@horms.kernel.org> (raw)
In-Reply-To: <20250625102413.483743-1-yuehaibing@huawei.com>

On Wed, Jun 25, 2025 at 06:24:13PM +0800, Yue Haibing wrote:
> Consolidate encap_type check to dedicated helper for code clean.
> 
> Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
> ---
>  net/core/lwtunnel.c | 46 ++++++++++++++++++++++-----------------------
>  1 file changed, 22 insertions(+), 24 deletions(-)
> 
> diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c
> index f9d76d85d04f..f9453f278715 100644
> --- a/net/core/lwtunnel.c
> +++ b/net/core/lwtunnel.c
> @@ -79,10 +79,18 @@ EXPORT_SYMBOL_GPL(lwtunnel_state_alloc);
>  static const struct lwtunnel_encap_ops __rcu *
>  		lwtun_encaps[LWTUNNEL_ENCAP_MAX + 1] __read_mostly;
>  
> +static inline int lwtunnel_encap_type_check(unsigned int encap_type)

Please don't use the inline keyword in .c files unless there
is a demonstratable - usually performance - reason to do so.
Which I don't think that is hte case here.

Rather, let the compiler inine functions as it sees fit.

> +{
> +	if (encap_type == LWTUNNEL_ENCAP_NONE ||
> +	    encap_type > LWTUNNEL_ENCAP_MAX)
> +		return -EINVAL;
> +	return 0;
> +}
> +

I'm not entirely sure if this change is worth the churn.
But if it is, perhaps a helper of the following form is simpler.

(Completely untested!)

static bool lwtunnel_encap_type_invalid(unsigned int encap_type)
{
	return encap_type == LWTUNNEL_ENCAP_NONE ||
	       encap_type > LWTUNNEL_ENCAP_MAX;
}


>  int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *ops,
>  			   unsigned int num)
>  {
> -	if (num > LWTUNNEL_ENCAP_MAX)
> +	if (lwtunnel_encap_type_check(num) < 0)

Which can then be used like this:

	if (lwtunnel_encap_type_invalid(num))

>  		return -ERANGE;
>  
>  	return !cmpxchg((const struct lwtunnel_encap_ops **)

...

-- 
pw-bot: changes-requested

      reply	other threads:[~2025-06-25 18:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-25 10:24 [PATCH net-next] lwtunnel: Add lwtunnel_encap_type_check() helper Yue Haibing
2025-06-25 18:52 ` Simon Horman [this message]

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=20250625185211.GN1562@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=yuehaibing@huawei.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.