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

Kay Sievers
2007-11-28T20:52:46Z

On Wed, 2007-11-28 at 15:42 -0500, Alan Stern wrote:
> This patch (as1020) adds a check to kobject_init() to insure that the
> ktype field is not NULL.

That's good.

> This is just for safety's sake; as far as I
> know there are no remaining places where the field is left unset. But
> ironically, kset_init() did fail to set it!

Nice to have that fixed.

> The patch fixes that and
> removes some redundant initialization in kset_createa().
>
> The patch also fixes up elevator_init(), where ktype was set after
> calling kobject_init() instead of before.

It should not harm, only the kset was needed before _init(), but even
that should be history with Greg's latest patch:
http://git.kernel.org/?p=linux/kernel/git/gregkh/patches.git;a=blob;f=driver/kobject-grab-the-kset-reference-in-kobject_add-not-kobject_init.patch;hb=HEAD

> Here is the check we discussed. I'm a little behind on Kay's most
> recent updates; I hope this doesn't clash with them.
>
> There may be some other places where ktype gets set after
> kobject_init() rather than before. My testing can't be termendously
> thorough. But they should all be easy to fix (like elevator.c was)

I think it's fine and elevator does not need to be changed, and we can
remove the requirement now from the documentation, as _init() now does
not depend on any pre-assigned values, right?

Kay