aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCornelia Huck <cornelia.huck@de.ibm.com>2009-03-04 06:44:00 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-03-24 19:38:26 -0400
commitffa6a7054d172a2f57248dff2de600ca795c5656 (patch)
treef93c6234bb90295c52fcef09e367ed77ff6c3645
parent60530afe1ee8a5532cb09d0ab5bc3f1a6495b780 (diff)
Driver core: Fix device_move() vs. dpm list ordering, v2
dpm_list currently relies on the fact that child devices will be registered after their parents to get a correct suspend order. Using device_move() however destroys this assumption, as an already registered device may be moved under a newly registered one. This patch adds a new argument to device_move(), allowing callers to specify how dpm_list should be adapted. Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/base/core.c19
-rw-r--r--drivers/base/power/main.c44
-rw-r--r--drivers/base/power/power.h8
-rw-r--r--drivers/s390/cio/device.c9
-rw-r--r--include/linux/device.h3
-rw-r--r--include/linux/pm.h11
-rw-r--r--net/bluetooth/hci_sysfs.c2
-rw-r--r--net/bluetooth/rfcomm/tty.c5
8 files changed, 92 insertions, 9 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 95c67ffd71da..e73c92d13a23 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1561,8 +1561,10 @@ out:
1561 * device_move - moves a device to a new parent 1561 * device_move - moves a device to a new parent
1562 * @dev: the pointer to the struct device to be moved 1562 * @dev: the pointer to the struct device to be moved
1563 * @new_parent: the new parent of the device (can by NULL) 1563 * @new_parent: the new parent of the device (can by NULL)
1564 * @dpm_order: how to reorder the dpm_list
1564 */ 1565 */
1565int device_move(struct device *dev, struct device *new_parent) 1566int device_move(struct device *dev, struct device *new_parent,
1567 enum dpm_order dpm_order)
1566{ 1568{
1567 int error; 1569 int error;
1568 struct device *old_parent; 1570 struct device *old_parent;
@@ -1572,6 +1574,7 @@ int device_move(struct device *dev, struct device *new_parent)
1572 if (!dev) 1574 if (!dev)
1573 return -EINVAL; 1575 return -EINVAL;
1574 1576
1577 device_pm_lock();
1575 new_parent = get_device(new_parent); 1578 new_parent = get_device(new_parent);
1576 new_parent_kobj = get_device_parent(dev, new_parent); 1579 new_parent_kobj = get_device_parent(dev, new_parent);
1577 1580
@@ -1613,9 +1616,23 @@ int device_move(struct device *dev, struct device *new_parent)
1613 put_device(new_parent); 1616 put_device(new_parent);
1614 goto out; 1617 goto out;
1615 } 1618 }
1619 switch (dpm_order) {
1620 case DPM_ORDER_NONE:
1621 break;
1622 case DPM_ORDER_DEV_AFTER_PARENT:
1623 device_pm_move_after(dev, new_parent);
1624 break;
1625 case DPM_ORDER_PARENT_BEFORE_DEV:
1626 device_pm_move_before(new_parent, dev);
1627 break;
1628 case DPM_ORDER_DEV_LAST:
1629 device_pm_move_last(dev);
1630 break;
1631 }
1616out_put: 1632out_put:
1617 put_device(old_parent); 1633 put_device(old_parent);
1618out: 1634out:
1635 device_pm_unlock();
1619 put_device(dev); 1636 put_device(dev);
1620 return error; 1637 return error;
1621} 1638}
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 2d14f4ae6c01..e255341682c8 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -107,6 +107,50 @@ void device_pm_remove(struct device *dev)
107} 107}
108 108
109/** 109/**
110 * device_pm_move_before - move device in dpm_list
111 * @deva: Device to move in dpm_list
112 * @devb: Device @deva should come before
113 */
114void device_pm_move_before(struct device *deva, struct device *devb)
115{
116 pr_debug("PM: Moving %s:%s before %s:%s\n",
117 deva->bus ? deva->bus->name : "No Bus",
118 kobject_name(&deva->kobj),
119 devb->bus ? devb->bus->name : "No Bus",
120 kobject_name(&devb->kobj));
121 /* Delete deva from dpm_list and reinsert before devb. */
122 list_move_tail(&deva->power.entry, &devb->power.entry);
123}
124
125/**
126 * device_pm_move_after - move device in dpm_list
127 * @deva: Device to move in dpm_list
128 * @devb: Device @deva should come after
129 */
130void device_pm_move_after(struct device *deva, struct device *devb)
131{
132 pr_debug("PM: Moving %s:%s after %s:%s\n",
133 deva->bus ? deva->bus->name : "No Bus",
134 kobject_name(&deva->kobj),
135 devb->bus ? devb->bus->name : "No Bus",
136 kobject_name(&devb->kobj));
137 /* Delete deva from dpm_list and reinsert after devb. */
138 list_move(&deva->power.entry, &devb->power.entry);
139}
140
141/**
142 * device_pm_move_last - move device to end of dpm_list
143 * @dev: Device to move in dpm_list
144 */
145void device_pm_move_last(struct device *dev)
146{
147 pr_debug("PM: Moving %s:%s to end of list\n",
148 dev->bus ? dev->bus->name : "No Bus",
149 kobject_name(&dev->kobj));
150 list_move_tail(&dev->power.entry, &dpm_list);
151}
152
153/**
110 * pm_op - execute the PM operation appropiate for given PM event 154 * pm_op - execute the PM operation appropiate for given PM event
111 * @dev: Device. 155 * @dev: Device.
112 * @ops: PM operations to choose from. 156 * @ops: PM operations to choose from.
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 41f51fae042f..c7cb4fc3735c 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -18,11 +18,19 @@ static inline struct device *to_device(struct list_head *entry)
18 18
19extern void device_pm_add(struct device *); 19extern void device_pm_add(struct device *);
20extern void device_pm_remove(struct device *); 20extern void device_pm_remove(struct device *);
21extern void device_pm_move_before(struct device *, struct device *);
22extern void device_pm_move_after(struct device *, struct device *);
23extern void device_pm_move_last(struct device *);
21 24
22#else /* CONFIG_PM_SLEEP */ 25#else /* CONFIG_PM_SLEEP */
23 26
24static inline void device_pm_add(struct device *dev) {} 27static inline void device_pm_add(struct device *dev) {}
25static inline void device_pm_remove(struct device *dev) {} 28static inline void device_pm_remove(struct device *dev) {}
29static inline void device_pm_move_before(struct device *deva,
30 struct device *devb) {}
31static inline void device_pm_move_after(struct device *deva,
32 struct device *devb) {}
33static inline void device_pm_move_last(struct device *dev) {}
26 34
27#endif 35#endif
28 36
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 611d2e001dd5..e28f8ae53453 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -799,7 +799,7 @@ static void sch_attach_disconnected_device(struct subchannel *sch,
799 return; 799 return;
800 other_sch = to_subchannel(cdev->dev.parent); 800 other_sch = to_subchannel(cdev->dev.parent);
801 /* Note: device_move() changes cdev->dev.parent */ 801 /* Note: device_move() changes cdev->dev.parent */
802 ret = device_move(&cdev->dev, &sch->dev); 802 ret = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV);
803 if (ret) { 803 if (ret) {
804 CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed " 804 CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed "
805 "(ret=%d)!\n", cdev->private->dev_id.ssid, 805 "(ret=%d)!\n", cdev->private->dev_id.ssid,
@@ -830,7 +830,7 @@ static void sch_attach_orphaned_device(struct subchannel *sch,
830 * Try to move the ccw device to its new subchannel. 830 * Try to move the ccw device to its new subchannel.
831 * Note: device_move() changes cdev->dev.parent 831 * Note: device_move() changes cdev->dev.parent
832 */ 832 */
833 ret = device_move(&cdev->dev, &sch->dev); 833 ret = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV);
834 if (ret) { 834 if (ret) {
835 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage " 835 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
836 "failed (ret=%d)!\n", 836 "failed (ret=%d)!\n",
@@ -897,7 +897,8 @@ void ccw_device_move_to_orphanage(struct work_struct *work)
897 * ccw device can take its place on the subchannel. 897 * ccw device can take its place on the subchannel.
898 * Note: device_move() changes cdev->dev.parent 898 * Note: device_move() changes cdev->dev.parent
899 */ 899 */
900 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev); 900 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev,
901 DPM_ORDER_NONE);
901 if (ret) { 902 if (ret) {
902 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed " 903 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
903 "(ret=%d)!\n", cdev->private->dev_id.ssid, 904 "(ret=%d)!\n", cdev->private->dev_id.ssid,
@@ -1129,7 +1130,7 @@ static void ccw_device_move_to_sch(struct work_struct *work)
1129 * Try to move the ccw device to its new subchannel. 1130 * Try to move the ccw device to its new subchannel.
1130 * Note: device_move() changes cdev->dev.parent 1131 * Note: device_move() changes cdev->dev.parent
1131 */ 1132 */
1132 rc = device_move(&cdev->dev, &sch->dev); 1133 rc = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV);
1133 mutex_unlock(&sch->reg_mutex); 1134 mutex_unlock(&sch->reg_mutex);
1134 if (rc) { 1135 if (rc) {
1135 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel " 1136 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel "
diff --git a/include/linux/device.h b/include/linux/device.h
index 914c1016dd8f..f98d0cfb4f81 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -494,7 +494,8 @@ extern int device_for_each_child(struct device *dev, void *data,
494extern struct device *device_find_child(struct device *dev, void *data, 494extern struct device *device_find_child(struct device *dev, void *data,
495 int (*match)(struct device *dev, void *data)); 495 int (*match)(struct device *dev, void *data));
496extern int device_rename(struct device *dev, char *new_name); 496extern int device_rename(struct device *dev, char *new_name);
497extern int device_move(struct device *dev, struct device *new_parent); 497extern int device_move(struct device *dev, struct device *new_parent,
498 enum dpm_order dpm_order);
498 499
499/* 500/*
500 * Root device objects for grouping under /sys/devices 501 * Root device objects for grouping under /sys/devices
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 24ba5f67b3a3..1d4e2d289821 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -400,6 +400,9 @@ extern void __suspend_report_result(const char *function, void *fn, int ret);
400 400
401#else /* !CONFIG_PM_SLEEP */ 401#else /* !CONFIG_PM_SLEEP */
402 402
403#define device_pm_lock() do {} while (0)
404#define device_pm_unlock() do {} while (0)
405
403static inline int device_suspend(pm_message_t state) 406static inline int device_suspend(pm_message_t state)
404{ 407{
405 return 0; 408 return 0;
@@ -409,6 +412,14 @@ static inline int device_suspend(pm_message_t state)
409 412
410#endif /* !CONFIG_PM_SLEEP */ 413#endif /* !CONFIG_PM_SLEEP */
411 414
415/* How to reorder dpm_list after device_move() */
416enum dpm_order {
417 DPM_ORDER_NONE,
418 DPM_ORDER_DEV_AFTER_PARENT,
419 DPM_ORDER_PARENT_BEFORE_DEV,
420 DPM_ORDER_DEV_LAST,
421};
422
412/* 423/*
413 * Global Power Management flags 424 * Global Power Management flags
414 * Used to keep APM and ACPI from both being active 425 * Used to keep APM and ACPI from both being active
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 1a1f916be44e..ed82796d4a0f 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -140,7 +140,7 @@ static void del_conn(struct work_struct *work)
140 dev = device_find_child(&conn->dev, NULL, __match_tty); 140 dev = device_find_child(&conn->dev, NULL, __match_tty);
141 if (!dev) 141 if (!dev)
142 break; 142 break;
143 device_move(dev, NULL); 143 device_move(dev, NULL, DPM_ORDER_DEV_LAST);
144 put_device(dev); 144 put_device(dev);
145 } 145 }
146 146
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index d030c69cb5a3..abdc703a11d2 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -731,7 +731,8 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
731 remove_wait_queue(&dev->wait, &wait); 731 remove_wait_queue(&dev->wait, &wait);
732 732
733 if (err == 0) 733 if (err == 0)
734 device_move(dev->tty_dev, rfcomm_get_device(dev)); 734 device_move(dev->tty_dev, rfcomm_get_device(dev),
735 DPM_ORDER_DEV_AFTER_PARENT);
735 736
736 rfcomm_tty_copy_pending(dev); 737 rfcomm_tty_copy_pending(dev);
737 738
@@ -751,7 +752,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
751 752
752 if (atomic_dec_and_test(&dev->opened)) { 753 if (atomic_dec_and_test(&dev->opened)) {
753 if (dev->tty_dev->parent) 754 if (dev->tty_dev->parent)
754 device_move(dev->tty_dev, NULL); 755 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
755 756
756 /* Close DLC and dettach TTY */ 757 /* Close DLC and dettach TTY */
757 rfcomm_dlc_close(dev->dlc, 0); 758 rfcomm_dlc_close(dev->dlc, 0);