aboutsummaryrefslogtreecommitdiffstats
path: root/main/busybox/2001-depmod-simple-memory-optimization.patch
blob: 0d8487560e4285ed401f17b4c4030aeb1b270745 (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
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
From 57d0eee1e1ec8ee02dd45b77ab3b6921b884855d Mon Sep 17 00:00:00 2001
From: Denys Vlasenko <vda.linux@googlemail.com>
Date: Sat, 24 Jan 2015 22:30:30 +0100
Subject: [PATCH 2001/2003] depmod: simple memory optimization

function                                             old     new   delta
filename2modname                                      67      86     +19
parse_module                                         374     351     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 modutils/depmod.c   | 19 +++++++++----------
 modutils/modutils.c |  6 +++++-
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/modutils/depmod.c b/modutils/depmod.c
index a41b3e4..37a8482 100644
--- a/modutils/depmod.c
+++ b/modutils/depmod.c
@@ -33,7 +33,6 @@ typedef struct module_info {
 static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM,
 				void *data, int depth UNUSED_PARAM)
 {
-	char modname[MODULE_NAME_LEN];
 	module_info **first = (module_info **) data;
 	char *image, *ptr;
 	module_info *info;
@@ -51,11 +50,10 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
 
 	info->dnext = info->dprev = info;
 	info->name = xstrdup(fname + 2); /* skip "./" */
-	info->modname = xstrdup(
-		filename2modname(
+	info->modname = filename2modname(
 			bb_get_last_path_component_nostrip(fname),
-			modname
-	));
+			NULL
+	);
 	for (ptr = image; ptr < image + len - 10; ptr++) {
 		if (strncmp(ptr, "depends=", 8) == 0) {
 			char *u;
@@ -250,11 +248,12 @@ int depmod_main(int argc UNUSED_PARAM, char **argv)
 		const char *fname = bb_basename(m->name);
 		filename2modname(fname, modname);
 		while (m->aliases) {
-			/* Last word can well be m->modname instead,
-			 * but depmod from module-init-tools 3.4
-			 * uses module basename, i.e., no s/-/_/g.
-			 * (pathname and .ko.* are still stripped)
-			 * Mimicking that... */
+			/*
+			 * Last word used to be a basename
+			 * (filename with path and .ko.* stripped)
+			 * at the time of module-init-tools 3.4.
+			 * kmod v.12 uses module name, i.e., s/-/_/g.
+			 */
 			printf("alias %s %s\n",
 				(char*)llist_pop(&m->aliases),
 				modname);
diff --git a/modutils/modutils.c b/modutils/modutils.c
index ff79d3f..84300d9 100644
--- a/modutils/modutils.c
+++ b/modutils/modutils.c
@@ -47,13 +47,14 @@ int FAST_FUNC string_to_llist(char *string, llist_t **llist, const char *delim)
 
 char* FAST_FUNC filename2modname(const char *filename, char *modname)
 {
+	char local_modname[MODULE_NAME_LEN];
 	int i;
 	const char *from;
 
 	if (filename == NULL)
 		return NULL;
 	if (modname == NULL)
-		modname = xmalloc(MODULE_NAME_LEN);
+		modname = local_modname;
 	// Disabled since otherwise "modprobe dir/name" would work
 	// as if it is "modprobe name". It is unclear why
 	// 'basenamization' was here in the first place.
@@ -63,6 +64,9 @@ char* FAST_FUNC filename2modname(const char *filename, char *modname)
 		modname[i] = (from[i] == '-') ? '_' : from[i];
 	modname[i] = '\0';
 
+	if (modname == local_modname)
+		return xstrdup(modname);
+
 	return modname;
 }
 
-- 
2.5.0