Re: [PATCH 3/4][Trivial] lib/kobject.c : Check ktype inkobject_add_internal

From: greg
Date: Mon Apr 23 2012 - 16:40:49 EST


On Sat, Apr 21, 2012 at 05:58:31PM +0800, yan wrote:
> If someone calls kobject_init with null kobj_type, kobject_init can
> detect it. But it does not have a return value, it just dumps stack.
> In this case, a kobject_add after that will result in:
> -->kobject_add_varg
> -->kobject_add_internal
> -->create_dir
> -->sysfs_create_dir
> -->sysfs_read_ns_type
> -->kobj_child_ns_ops
> In the end, it will call ->ktype->child_ns_type directly and we have
> an oops.
>
> Check ktype before really add a kobject.

But how can we add a kobject without a valid ktype?

At the most, I'd prefer to warn about this, much like we warn about not
having a name, and not just returning an error without a hint as to what
went wrong.

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/