public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>,
	Greg KH <greg@kroah.com>,
	Kernel development list <linux-kernel@vger.kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Randy Dunlap <randy.dunlap@oracle.com>
Subject: Re: [PATCH] kobject: make sure kobj->ktype is set before kobject_init
Date: Thu, 29 Nov 2007 21:19:57 +0100	[thread overview]
Message-ID: <1196367597.7903.25.camel@lov.site> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0711291455410.5666-100000@iolanthe.rowland.org>

On Thu, 2007-11-29 at 15:09 -0500, Alan Stern wrote:
> On Thu, 29 Nov 2007, Kay Sievers wrote:
> 
> > > My conclusion is different.  We should make kobject_init() not consume
> > > any resources at all; just initialize various fields.  That way it
> > > would be okay to call either kfree() or kobject_put() on an initialized
> > > kobject.  And then when something like device_register() fails, the
> > > caller would know the proper thing to do would be to call the put()  
> > > routine, always.
> > > 
> > > Of course, once the name has been assigned, only kobject_put() should
> > > be used.
> > 
> > Now we just move the exactly the same problem from _init() to
> > _set_name(). To free the name of an unregistered we would need to call
> > _put() which free()'s the whole object again. :) 
> 
> I don't see that as a problem and it's not clear why you do.
> 
> It doesn't matter whether a kobject has been registered or not; once
> it has been initialized you _should_ call kobject_put().  (Although
> it's okay to call kfree() if the name hasn't been set yet.)

I just say, it's exactly the same problem and it does not really make a
difference that kobject_init() does not do anything, if we require
another function to be called before we can call kobject_add(). A
kobject without a name will not be valid, and we will need a way for an
easy cleanup of allocated resources I think.

> The same is true of larger objects.  Once you have called
> device_initialize(), you _should_ call device_put() (although it's okay
> to call kfree()).  Provided init routines don't consume resources, this
> will work.
> 
> The only remaining problem is that somebody might set the name first
> and then decide to abandon the object before calling kobject_init().  
> However this probably never happens anywhere.

What is the whole point of kobject_init() then? You can just do the same
stuff in kobject_add() if you require not to allocate anything there. 

None of the initialized fields can be used before we have called
kobject_add(), right?

> > > There's another good reason for not assigning the name in
> > > kobject_init(): Code that uses kobjects (like the driver core) doesn't
> > > set the name until later.
> > 
> > That can be done at any stage, I guess. We will rip out the name in the
> > struct device anyway.
> 
> Are you also going to change all the places in the kernel where the
> device name (.bus_id) isn't set until after device_initialize() has
> been called?

Yes, I already have a patch that does that for all stuff that was needed
on my boxes.

Kay


  reply	other threads:[~2007-11-29 20:20 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-27 23:02 [RFC] New kobject/kset/ktype documentation and example code Greg KH
2007-11-27 23:03 ` [RFC] sample kobject implementation Greg KH
2007-11-27 23:04 ` [RFC] Sample kset/ktype/kobject implementation Greg KH
2007-11-28 16:35   ` Cornelia Huck
2007-11-29  6:11     ` Greg KH
2007-11-29  9:39       ` Cornelia Huck
2007-11-29 20:39         ` Greg KH
2007-11-29 22:11           ` Alan Stern
2007-11-30  5:07             ` Dave Young
2007-11-30  5:57               ` Dave Young
2007-11-30 14:51               ` Alan Stern
2007-11-30  6:41             ` Greg KH
2007-11-27 23:10 ` [RFC] New kobject/kset/ktype documentation and example code Kyle McMartin
2007-11-27 23:29   ` Greg KH
2007-11-27 23:21 ` Frans Pop
2007-11-28  3:50 ` Jonathan Corbet
2007-11-29  5:46   ` Greg KH
2007-11-28  9:01 ` Cornelia Huck
2007-11-28 12:35   ` Kay Sievers
2007-11-28 15:52     ` Cornelia Huck
2007-11-28 16:03       ` Kay Sievers
2007-11-28 16:09         ` Cornelia Huck
2007-11-28 17:06           ` Greg KH
2007-11-28 19:18   ` Alan Stern
2007-11-29 10:12     ` Cornelia Huck
2007-11-29 15:47       ` Alan Stern
2007-11-29 16:28         ` Cornelia Huck
2007-11-29 16:55           ` Alan Stern
2007-11-29 17:52             ` Cornelia Huck
2007-11-29  5:59   ` Greg KH
2007-11-28 11:45 ` Cornelia Huck
2007-11-28 12:23   ` Kay Sievers
2007-11-28 15:48     ` Cornelia Huck
2007-11-28 15:57       ` Kay Sievers
2007-11-28 16:12         ` Cornelia Huck
2007-11-28 16:36           ` Kay Sievers
2007-11-28 16:51             ` Cornelia Huck
2007-11-28 17:00               ` Kay Sievers
2007-11-29  6:08                 ` Greg KH
2007-11-29  7:50                   ` Kay Sievers
2007-11-29  9:35                     ` Cornelia Huck
2007-11-29 10:53                       ` Kay Sievers
2007-11-29  6:02     ` Greg KH
2007-11-29  6:04   ` Greg KH
2007-11-29  9:41     ` Cornelia Huck
2007-11-28 19:03 ` Alan Stern
2007-11-28 19:28   ` Kay Sievers
2007-11-28 19:36     ` Alan Stern
2007-11-28 19:46       ` Kay Sievers
2007-11-28 20:42         ` [PATCH] kobject: make sure kobj->ktype is set before kobject_init Alan Stern
2007-11-28 20:52           ` Kay Sievers
2007-11-28 21:45           ` Greg KH
2007-11-28 22:00             ` Alan Stern
2007-11-28 22:38               ` Greg KH
2007-11-29 10:05               ` Cornelia Huck
2007-11-29 10:59                 ` Kay Sievers
2007-11-29 11:48                   ` Cornelia Huck
2007-11-29 15:54                   ` Alan Stern
2007-11-29 16:04                     ` Kay Sievers
2007-11-29 16:21                       ` Cornelia Huck
2007-11-29 21:53                         ` kobject_init rewrite Greg KH
2007-11-29 21:54                           ` Greg KH
2007-11-30  9:31                             ` Cornelia Huck
2007-11-29 22:16                           ` Alan Stern
2007-11-29 22:24                             ` Greg KH
2007-11-29 17:06                       ` [PATCH] kobject: make sure kobj->ktype is set before kobject_init Alan Stern
2007-11-29 17:17                         ` Kay Sievers
2007-11-29 18:04                           ` Alan Stern
2007-11-29 18:33                             ` Kay Sievers
2007-11-29 19:05                               ` Alan Stern
2007-11-29 19:51                                 ` Kay Sievers
2007-11-29 20:09                                   ` Alan Stern
2007-11-29 20:19                                     ` Kay Sievers [this message]
2007-11-29 20:26                                       ` Kay Sievers
2007-11-30  9:30                                         ` Cornelia Huck
2007-11-29  6:18   ` [RFC] New kobject/kset/ktype documentation and example code Greg KH
2007-11-29 15:42     ` Alan Stern

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=1196367597.7903.25.camel@lov.site \
    --to=kay.sievers@vrfy.org \
    --cc=corbet@lwn.net \
    --cc=cornelia.huck@de.ibm.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=randy.dunlap@oracle.com \
    --cc=stern@rowland.harvard.edu \
    /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