Re: [PATCH] kobject: make sure kobj->ktype is set before kobject_init

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Kay Sievers <kay.sievers@...>
Cc: Cornelia Huck <cornelia.huck@...>, Greg KH <greg@...>, Kernel development list <linux-kernel@...>, Jonathan Corbet <corbet@...>, Randy Dunlap <randy.dunlap@...>
Date: Thursday, November 29, 2007 - 2:04 pm

On Thu, 29 Nov 2007, Kay Sievers wrote:


Let's say device_register() calls device_init(), which calls 
kobject_init(), which fails.  Then there's no cleanup to do -- 
device_register() returns -ENOMEM or some such code and the caller has 
to do the kfree().

Now let's say device_register() calls device_init(), which succeeds, 
and then calls device_add(), which fails.  To recover properly, 
somebody then has to call device_put().  That "somebody" can't be the 
original caller -- according to the previous paragraph the original 
caller won't do anything but kfree().  So the "somebody" has to be 
device_register() itself.

But the device_put() will call kobject_put(), which will invoke the
device's cleanup routine, which will deallocate the structure.  Now the
original caller gets an error code (perhaps -ENOMEM again) but must
_not_ call kfree().

So what should the original caller do when an error occurs?

Alan Stern

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH] kobject: make sure kobj->ktype is set before ..., Alan Stern, (Thu Nov 29, 2:04 pm)
kobject_init rewrite, Greg KH, (Thu Nov 29, 5:53 pm)
Re: kobject_init rewrite, Alan Stern, (Thu Nov 29, 6:16 pm)
Re: kobject_init rewrite, Greg KH, (Thu Nov 29, 6:24 pm)
Re: kobject_init rewrite, Greg KH, (Thu Nov 29, 5:54 pm)
Re: kobject_init rewrite, Cornelia Huck, (Fri Nov 30, 5:31 am)
[RFC] Sample kset/ktype/kobject implementation, Greg KH, (Tue Nov 27, 7:04 pm)
Re: [RFC] Sample kset/ktype/kobject implementation, Cornelia Huck, (Wed Nov 28, 12:35 pm)
Re: [RFC] Sample kset/ktype/kobject implementation, Cornelia Huck, (Thu Nov 29, 5:39 am)
Re: [RFC] Sample kset/ktype/kobject implementation, Alan Stern, (Thu Nov 29, 6:11 pm)
Re: [RFC] Sample kset/ktype/kobject implementation, Dave Young, (Fri Nov 30, 1:07 am)
Re: [RFC] Sample kset/ktype/kobject implementation, Alan Stern, (Fri Nov 30, 10:51 am)
Re: [RFC] Sample kset/ktype/kobject implementation, Dave Young, (Fri Nov 30, 1:57 am)
[RFC] sample kobject implementation, Greg KH, (Tue Nov 27, 7:03 pm)