diff options
author | Alan Jenkins <alan-jenkins@tuffmail.co.uk> | 2009-09-30 17:22:10 +0100 |
---|---|---|
committer | Alan Jenkins <alan-jenkins@tuffmail.co.uk> | 2010-02-25 15:29:24 +0000 |
commit | 09e4ce22b5751918ea1c8bd11ee36a10bcc21c54 (patch) | |
tree | 289665e2123c40ca8a77c58195f604e1ab92533a | |
parent | 6c31b6a061020a0b6af0aba28674a2e37516e6b3 (diff) | |
download | module-init-tools-09e4ce22b5751918ea1c8bd11ee36a10bcc21c54.tar.gz |
modprobe: simplify insmod() calling convention - don't free optstring
There's no need to clobber optstring; we can afford to make a copy.
Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
-rw-r--r-- | modprobe.c | 44 |
1 files changed, 24 insertions, 20 deletions
@@ -510,15 +510,17 @@ static char *prepend_option(char *options, const char *newoption) /* Add to options */ static char *add_extra_options(const char *modname, - char *optstring, + const char *optstring, const struct module_options *options) { + char *opts = NOFAIL(strdup(optstring)); + while (options) { if (streq(options->modulename, modname)) - optstring = prepend_option(optstring, options->options); + opts = prepend_option(opts, options->options); options = options->next; } - return optstring; + return opts; } /* Is module in /proc/modules? If so, fill in usecount if not NULL. @@ -1181,9 +1183,9 @@ static void do_command(const char *modname, free(replaced_cmd); } -/* Actually do the insert. Frees second arg. */ +/* Actually do the insert. */ static int insmod(struct list_head *list, - char *optstring, + const char *optstring, const char *newname, const struct module_options *options, const struct module_command *commands, @@ -1197,6 +1199,7 @@ static int insmod(struct list_head *list, struct module *mod = list_entry(list->next, struct module, list); int rc = 0; int already_loaded; + char *opts = NULL; /* Take us off the list. */ list_del(&mod->list); @@ -1206,12 +1209,12 @@ static int insmod(struct list_head *list, modprobe_flags_t f = flags; f &= ~mit_first_time; f &= ~mit_ignore_commands; - if ((rc = insmod(list, NOFAIL(strdup("")), NULL, + if ((rc = insmod(list, "", NULL, options, commands, "", warn, f)) != 0) { error("Error inserting %s (%s): %s\n", mod->modname, mod->filename, insert_moderror(errno)); - goto out_optstring; + goto out; } } @@ -1219,7 +1222,7 @@ static int insmod(struct list_head *list, if (fd < 0) { error("Could not open '%s': %s\n", mod->filename, strerror(errno)); - goto out_optstring; + goto out; } /* Don't do ANYTHING if already in kernel. */ @@ -1244,7 +1247,7 @@ static int insmod(struct list_head *list, close_file(fd); do_command(mod->modname, command, flags & mit_dry_run, error, "install", cmdline_opts); - goto out_optstring; + goto out; } } @@ -1263,14 +1266,14 @@ static int insmod(struct list_head *list, clear_magic(module); /* Config file might have given more options */ - optstring = add_extra_options(mod->modname, optstring, options); + opts = add_extra_options(mod->modname, optstring, options); - info("insmod %s %s\n", mod->filename, optstring); + info("insmod %s %s\n", mod->filename, opts); if (flags & mit_dry_run) - goto out; + goto out_elf_file; - ret = init_module(module->data, module->len, optstring); + ret = init_module(module->data, module->len, opts); if (ret != 0) { if (errno == EEXIST) { if (flags & mit_first_time) @@ -1286,12 +1289,12 @@ static int insmod(struct list_head *list, insert_moderror(errno)); rc = 1; } - out: + out_elf_file: release_elf_file(module); out_unlock: close_file(fd); - out_optstring: - free(optstring); + free(opts); + out: return rc; } @@ -1374,7 +1377,7 @@ nonexistent_module: static int handle_module(const char *modname, struct list_head *todo_list, const char *newname, - char *options, + const char *options, struct module_options *modoptions, struct module_command *commands, const char *cmdline_opts, @@ -1401,7 +1404,7 @@ static int handle_module(const char *modname, if (flags & mit_remove) rmmod(todo_list, newname, commands, cmdline_opts, error, flags); else - insmod(todo_list, NOFAIL(strdup(options)), newname, + insmod(todo_list, options, newname, modoptions, commands, cmdline_opts, error, flags); return 0; @@ -1491,9 +1494,9 @@ int do_modprobe(char *modname, err = warn; while (aliases) { /* Add the options for this alias. */ - char *opts = NOFAIL(strdup(cmdline_opts)); + char *opts; opts = add_extra_options(modname, - opts, modoptions); + cmdline_opts, modoptions); read_depends(dirname, aliases->module, &list); failed |= handle_module(aliases->module, @@ -1501,6 +1504,7 @@ int do_modprobe(char *modname, commands, cmdline_opts, err, flags); aliases = aliases->next; + free(opts); INIT_LIST_HEAD(&list); } } else { |