Take or put a reference to a module, so it can't be unloaded while in use.
Signed-off-by: Nigel Cunningham <[email protected]>
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]