Commit c39c1c81 authored by Roland Dreier's avatar Roland Dreier Committed by Linus Torvalds

[PATCH] cdev_init: zero out cdev before kobject_init()

Right now, cdev_init() works in a way that is not very intuitive.  If a
driver passes an uninitialized struct cdev to cdev_init(), then an
uninitialized struct kobject will be passed to kobject_init(), which does
kset_get() on kobj->kset, which probably points off into space and causes
an oops.  Drivers can work around this by zeroing out their struct cdev in
advance (and indeed most if not all of the things passed to cdev_init()
come from BSS) but I think it makes more sense for cdev_init() to live up
to its name and actually work on an uninitialized cdev.
Signed-off-by: default avatarRoland Dreier <roland@topspin.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ad9e036c
......@@ -417,6 +417,7 @@ struct cdev *cdev_alloc(void)
void cdev_init(struct cdev *cdev, struct file_operations *fops)
{
memset(cdev, 0, sizeof *cdev);
INIT_LIST_HEAD(&cdev->list);
cdev->kobj.ktype = &ktype_cdev_default;
kobject_init(&cdev->kobj);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment