diff options
| author | Ben Dooks <ben@fluff.org> | 2008-03-04 18:09:06 -0500 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-04-19 22:10:24 -0400 |
| commit | da009f39f85a3ee9deeb10f0f05ddd4efdd67020 (patch) | |
| tree | ba04c23e0d5a831705f0f9bfe1a9be10aff99a78 /drivers/base | |
| parent | 6c847402e1c69c1cfe2bddeadc8391bacbb3d0a5 (diff) | |
sysdev: detect multiple driver registrations
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>
Diffstat (limited to 'drivers/base')
| -rw-r--r-- | 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 8e13fd942163..1a06c2393719 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) | |||
| 167 | { | 167 | { |
| 168 | int err = 0; | 168 | int err = 0; |
| 169 | 169 | ||
| 170 | if (!cls) { | ||
| 171 | printk(KERN_WARNING "sysdev: invalid class passed to " | ||
| 172 | "sysdev_driver_register!\n"); | ||
| 173 | WARN_ON(1); | ||
| 174 | return -EINVAL; | ||
| 175 | } | ||
| 176 | |||
| 177 | /* Check whether this driver has already been added to a class. */ | ||
| 178 | if ((drv->entry.next != drv->entry.prev) || | ||
| 179 | (drv->entry.next != NULL)) { | ||
| 180 | printk(KERN_WARNING "sysdev: class %s: driver (%p) has already" | ||
| 181 | " been registered to a class, something is wrong, but " | ||
| 182 | "will forge on!\n", cls->name, drv); | ||
| 183 | WARN_ON(1); | ||
| 184 | } | ||
| 185 | |||
| 170 | mutex_lock(&sysdev_drivers_lock); | 186 | mutex_lock(&sysdev_drivers_lock); |
| 171 | if (cls && kset_get(&cls->kset)) { | 187 | if (cls && kset_get(&cls->kset)) { |
| 172 | list_add_tail(&drv->entry, &cls->drivers); | 188 | list_add_tail(&drv->entry, &cls->drivers); |
