Re: kobject_init rewrite

Cornelia Huck
2007-11-30T09:31:57Z

On Thu, 29 Nov 2007 13:54:55 -0800,
Greg KH <greg@kroah.com> wrote:

> One minor documentation update:
>
> > /**
> > * 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.
>
> If the function does not return an error, the only way the kobject's
> memory can be properly freed is with a call to kobject_put(). kfree()
> should never be called on a kobject after this function has been called,
> execept from the ktype's release function.
>
> > */
> > 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;
> > }
> >

Yes, this looks fine.