summaryrefslogtreecommitdiff
path: root/package/system/ubox/patches/001-insmod.patch
blob: af858d9f4bcdbd263449dee715f4d7d51bf6703e (plain)
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
Index: ubox-2015-02-25.1/kmodloader.c
===================================================================
--- ubox-2015-02-25.1.orig/kmodloader.c
+++ ubox-2015-02-25.1/kmodloader.c
@@ -483,14 +483,15 @@ static int insert_module(char *path, con
 		return ret;
 	}
 
-	data = malloc(s.st_size);
-	if (read(fd, data, s.st_size) == s.st_size)
-		ret = syscall(__NR_init_module, data, (unsigned long) s.st_size, options);
-	else
+	data = mmap(NULL, s.st_size, PROT_READ,
+                       MAP_PRIVATE, fd, 0);
+	if (data == MAP_FAILED)
 		ERROR("failed to read full module %s\n", path);
+	else
+		ret = syscall(__NR_init_module, data, (unsigned long) s.st_size, options);
 
+	munmap(data, s.st_size);
 	close(fd);
-	free(data);
 
 	return ret;
 }
@@ -574,15 +575,18 @@ static int main_insmod(int argc, char **
 	if (argc < 2)
 		return print_insmod_usage();
 
+	if (init_module_folders())
+		return -1;
+
+	if (scan_loaded_modules())
+		return -1;
+
 	name = get_module_name(argv[1]);
 	if (!name) {
 		ERROR("cannot find module - %s\n", argv[1]);
 		return -1;
 	}
 
-	if (scan_loaded_modules())
-		return -1;
-
 	if (find_module(name)) {
 		ERROR("module is already loaded - %s\n", name);
 		return -1;