linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Veaceslav Falico <vfalico@redhat.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	bhelgaas@google.com
Subject: Re: [PATCH] module: add kset_obj_exists() and use it
Date: Thu, 11 Apr 2013 15:53:40 +0200	[thread overview]
Message-ID: <20130411135340.GF21320@redhat.com> (raw)
In-Reply-To: <20130411132831.GC2909@kroah.com>

On Thu, Apr 11, 2013 at 06:28:31AM -0700, Greg KH wrote:
>On Thu, Apr 11, 2013 at 11:55:37AM +0200, Veaceslav Falico wrote:
>> However, I think my patch still adds something good, cause now we have 2
>> cases where we basically do:
>>
>> k = kset_find_obj();
>> if (!k)
>> 	return;
>> kobject_put(k);
>>
>> which adds useless overhead (by using kobject_get()/kobject_put(), and
>> kobject_release() - which is called from kobject_put()) - where we should
>> only verify if there exists a kobject with the specified name.
>>
>> Should I resend it with a properly fixed commit message, or it's really not
>> needed?
>
>I don't think it's really needed, there is no speed/overhead issue here
>and you need to do the kobject_get/put stuff anyway if you are trying to
>look at a kobject.

This is the point, actually, that we don't need to look at a kobject. We
only need to know if it existed that time or not, here are those two
examples of code:

static int mod_sysfs_init(struct module *mod)
{
         int err;
         struct kobject *kobj;

	...

         kobj = kset_find_obj(module_kset, mod->name);
         if (kobj) {
                 printk(KERN_ERR "%s: module is already loaded\n", mod->name);
                 kobject_put(kobj);
                 err = -EINVAL;
                 goto out;
         }

	...

So we just verify if there's a kobject with mod->name, and if it exists -
_put() it back and return, otherwise do nothing (with it).

Same here:

static char *make_slot_name(const char *name)
{
	...

         for (;;) {
                 struct kobject *dup_slot;
                 dup_slot = kset_find_obj(pci_slots_kset, new_name);
                 if (!dup_slot)
                         break;
                 kobject_put(dup_slot);

	...

We look if there exists a kobject named new_name in pci_slots_kset, if yes
- free it and try another name, if not - then we're good to go.

In both examples we don't look at that kobject, and only uselessly
_get()/_put() it. And it looks a bit ugly. After the patch, in both cases,
it takes only one call to kset_obj_exists() to find out if the object
exists at that time.

However, I have absolutely no knowledge/experience in this domain and might
for sure be missing something. Sorry if it's the case.

>
>thanks,
>
>greg k-h

  reply	other threads:[~2013-04-11 13:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 11:22 [PATCH] module: add kset_obj_exists() and use it Veaceslav Falico
2013-04-10  7:17 ` Rusty Russell
2013-04-11  9:55   ` Veaceslav Falico
2013-04-11 13:28     ` Greg KH
2013-04-11 13:53       ` Veaceslav Falico [this message]
2013-04-11 15:20         ` Greg KH
2013-04-11 15:39           ` Veaceslav Falico
2013-04-15  2:26     ` Rusty Russell
2013-04-16 12:26       ` Veaceslav Falico
2013-04-17  3:55         ` Rusty Russell
2013-04-17  5:33           ` Veaceslav Falico
2013-04-10 17:27 ` Greg KH
2013-04-11  1:58   ` Rusty Russell
2013-04-11  5:05     ` Veaceslav Falico

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=20130411135340.GF21320@redhat.com \
    --to=vfalico@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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;
as well as URLs for NNTP newsgroup(s).