lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250625185211.GN1562@horms.kernel.org>
Date: Wed, 25 Jun 2025 19:52:11 +0100
From: Simon Horman <horms@...nel.org>
To: Yue Haibing <yuehaibing@...wei.com>
Cc: davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
	pabeni@...hat.com, netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next] lwtunnel: Add lwtunnel_encap_type_check() helper

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@...wei.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ