public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org, akpm@osdl.org
Subject: [PATCH] Driver core and kobject paranoia checks
Date: Wed, 30 Jul 2003 17:27:42 -0700	[thread overview]
Message-ID: <20030731002742.GA5873@kroah.com> (raw)

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);
 }

                 reply	other threads:[~2003-07-31  0:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030731002742.GA5873@kroah.com \
    --to=greg@kroah.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox