Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM: Remove destroy_suspended_device()

After 2.6.24 there was a plan to make the PM core acquire all device
semaphores during a suspend/hibernation to protect itself from
concurrent operations involving device objects. That proved to be
too heavy-handed and we found a better way to achieve the goal, but
before it happened, we had introduced the functions
device_pm_schedule_removal() and destroy_suspended_device() to allow
drivers to "safely" destroy a suspended device and we had adapted some
drivers to use them. Now that these functions are no longer necessary,
it seems reasonable to remove them and modify their users to use the
normal device unregistration instead.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Rafael J. Wysocki and committed by
Greg Kroah-Hartman
b844eba2 138fe4e0

+22 -146
+1 -3
arch/x86/kernel/cpuid.c
··· 154 154 err = cpuid_device_create(cpu); 155 155 break; 156 156 case CPU_UP_CANCELED: 157 + case CPU_UP_CANCELED_FROZEN: 157 158 case CPU_DEAD: 158 159 cpuid_device_destroy(cpu); 159 - break; 160 - case CPU_UP_CANCELED_FROZEN: 161 - destroy_suspended_device(cpuid_class, MKDEV(CPUID_MAJOR, cpu)); 162 160 break; 163 161 } 164 162 return err ? NOTIFY_BAD : NOTIFY_OK;
+1 -3
arch/x86/kernel/msr.c
··· 162 162 err = msr_device_create(cpu); 163 163 break; 164 164 case CPU_UP_CANCELED: 165 + case CPU_UP_CANCELED_FROZEN: 165 166 case CPU_DEAD: 166 167 msr_device_destroy(cpu); 167 - break; 168 - case CPU_UP_CANCELED_FROZEN: 169 - destroy_suspended_device(msr_class, MKDEV(MSR_MAJOR, cpu)); 170 168 break; 171 169 } 172 170 return err ? NOTIFY_BAD : NOTIFY_OK;
-29
drivers/base/core.c
··· 1163 1163 } 1164 1164 EXPORT_SYMBOL_GPL(device_destroy); 1165 1165 1166 - #ifdef CONFIG_PM_SLEEP 1167 - /** 1168 - * destroy_suspended_device - asks the PM core to remove a suspended device 1169 - * @class: pointer to the struct class that this device was registered with 1170 - * @devt: the dev_t of the device that was previously registered 1171 - * 1172 - * This call notifies the PM core of the necessity to unregister a suspended 1173 - * device created with a call to device_create() (devices cannot be 1174 - * unregistered directly while suspended, since the PM core holds their 1175 - * semaphores at that time). 1176 - * 1177 - * It can only be called within the scope of a system sleep transition. In 1178 - * practice this means it has to be directly or indirectly invoked either by 1179 - * a suspend or resume method, or by the PM core (e.g. via 1180 - * disable_nonboot_cpus() or enable_nonboot_cpus()). 1181 - */ 1182 - void destroy_suspended_device(struct class *class, dev_t devt) 1183 - { 1184 - struct device *dev; 1185 - 1186 - dev = class_find_device(class, &devt, __match_devt); 1187 - if (dev) { 1188 - device_pm_schedule_removal(dev); 1189 - put_device(dev); 1190 - } 1191 - } 1192 - EXPORT_SYMBOL_GPL(destroy_suspended_device); 1193 - #endif /* CONFIG_PM_SLEEP */ 1194 - 1195 1166 /** 1196 1167 * device_rename - renames a device 1197 1168 * @dev: the pointer to the struct device to be renamed
-40
drivers/base/power/main.c
··· 50 50 LIST_HEAD(dpm_active); 51 51 static LIST_HEAD(dpm_off); 52 52 static LIST_HEAD(dpm_off_irq); 53 - static LIST_HEAD(dpm_destroy); 54 53 55 54 static DEFINE_MUTEX(dpm_list_mtx); 56 55 ··· 102 103 list_del_init(&dev->power.entry); 103 104 mutex_unlock(&dpm_list_mtx); 104 105 } 105 - 106 - /** 107 - * device_pm_schedule_removal - schedule the removal of a suspended device 108 - * @dev: Device to destroy 109 - * 110 - * Moves the device to the dpm_destroy list for further processing by 111 - * unregister_dropped_devices(). 112 - */ 113 - void device_pm_schedule_removal(struct device *dev) 114 - { 115 - pr_debug("PM: Preparing for removal: %s:%s\n", 116 - dev->bus ? dev->bus->name : "No Bus", 117 - kobject_name(&dev->kobj)); 118 - mutex_lock(&dpm_list_mtx); 119 - list_move_tail(&dev->power.entry, &dpm_destroy); 120 - mutex_unlock(&dpm_list_mtx); 121 - } 122 - EXPORT_SYMBOL_GPL(device_pm_schedule_removal); 123 106 124 107 /*------------------------- Resume routines -------------------------*/ 125 108 ··· 227 246 } 228 247 229 248 /** 230 - * unregister_dropped_devices - Unregister devices scheduled for removal 231 - * 232 - * Unregister all devices on the dpm_destroy list. 233 - */ 234 - static void unregister_dropped_devices(void) 235 - { 236 - mutex_lock(&dpm_list_mtx); 237 - while (!list_empty(&dpm_destroy)) { 238 - struct list_head *entry = dpm_destroy.next; 239 - struct device *dev = to_device(entry); 240 - 241 - mutex_unlock(&dpm_list_mtx); 242 - /* This also removes the device from the list */ 243 - device_unregister(dev); 244 - mutex_lock(&dpm_list_mtx); 245 - } 246 - mutex_unlock(&dpm_list_mtx); 247 - } 248 - 249 - /** 250 249 * device_resume - Restore state of each device in system. 251 250 * 252 251 * Resume all the devices, unlock them all, and allow new ··· 236 275 { 237 276 might_sleep(); 238 277 dpm_resume(); 239 - unregister_dropped_devices(); 240 278 } 241 279 EXPORT_SYMBOL_GPL(device_resume); 242 280
+5 -5
drivers/char/hw_random/core.c
··· 238 238 NULL); 239 239 240 240 241 - static void unregister_miscdev(bool suspended) 241 + static void unregister_miscdev(void) 242 242 { 243 243 device_remove_file(rng_miscdev.this_device, &dev_attr_rng_available); 244 244 device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current); 245 - __misc_deregister(&rng_miscdev, suspended); 245 + misc_deregister(&rng_miscdev); 246 246 } 247 247 248 248 static int register_miscdev(void) ··· 317 317 } 318 318 EXPORT_SYMBOL_GPL(hwrng_register); 319 319 320 - void __hwrng_unregister(struct hwrng *rng, bool suspended) 320 + void hwrng_unregister(struct hwrng *rng) 321 321 { 322 322 int err; 323 323 ··· 336 336 } 337 337 } 338 338 if (list_empty(&rng_list)) 339 - unregister_miscdev(suspended); 339 + unregister_miscdev(); 340 340 341 341 mutex_unlock(&rng_mutex); 342 342 } 343 - EXPORT_SYMBOL_GPL(__hwrng_unregister); 343 + EXPORT_SYMBOL_GPL(hwrng_unregister); 344 344 345 345 346 346 MODULE_DESCRIPTION("H/W Random Number Generator (RNG) driver");
+4 -9
drivers/char/misc.c
··· 232 232 } 233 233 234 234 /** 235 - * __misc_deregister - unregister a miscellaneous device 235 + * misc_deregister - unregister a miscellaneous device 236 236 * @misc: device to unregister 237 - * @suspended: to be set if the function is used during suspend/resume 238 237 * 239 238 * Unregister a miscellaneous device that was previously 240 239 * successfully registered with misc_register(). Success ··· 241 242 * indicates an error. 242 243 */ 243 244 244 - int __misc_deregister(struct miscdevice *misc, bool suspended) 245 + int misc_deregister(struct miscdevice *misc) 245 246 { 246 247 int i = misc->minor; 247 248 ··· 250 251 251 252 mutex_lock(&misc_mtx); 252 253 list_del(&misc->list); 253 - if (suspended) 254 - destroy_suspended_device(misc_class, 255 - MKDEV(MISC_MAJOR, misc->minor)); 256 - else 257 - device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); 254 + device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); 258 255 if (i < DYNAMIC_MINORS && i>0) { 259 256 misc_minors[i>>3] &= ~(1 << (misc->minor & 7)); 260 257 } ··· 259 264 } 260 265 261 266 EXPORT_SYMBOL(misc_register); 262 - EXPORT_SYMBOL(__misc_deregister); 267 + EXPORT_SYMBOL(misc_deregister); 263 268 264 269 static int __init misc_init(void) 265 270 {
+3 -8
drivers/leds/led-class.c
··· 139 139 /** 140 140 * __led_classdev_unregister - unregisters a object of led_properties class. 141 141 * @led_cdev: the led device to unregister 142 - * @suspended: indicates whether system-wide suspend or resume is in progress 143 142 * 144 143 * Unregisters a previously registered via led_classdev_register object. 145 144 */ 146 - void __led_classdev_unregister(struct led_classdev *led_cdev, 147 - bool suspended) 145 + void led_classdev_unregister(struct led_classdev *led_cdev) 148 146 { 149 147 device_remove_file(led_cdev->dev, &dev_attr_brightness); 150 148 #ifdef CONFIG_LEDS_TRIGGERS ··· 153 155 up_write(&led_cdev->trigger_lock); 154 156 #endif 155 157 156 - if (suspended) 157 - device_pm_schedule_removal(led_cdev->dev); 158 - else 159 - device_unregister(led_cdev->dev); 158 + device_unregister(led_cdev->dev); 160 159 161 160 down_write(&leds_list_lock); 162 161 list_del(&led_cdev->node); 163 162 up_write(&leds_list_lock); 164 163 } 165 - EXPORT_SYMBOL_GPL(__led_classdev_unregister); 164 + EXPORT_SYMBOL_GPL(led_classdev_unregister); 166 165 167 166 static int __init leds_init(void) 168 167 {
+1 -4
drivers/net/wireless/b43/leds.c
··· 116 116 { 117 117 if (!led->dev) 118 118 return; 119 - if (led->dev->suspend_in_progress) 120 - led_classdev_unregister_suspended(&led->led_dev); 121 - else 122 - led_classdev_unregister(&led->led_dev); 119 + led_classdev_unregister(&led->led_dev); 123 120 b43_led_turn_off(led->dev, led->index, led->activelow); 124 121 led->dev = NULL; 125 122 }
+4 -4
drivers/net/wireless/b43/main.c
··· 2804 2804 return (sizeof(u16)); 2805 2805 } 2806 2806 2807 - static void b43_rng_exit(struct b43_wl *wl, bool suspended) 2807 + static void b43_rng_exit(struct b43_wl *wl) 2808 2808 { 2809 2809 if (wl->rng_initialized) 2810 - __hwrng_unregister(&wl->rng, suspended); 2810 + hwrng_unregister(&wl->rng); 2811 2811 } 2812 2812 2813 2813 static int b43_rng_init(struct b43_wl *wl) ··· 3824 3824 3825 3825 if (!dev->suspend_in_progress) { 3826 3826 b43_leds_exit(dev); 3827 - b43_rng_exit(dev->wl, false); 3827 + b43_rng_exit(dev->wl); 3828 3828 } 3829 3829 b43_dma_free(dev); 3830 3830 b43_pio_free(dev); ··· 4589 4589 err = b43_wireless_core_start(wldev); 4590 4590 if (err) { 4591 4591 b43_leds_exit(wldev); 4592 - b43_rng_exit(wldev->wl, true); 4592 + b43_rng_exit(wldev->wl); 4593 4593 b43_wireless_core_exit(wldev); 4594 4594 b43err(wl, "Resume failed at core start\n"); 4595 4595 goto out;
-14
include/linux/device.h
··· 545 545 dev_t devt, const char *fmt, ...) 546 546 __attribute__((format(printf, 4, 5))); 547 547 extern void device_destroy(struct class *cls, dev_t devt); 548 - #ifdef CONFIG_PM_SLEEP 549 - extern void destroy_suspended_device(struct class *cls, dev_t devt); 550 - extern void device_pm_schedule_removal(struct device *); 551 - #else /* !CONFIG_PM_SLEEP */ 552 - static inline void destroy_suspended_device(struct class *cls, dev_t devt) 553 - { 554 - device_destroy(cls, devt); 555 - } 556 - 557 - static inline void device_pm_schedule_removal(struct device *dev) 558 - { 559 - device_unregister(dev); 560 - } 561 - #endif /* !CONFIG_PM_SLEEP */ 562 548 563 549 /* 564 550 * Platform "fixup" functions - allow the platform to have their say
+1 -9
include/linux/hw_random.h
··· 44 44 /** Register a new Hardware Random Number Generator driver. */ 45 45 extern int hwrng_register(struct hwrng *rng); 46 46 /** Unregister a Hardware Random Number Generator driver. */ 47 - extern void __hwrng_unregister(struct hwrng *rng, bool suspended); 48 - static inline void hwrng_unregister(struct hwrng *rng) 49 - { 50 - __hwrng_unregister(rng, false); 51 - } 52 - static inline void hwrng_unregister_suspended(struct hwrng *rng) 53 - { 54 - __hwrng_unregister(rng, true); 55 - } 47 + extern void hwrng_unregister(struct hwrng *rng); 56 48 57 49 #endif /* __KERNEL__ */ 58 50 #endif /* LINUX_HWRANDOM_H_ */
+1 -9
include/linux/leds.h
··· 59 59 60 60 extern int led_classdev_register(struct device *parent, 61 61 struct led_classdev *led_cdev); 62 - extern void __led_classdev_unregister(struct led_classdev *led_cdev, bool sus); 63 - static inline void led_classdev_unregister(struct led_classdev *lcd) 64 - { 65 - __led_classdev_unregister(lcd, false); 66 - } 67 - static inline void led_classdev_unregister_suspended(struct led_classdev *lcd) 68 - { 69 - __led_classdev_unregister(lcd, true); 70 - } 62 + extern void led_classdev_unregister(struct led_classdev *lcd); 71 63 extern void led_classdev_suspend(struct led_classdev *led_cdev); 72 64 extern void led_classdev_resume(struct led_classdev *led_cdev); 73 65
+1 -9
include/linux/miscdevice.h
··· 43 43 }; 44 44 45 45 extern int misc_register(struct miscdevice * misc); 46 - extern int __misc_deregister(struct miscdevice *misc, bool suspended); 47 - static inline int misc_deregister(struct miscdevice *misc) 48 - { 49 - return __misc_deregister(misc, false); 50 - } 51 - static inline int misc_deregister_suspended(struct miscdevice *misc) 52 - { 53 - return __misc_deregister(misc, true); 54 - } 46 + extern int misc_deregister(struct miscdevice *misc); 55 47 56 48 #define MODULE_ALIAS_MISCDEV(minor) \ 57 49 MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR) \