lkml.org 
[lkml]   [2006]   [Feb]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[ 06/10] [Suspend2] Get/put module reference.
Date

Take or put a reference to a module, so it can't be unloaded while in use.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

kernel/power/modules.c | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index a7c3c38..dd53b27 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -185,3 +185,41 @@ struct suspend_module_ops *get_next_filt

return active_writer;
}
+
+/* suspend2_get_modules
+ *
+ * Take a reference to modules so they can't go away under us.
+ */
+
+int suspend2_get_modules(void)
+{
+ struct suspend_module_ops *this_module;
+
+ list_for_each_entry(this_module, &suspend_modules, module_list) {
+ if (!try_module_get(this_module->module)) {
+ /* Failed! Reverse gets and return error */
+ struct suspend_module_ops *this_module2;
+ list_for_each_entry(this_module2, &suspend_modules, module_list) {
+ if (this_module == this_module2)
+ return -EINVAL;
+ module_put(this_module2->module);
+ }
+ }
+ }
+
+ return 0;
+}
+
+/* suspend2_put_modules
+ *
+ * Release our references to modules we used.
+ */
+
+void suspend2_put_modules(void)
+{
+ struct suspend_module_ops *this_module;
+
+ list_for_each_entry(this_module, &suspend_modules, module_list) {
+ module_put(this_module->module);
+ }
+}
--
Nigel Cunningham nigel at suspend2 dot net
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-02-01 12:44    [W:0.184 / U:7.140 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site