kobject_init rewrite

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

On Thu, Nov 29, 2007 at 05:21:34PM +0100, Cornelia Huck wrote:


Ok, how about this function.  If it errors out, it is free to just call
kfree() on the kobject.  Seems simple enough to me, any objections?  If
not, I'll go through and fix up the whole tree...

thanks,

greg k-h

-----------------

/**
 * kobject_init - initialize a kobject structure
 * @kobj: pointer to the kobject to initialize
 * @ktype: pointer to the ktype for this kobject.
 * @fmt: the name of the kobject
 *
 * This function will properly initialize a kobject such that it can then
 * be passed to the kobject_add() call.
 *
 * If the function returns an error, the memory allocated by the kobject
 * can be safely freed, no other functions need to be called.
 */
int kobject_init(struct kobject *kobj, struct kobj_type *ktype, const char *fmt, ...)
{
	va_list args;
	int retval;

	if (!kobj)
		return -EINVAL;

	if (!ktype)
		return -EINVAL;

	WARN_ON(atomic_read(&kobj->kref.refcount));
	kref_init(&kobj->kref);
	INIT_LIST_HEAD(&kobj->entry);
	kobj->ktype = ktype;

	va_start(args, fmt);
	retval = kobject_set_name_vargs(kobj, fmt, args);
	va_end(args);

	return retval;
}

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

Messages in current thread:
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)