linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Driver core and kobject paranoia checks
@ 2003-07-31  0:27 Greg KH
  0 siblings, 0 replies; only message in thread
From: Greg KH @ 2003-07-31  0:27 UTC (permalink / raw)
  To: linux-kernel, akpm

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.

diff -Nru a/drivers/base/class.c b/drivers/base/class.c
--- a/drivers/base/class.c	Wed Jul 30 16:35:16 2003
+++ b/drivers/base/class.c	Wed Jul 30 16:35:16 2003
@@ -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 = {
diff -Nru a/drivers/base/core.c b/drivers/base/core.c
--- a/drivers/base/core.c	Wed Jul 30 16:35:16 2003
+++ b/drivers/base/core.c	Wed Jul 30 16:35:16 2003
@@ -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 = {
diff -Nru a/lib/kobject.c b/lib/kobject.c
--- a/lib/kobject.c	Wed Jul 30 16:35:16 2003
+++ b/lib/kobject.c	Wed Jul 30 16:35:16 2003
@@ -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);
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-07-31  0:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-31  0:27 [PATCH] Driver core and kobject paranoia checks Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).