Skip to content

Commit 5fa21d8

Browse files
author
Linus Torvalds
committed
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/usb-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/usb-2.6: [PATCH] Driver core: fix locking issues with the devices that are attached to classes [PATCH] USB: get USB suspend to work again
2 parents 8542e58 + 5d9fd16 commit 5fa21d8

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎drivers/base/core.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ int device_add(struct device *dev)
356356
if (parent)
357357
klist_add_tail(&dev->knode_parent, &parent->klist_children);
358358

359+
if (dev->class) {
360+
/* tie the class to the device */
361+
down(&dev->class->sem);
362+
list_add_tail(&dev->node, &dev->class->devices);
363+
up(&dev->class->sem);
364+
}
365+
359366
/* notify platform of device entry */
360367
if (platform_notify)
361368
platform_notify(dev);
@@ -455,6 +462,9 @@ void device_del(struct device * dev)
455462
sysfs_remove_link(&dev->kobj, "device");
456463
sysfs_remove_link(&dev->parent->kobj, class_name);
457464
kfree(class_name);
465+
down(&dev->class->sem);
466+
list_del_init(&dev->node);
467+
up(&dev->class->sem);
458468
}
459469
device_remove_file(dev, &dev->uevent_attr);
460470

@@ -601,11 +611,6 @@ struct device *device_create(struct class *class, struct device *parent,
601611
if (retval)
602612
goto error;
603613

604-
/* tie the class to the device */
605-
down(&class->sem);
606-
list_add_tail(&dev->node, &class->devices);
607-
up(&class->sem);
608-
609614
return dev;
610615

611616
error:
@@ -636,9 +641,7 @@ void device_destroy(struct class *class, dev_t devt)
636641
}
637642
up(&class->sem);
638643

639-
if (dev) {
640-
list_del_init(&dev->node);
644+
if (dev)
641645
device_unregister(dev);
642-
}
643646
}
644647
EXPORT_SYMBOL_GPL(device_destroy);

‎drivers/usb/core/usb.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,8 @@ void usb_buffer_unmap_sg (struct usb_device *dev, unsigned pipe,
991991

992992
static int verify_suspended(struct device *dev, void *unused)
993993
{
994+
if (dev->driver == NULL)
995+
return 0;
994996
return (dev->power.power_state.event == PM_EVENT_ON) ? -EBUSY : 0;
995997
}
996998

0 commit comments

Comments
 (0)