[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1208688366-9252-17-git-send-email-gregkh@suse.de>
Date: Sun, 20 Apr 2008 03:45:47 -0700
From: Greg Kroah-Hartman <gregkh@...e.de>
To: linux-kernel@...r.kernel.org
Cc: Ben Dooks <ben@...ff.org>, Kay Sievers <kay.sievers@...y.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Greg Kroah-Hartman <gregkh@...e.de>
Subject: [PATCH 17/36] sysdev: detect multiple driver registrations
From: Ben Dooks <ben@...ff.org>
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.
Signed-off-by: Ben Dooks <ben@...ff.org>
Cc: Kay Sievers <kay.sievers@...y.org>
Signed-off-by: Andrew Morton <akpm@...ux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@...e.de>
---
drivers/base/sys.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 8e13fd9..1a06c23 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -167,6 +167,22 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
{
int err = 0;
+ if (!cls) {
+ printk(KERN_WARNING "sysdev: invalid class passed to "
+ "sysdev_driver_register!\n");
+ WARN_ON(1);
+ return -EINVAL;
+ }
+
+ /* Check whether this driver has already been added to a class. */
+ if ((drv->entry.next != drv->entry.prev) ||
+ (drv->entry.next != NULL)) {
+ printk(KERN_WARNING "sysdev: class %s: driver (%p) has already"
+ " been registered to a class, something is wrong, but "
+ "will forge on!\n", cls->name, drv);
+ WARN_ON(1);
+ }
+
mutex_lock(&sysdev_drivers_lock);
if (cls && kset_get(&cls->kset)) {
list_add_tail(&drv->entry, &cls->drivers);
--
1.5.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists