[PATCH 2.5.64] Add error checking get_disk().

Bob Miller (rem@osdl.org)
Mon, 17 Mar 2003 11:24:32 -0800


The get_disk() function should check the return value from kobject_get()
before passing it to to_disk(). This patch fixes this error.

-- 
Bob Miller					Email: rem@osdl.org
Open Source Development Lab			Phone: 503.626.2455 Ext. 17

diff -Nru a/drivers/block/genhd.c b/drivers/block/genhd.c --- a/drivers/block/genhd.c Mon Mar 17 11:12:16 2003 +++ b/drivers/block/genhd.c Mon Mar 17 11:12:16 2003 @@ -538,12 +538,20 @@ struct gendisk *get_disk(struct gendisk *disk) { struct module *owner; + struct kobject *kobj; + if (!disk->fops) return NULL; owner = disk->fops->owner; if (owner && !try_module_get(owner)) return NULL; - return to_disk(kobject_get(&disk->kobj)); + kobj = kobject_get(&disk->kobj); + if (kobj == NULL) { + module_put(owner); + return NULL; + } + return to_disk(kobj); + } void put_disk(struct gendisk *disk) - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/