1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
From fcfe596eb13f62ca9dd7de272a5a87ae843b2a00 Mon Sep 17 00:00:00 2001
From: Abuzer Rafey <abuzer@rafey.xyz>
Date: Wed, 13 Apr 2016 03:09:12 -0400
Subject: [PATCH] Simplify module_unload
---
src/module.c | 72 ++++++++++--------------------------------------------------
1 file changed, 12 insertions(+), 60 deletions(-)
diff --git a/src/module.c b/src/module.c
index db9736a..38e2daa 100644
--- a/src/module.c
+++ b/src/module.c
@@ -93,56 +93,27 @@ int module_load(char *module_name, char *driver) {
*/
int module_unload(char *driver) {
- if (module_is_loaded("nvidia_uvm") == 1) {
- int retries = 30;
- bb_log(LOG_INFO, "Unloading nvidia_uvm driver\n");
- char *mod_argv[] = {
- "modprobe",
- "-r",
- "nvidia_uvm",
- "nvidia_modeset",
- NULL
- };
- bb_run_fork_wait(mod_argv, 10);
- while (retries-- > 0 && module_is_loaded("nvidia_uvm") == 1) {
- usleep(100000);
- }
- if (module_is_loaded(driver) == 1) {
- bb_log(LOG_ERR, "Unloading %s driver timed out.\n", driver);
- return 0;
- }
- }
+ char uvm[] = "nvidia_uvm";
+ char drm[] = "nvidia_drm";
+ char modeset[] = "nvidia_modeset";
+ int uvm_is_loaded = module_is_loaded(uvm);
+ int drm_is_loaded = module_is_loaded(drm);
+ int modeset_is_loaded = module_is_loaded(modeset);
- else if (module_is_loaded("nvidia_drm") == 1) {
+ if (uvm_is_loaded || drm_is_loaded || modeset_is_loaded || *driver == 1) {
int retries = 30;
- bb_log(LOG_INFO, "Unloading nvidia_drm driver\n");
+ bb_log(LOG_INFO, "Unloading UVM/DRM/MODESET driver\n");
char *mod_argv[] = {
"modprobe",
"-r",
+ "nvidia_uvm",
"nvidia_drm",
- NULL
- };
- bb_run_fork_wait(mod_argv, 10);
- while (retries-- > 0 && module_is_loaded("nvidia_drm") == 1) {
- usleep(100000);
- }
- if (module_is_loaded(driver) == 1) {
- bb_log(LOG_ERR, "Unloading %s driver timed out.\n", driver);
- return 0;
- }
- }
-
- else if (module_is_loaded("nvidia_modeset") == 1) {
- int retries = 30;
- bb_log(LOG_INFO, "Unloading nvidia_modeset driver\n");
- char *mod_argv[] = {
- "modprobe",
- "-r",
"nvidia_modeset",
+ driver,
NULL
};
bb_run_fork_wait(mod_argv, 10);
- while (retries-- > 0 && module_is_loaded("nvidia_modeset") == 1) {
+ while (retries-- > 0 && module_is_loaded(driver) == 1) {
usleep(100000);
}
if (module_is_loaded(driver) == 1) {
@@ -150,26 +121,7 @@ int module_unload(char *driver) {
return 0;
}
}
-
- else if (module_is_loaded(driver) == 1) {
- int retries = 30;
- bb_log(LOG_INFO, "Unloading %s driver\n", driver);
- char *mod_argv[] = {
- "modprobe",
- "-r",
- driver,
- NULL
- };
- bb_run_fork_wait(mod_argv, 10);
- while (retries-- > 0 && module_is_loaded(driver) == 1) {
- usleep(100000);
- }
- if (module_is_loaded(driver) == 1) {
- bb_log(LOG_ERR, "Unloading %s driver timed out.\n", driver);
- return 0;
- }
- }
- return 1;
+ return 1;
}
/**
|