diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-01-24 22:30:30 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-01-24 22:30:30 +0100 |
commit | cc70b6f8b6c6441e1c48690c7885700a2d389946 (patch) | |
tree | 4ed5b3b75f89ff88d28f639c0911507c07c09c77 | |
parent | 86031a5ffd106b8128f5763d32c273b96875f707 (diff) | |
download | busybox-w32-cc70b6f8b6c6441e1c48690c7885700a2d389946.tar.gz busybox-w32-cc70b6f8b6c6441e1c48690c7885700a2d389946.tar.bz2 busybox-w32-cc70b6f8b6c6441e1c48690c7885700a2d389946.zip |
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>
-rw-r--r-- | modutils/depmod.c | 19 | ||||
-rw-r--r-- | modutils/modutils.c | 6 |
2 files changed, 14 insertions, 11 deletions
diff --git a/modutils/depmod.c b/modutils/depmod.c index a41b3e440..37a8482d9 100644 --- a/modutils/depmod.c +++ b/modutils/depmod.c | |||
@@ -33,7 +33,6 @@ typedef struct module_info { | |||
33 | static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM, | 33 | static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM, |
34 | void *data, int depth UNUSED_PARAM) | 34 | void *data, int depth UNUSED_PARAM) |
35 | { | 35 | { |
36 | char modname[MODULE_NAME_LEN]; | ||
37 | module_info **first = (module_info **) data; | 36 | module_info **first = (module_info **) data; |
38 | char *image, *ptr; | 37 | char *image, *ptr; |
39 | module_info *info; | 38 | module_info *info; |
@@ -51,11 +50,10 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA | |||
51 | 50 | ||
52 | info->dnext = info->dprev = info; | 51 | info->dnext = info->dprev = info; |
53 | info->name = xstrdup(fname + 2); /* skip "./" */ | 52 | info->name = xstrdup(fname + 2); /* skip "./" */ |
54 | info->modname = xstrdup( | 53 | info->modname = filename2modname( |
55 | filename2modname( | ||
56 | bb_get_last_path_component_nostrip(fname), | 54 | bb_get_last_path_component_nostrip(fname), |
57 | modname | 55 | NULL |
58 | )); | 56 | ); |
59 | for (ptr = image; ptr < image + len - 10; ptr++) { | 57 | for (ptr = image; ptr < image + len - 10; ptr++) { |
60 | if (strncmp(ptr, "depends=", 8) == 0) { | 58 | if (strncmp(ptr, "depends=", 8) == 0) { |
61 | char *u; | 59 | char *u; |
@@ -250,11 +248,12 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) | |||
250 | const char *fname = bb_basename(m->name); | 248 | const char *fname = bb_basename(m->name); |
251 | filename2modname(fname, modname); | 249 | filename2modname(fname, modname); |
252 | while (m->aliases) { | 250 | while (m->aliases) { |
253 | /* Last word can well be m->modname instead, | 251 | /* |
254 | * but depmod from module-init-tools 3.4 | 252 | * Last word used to be a basename |
255 | * uses module basename, i.e., no s/-/_/g. | 253 | * (filename with path and .ko.* stripped) |
256 | * (pathname and .ko.* are still stripped) | 254 | * at the time of module-init-tools 3.4. |
257 | * Mimicking that... */ | 255 | * kmod v.12 uses module name, i.e., s/-/_/g. |
256 | */ | ||
258 | printf("alias %s %s\n", | 257 | printf("alias %s %s\n", |
259 | (char*)llist_pop(&m->aliases), | 258 | (char*)llist_pop(&m->aliases), |
260 | modname); | 259 | modname); |
diff --git a/modutils/modutils.c b/modutils/modutils.c index ff79d3fac..84300d931 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) | |||
47 | 47 | ||
48 | char* FAST_FUNC filename2modname(const char *filename, char *modname) | 48 | char* FAST_FUNC filename2modname(const char *filename, char *modname) |
49 | { | 49 | { |
50 | char local_modname[MODULE_NAME_LEN]; | ||
50 | int i; | 51 | int i; |
51 | const char *from; | 52 | const char *from; |
52 | 53 | ||
53 | if (filename == NULL) | 54 | if (filename == NULL) |
54 | return NULL; | 55 | return NULL; |
55 | if (modname == NULL) | 56 | if (modname == NULL) |
56 | modname = xmalloc(MODULE_NAME_LEN); | 57 | modname = local_modname; |
57 | // Disabled since otherwise "modprobe dir/name" would work | 58 | // Disabled since otherwise "modprobe dir/name" would work |
58 | // as if it is "modprobe name". It is unclear why | 59 | // as if it is "modprobe name". It is unclear why |
59 | // 'basenamization' was here in the first place. | 60 | // 'basenamization' was here in the first place. |
@@ -63,6 +64,9 @@ char* FAST_FUNC filename2modname(const char *filename, char *modname) | |||
63 | modname[i] = (from[i] == '-') ? '_' : from[i]; | 64 | modname[i] = (from[i] == '-') ? '_' : from[i]; |
64 | modname[i] = '\0'; | 65 | modname[i] = '\0'; |
65 | 66 | ||
67 | if (modname == local_modname) | ||
68 | return xstrdup(modname); | ||
69 | |||
66 | return modname; | 70 | return modname; |
67 | } | 71 | } |
68 | 72 | ||