From: Ben Dooks <ben@fluff.org>
To: gregkh@suse.de, linux-kernel@vger.kernel.org
Subject: sysdev: detecting multiple driver registrations
Date: Mon, 18 Feb 2008 14:51:24 +0000 [thread overview]
Message-ID: <20080218145124.GA17980@fluff.org.uk> (raw)
I've just found how easy it is to accidentally register
a sysdev_driver for two different classes. When this
happens, bad things happen as the sysdev_driver structure
keeps has the list entry for the driver registration.
The following patch makes a WARN_ON() if this happens,
although I think BUG_ON or returning -EAGAIN could also be valid
responses to this.
Index: linux-2.6.24-quilt5/drivers/base/sys.c
===================================================================
--- linux-2.6.24-quilt5.orig/drivers/base/sys.c
+++ linux-2.6.24-quilt5/drivers/base/sys.c
@@ -169,6 +169,11 @@ int sysdev_driver_register(struct sysdev
{
int err = 0;
+ /* Check whether this driver has already been added to a class. */
+
+ WARN_ON(drv->entry.next != drv->entry.prev);
+ WARN_ON(drv->entry.next != NULL);
+
mutex_lock(&sysdev_drivers_lock);
if (cls && kset_get(&cls->kset)) {
list_add_tail(&drv->entry, &cls->drivers);
My first question is, whether people think that this check
is a sane and worthwhile thing to do.
The second question is, should this be BUG_ON, WARN_ON or
return an error (with optional print)?
And my third question is that a number of drivers are
assuming an NULL initialised 'struct list_head' is a
valid setup for an include/linux/list.h list. Is
there a case of using LIST_HEAD_INIT() on all sysdev
driver structures? If not, should we be using
INIT_LIST_HEAD() in sysdev_driver_register(). The header
is not clear on what should be done.
--
Ben
reply other threads:[~2008-02-18 14:51 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=20080218145124.GA17980@fluff.org.uk \
--to=ben@fluff.org \
--cc=gregkh@suse.de \
--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