aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2008-02-05 01:30:11 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-05 12:44:23 -0500
commit533354d4ac48b7df99f18f952e5d51c3f59ba56c (patch)
treed1d5616e39d58ce8f27127901d43d4b0b0f69fa5
parentf011e2e2df3393c16b0fdc48e855e909b7e021ee (diff)
Misc: Add possibility to remove misc devices during suspend/resume
Make it possible to unregister a misc device object in a safe way during a suspend/resume cycle. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Cc: Michael Buesch <mb@bu3sch.de> Cc: Pavel Machek <pavel@ucw.cz> Cc: "John W. Linville" <linville@tuxdriver.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Len Brown <lenb@kernel.org> Cc: Greg KH <greg@kroah.com> Cc: Kay Sievers <kay.sievers@vrfy.org> Cc: Richard Purdie <rpurdie@rpsys.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/char/misc.c13
-rw-r--r--include/linux/miscdevice.h10
2 files changed, 18 insertions, 5 deletions
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 71c8cd7fa15f..a39101feb2ed 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -232,8 +232,9 @@ int misc_register(struct miscdevice * misc)
232} 232}
233 233
234/** 234/**
235 * misc_deregister - unregister a miscellaneous device 235 * __misc_deregister - unregister a miscellaneous device
236 * @misc: device to unregister 236 * @misc: device to unregister
237 * @suspended: to be set if the function is used during suspend/resume
237 * 238 *
238 * Unregister a miscellaneous device that was previously 239 * Unregister a miscellaneous device that was previously
239 * successfully registered with misc_register(). Success 240 * successfully registered with misc_register(). Success
@@ -241,7 +242,7 @@ int misc_register(struct miscdevice * misc)
241 * indicates an error. 242 * indicates an error.
242 */ 243 */
243 244
244int misc_deregister(struct miscdevice * misc) 245int __misc_deregister(struct miscdevice *misc, bool suspended)
245{ 246{
246 int i = misc->minor; 247 int i = misc->minor;
247 248
@@ -250,7 +251,11 @@ int misc_deregister(struct miscdevice * misc)
250 251
251 mutex_lock(&misc_mtx); 252 mutex_lock(&misc_mtx);
252 list_del(&misc->list); 253 list_del(&misc->list);
253 device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); 254 if (suspended)
255 destroy_suspended_device(misc_class,
256 MKDEV(MISC_MAJOR, misc->minor));
257 else
258 device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
254 if (i < DYNAMIC_MINORS && i>0) { 259 if (i < DYNAMIC_MINORS && i>0) {
255 misc_minors[i>>3] &= ~(1 << (misc->minor & 7)); 260 misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
256 } 261 }
@@ -259,7 +264,7 @@ int misc_deregister(struct miscdevice * misc)
259} 264}
260 265
261EXPORT_SYMBOL(misc_register); 266EXPORT_SYMBOL(misc_register);
262EXPORT_SYMBOL(misc_deregister); 267EXPORT_SYMBOL(__misc_deregister);
263 268
264static int __init misc_init(void) 269static int __init misc_init(void)
265{ 270{
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index dff9ea32606a..24b30b9b4f8a 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -43,7 +43,15 @@ struct miscdevice {
43}; 43};
44 44
45extern int misc_register(struct miscdevice * misc); 45extern int misc_register(struct miscdevice * misc);
46extern int misc_deregister(struct miscdevice * misc); 46extern int __misc_deregister(struct miscdevice *misc, bool suspended);
47static inline int misc_deregister(struct miscdevice *misc)
48{
49 return __misc_deregister(misc, false);
50}
51static inline int misc_deregister_suspended(struct miscdevice *misc)
52{
53 return __misc_deregister(misc, true);
54}
47 55
48#define MODULE_ALIAS_MISCDEV(minor) \ 56#define MODULE_ALIAS_MISCDEV(minor) \
49 MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR) \ 57 MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR) \