From: Greg KH <greg@kroah.com>

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 :)



 25-akpm/drivers/base/class.c |    6 ++++++
 25-akpm/drivers/base/core.c  |    6 ++++++
 25-akpm/lib/kobject.c        |    7 +++++++
 3 files changed, 19 insertions(+)

diff -puN drivers/base/class.c~kobject-paranoia-checks drivers/base/class.c
--- 25/drivers/base/class.c~kobject-paranoia-checks	Wed Jul 30 17:29:41 2003
+++ 25-akpm/drivers/base/class.c	Wed Jul 30 17:29:41 2003
@@ -194,6 +194,12 @@ static void class_dev_release(struct kob
 
 	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 -puN drivers/base/core.c~kobject-paranoia-checks drivers/base/core.c
--- 25/drivers/base/core.c~kobject-paranoia-checks	Wed Jul 30 17:29:41 2003
+++ 25-akpm/drivers/base/core.c	Wed Jul 30 17:29:41 2003
@@ -77,6 +77,12 @@ static void device_release(struct kobjec
 	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 -puN lib/kobject.c~kobject-paranoia-checks lib/kobject.c
--- 25/lib/kobject.c~kobject-paranoia-checks	Wed Jul 30 17:29:41 2003
+++ 25-akpm/lib/kobject.c	Wed Jul 30 17:29:41 2003
@@ -395,6 +395,13 @@ void kobject_cleanup(struct kobject * ko
 	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);
 }

_