Skip to contentSkip to conversation

Driver core and kobject paranoia checks

PATCH New Greg KH 1 participant 1 message Jul 31, 2003

Subsystems (2)
lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 Driver core and kobject paranoia checks

Hi,

Here's a fun patch for the driver core, and the kobject core that will tell you if any programmers messed up when they implemented driver and kobject code. Running with this patch shows lots of people who messed things up (myself included.) I have patches in the USB tree to fix all of the warnings that this patch throws, and the network people know are busy fixing their issues too.

The kobject portion of the patch can give false positives when kobjects that are static are unregistered, so I don't think that patch should be added to the kernel tree right now. Andrew, feel free to pick up the other portion for the -mm tree if you want. After the usb and networking changes get into Linus's tree, I'll probably push for this too.

Oh, this patch also moves the driver and kobject api quite a few steps up Rusty's "how bad is the API" rating scale :)

thanks,

greg k-h

# driver core and kobject paranoia checks.
drivers/base/class.c +6 -0
diff -Nru a/drivers/base/class.c b/drivers/base/class.c
@@ -194,6 +194,12 @@
 
 	if (cls->release)
 		cls->release(cd);
+	else {
+		printk(KERN_ERR "Device class '%s' does not have a release() function, "
+			"it is broken and must be fixed.\n",
+			cd->class_id);
+		WARN_ON(1);
+	}
 }
 
 static struct kobj_type ktype_class_device = {
drivers/base/core.c +6 -0
diff -Nru a/drivers/base/core.c b/drivers/base/core.c
@@ -77,6 +77,12 @@
 	struct device * dev = to_dev(kobj);
 	if (dev->release)
 		dev->release(dev);
+	else {
+		printk(KERN_ERR "Device '%s' does not have a release() function, "
+			"it is broken and must be fixed.\n",
+			dev->bus_id);
+		WARN_ON(1);
+	}
 }
 
 static struct kobj_type ktype_device = {
lib/kobject.c +7 -0
diff -Nru a/lib/kobject.c b/lib/kobject.c
@@ -397,6 +397,13 @@
 	pr_debug("kobject %s: cleaning up\n",kobj->name);
 	if (t && t->release)
 		t->release(kobj);
+	else {
+		printk(KERN_ERR "kobject '%s' does not have a release() function, "
+			"it is broken and must be fixed.\n",
+			kobj->name);
+		WARN_ON(1);
+	}
+
 	if (s)
 		kset_put(s);
 }