Skip to content

Commit

Permalink
sysdev: detect multiple driver registrations
Browse files Browse the repository at this point in the history
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@fluff.org>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Ben Dooks authored and Greg Kroah-Hartman committed Apr 20, 2008
1 parent 6c84740 commit da009f3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions drivers/base/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit da009f3

Please sign in to comment.