[PATCH -mm 2/5] Misc: Add possibility to remove misc devices during suspend/resume

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Rafael J. Wysocki
Date: Thursday, January 24, 2008 - 5:31 pm

From: Rafael J. Wysocki <rjw@sisk.pl>

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>
---
 drivers/char/misc.c        |   13 +++++++++----
 include/linux/miscdevice.h |   10 +++++++++-
 2 files changed, 18 insertions(+), 5 deletions(-)

Index: linux-2.6.24-rc8-mm1/include/linux/miscdevice.h
===================================================================
--- linux-2.6.24-rc8-mm1.orig/include/linux/miscdevice.h
+++ linux-2.6.24-rc8-mm1/include/linux/miscdevice.h
@@ -43,7 +43,15 @@ struct miscdevice  {
 };
 
 extern int misc_register(struct miscdevice * misc);
-extern int misc_deregister(struct miscdevice * misc);
+extern int __misc_deregister(struct miscdevice *misc, bool suspended);
+static inline int misc_deregister(struct miscdevice *misc)
+{
+	return __misc_deregister(misc, false);
+}
+static inline int misc_deregister_suspended(struct miscdevice *misc)
+{
+	return __misc_deregister(misc, true);
+}
 
 #define MODULE_ALIAS_MISCDEV(minor)				\
 	MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR)	\
Index: linux-2.6.24-rc8-mm1/drivers/char/misc.c
===================================================================
--- linux-2.6.24-rc8-mm1.orig/drivers/char/misc.c
+++ linux-2.6.24-rc8-mm1/drivers/char/misc.c
@@ -232,8 +232,9 @@ int misc_register(struct miscdevice * mi
 }
 
 /**
- *	misc_deregister - unregister a miscellaneous device
+ *	__misc_deregister - unregister a miscellaneous device
  *	@misc: device to unregister
+ *	@suspended: to be set if the function is used during suspend/resume
  *
  *	Unregister a miscellaneous device that was previously
  *	successfully registered with misc_register(). Success
@@ -241,7 +242,7 @@ int misc_register(struct miscdevice * mi
  *	indicates an error.
  */
 
-int misc_deregister(struct miscdevice * misc)
+int __misc_deregister(struct miscdevice *misc, bool suspended)
 {
 	int i = misc->minor;
 
@@ -250,7 +251,11 @@ int misc_deregister(struct miscdevice * 
 
 	mutex_lock(&misc_mtx);
 	list_del(&misc->list);
-	device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
+	if (suspended)
+		destroy_suspended_device(misc_class,
+					MKDEV(MISC_MAJOR, misc->minor));
+	else
+		device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
 	if (i < DYNAMIC_MINORS && i>0) {
 		misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
 	}
@@ -259,7 +264,7 @@ int misc_deregister(struct miscdevice * 
 }
 
 EXPORT_SYMBOL(misc_register);
-EXPORT_SYMBOL(misc_deregister);
+EXPORT_SYMBOL(__misc_deregister);
 
 static int __init misc_init(void)
 {

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH -mm 0/5] b43: Fix suspend/resume deadlock, Rafael J. Wysocki, (Thu Jan 24, 5:27 pm)
[PATCH -mm 1/5] PM: Export device_pm_schedule_removal, Rafael J. Wysocki, (Thu Jan 24, 5:30 pm)
[PATCH -mm 2/5] Misc: Add possibility to remove misc devic ..., Rafael J. Wysocki, (Thu Jan 24, 5:31 pm)
[PATCH -mm 3/5] HWRNG: Add possibility to remove hwrng dev ..., Rafael J. Wysocki, (Thu Jan 24, 5:35 pm)
[PATCH -mm 4/5] Leds: Add possibility to remove leds class ..., Rafael J. Wysocki, (Thu Jan 24, 5:36 pm)
[PATCH -mm 5/5] b43: Avoid unregistering device objects du ..., Rafael J. Wysocki, (Thu Jan 24, 5:37 pm)
Re: [PATCH -mm 1/5] PM: Export device_pm_schedule_removal, Pavel Machek, (Fri Jan 25, 12:44 am)
Re: [PATCH -mm 5/5] b43: Avoid unregistering device object ..., Rafael J. Wysocki, (Fri Jan 25, 4:45 am)