Skip to contentSkip to conversation

Add error checking get_disk().

PATCH New Bob Miller 1 participant 1 message Mar 17, 2003

lore
Share & tools
lore

Bob Miller

author
#0 lore raw

PATCH 1/1 Add error checking get_disk().

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

Signature · 29 lines
Bob Miller					Email: [email protected]
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)