mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: wuchi <wuchi.zero@gmail.com>
Cc: rafael@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/kobject: Simplify checking of parameters in kobj_ns_type_register.
Date: Fri, 17 Jun 2022 10:49:43 +0200	[thread overview]
Message-ID: <YqxAJ0JiN7V1uekr@kroah.com> (raw)
In-Reply-To: <20220617083832.85287-1-wuchi.zero@gmail.com>

On Fri, Jun 17, 2022 at 04:38:32PM +0800, wuchi wrote:
> 1. Merge checking of following code:
>     if (type >= KOBJ_NS_TYPES)
>     ...
>     if (type <= KOBJ_NS_TYPE_NONE)

Why?

> 2. Move the checking of parameters out of critical section, there is
> no need to check that with spinlock.

Why does it matter?


> 
> Signed-off-by: wuchi <wuchi.zero@gmail.com>
> ---
>  lib/kobject.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/kobject.c b/lib/kobject.c
> index 5f0e71ab292c..6a8b009682b8 100644
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -996,19 +996,13 @@ static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
>  int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
>  {
>  	enum kobj_ns_type type = ops->type;
> -	int error;
> -
> -	spin_lock(&kobj_ns_type_lock);
> +	int error = -EBUSY;
>  
> -	error = -EINVAL;
> -	if (type >= KOBJ_NS_TYPES)
> -		goto out;
> +	if (unlikely(type >= KOBJ_NS_TYPES || type <= KOBJ_NS_TYPE_NONE))

Why add unlikely?  Did you measure the performance benifit?  If not,
please never add likely/unlikely.

> +		return -EINVAL;
>  
> -	error = -EINVAL;
> -	if (type <= KOBJ_NS_TYPE_NONE)
> -		goto out;
> +	spin_lock(&kobj_ns_type_lock);
>  
> -	error = -EBUSY;


How did you test this?  What is the benefit?

thanks,

greg k-h

  reply	other threads:[~2022-06-17  8:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17  8:38 wuchi
2022-06-17  8:49 ` Greg KH [this message]
2022-06-17  9:55   ` chi wu

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=YqxAJ0JiN7V1uekr@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=wuchi.zero@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®