diff options
author | Thierry Vignaud <tv@mageia.org> | 2012-12-12 10:12:16 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2012-12-12 10:12:16 +0000 |
commit | ee5d3e43c585a4386ded58d76fac2ef0985d96b5 (patch) | |
tree | a6f59fa82673a7982238405197ec652de498c529 /modalias.c | |
parent | 52c9d46227efeb02415c202866d38b4fc458d572 (diff) | |
download | ldetect-ee5d3e43c585a4386ded58d76fac2ef0985d96b5.tar ldetect-ee5d3e43c585a4386ded58d76fac2ef0985d96b5.tar.gz ldetect-ee5d3e43c585a4386ded58d76fac2ef0985d96b5.tar.bz2 ldetect-ee5d3e43c585a4386ded58d76fac2ef0985d96b5.tar.xz ldetect-ee5d3e43c585a4386ded58d76fac2ef0985d96b5.zip |
make ldetect 3x faster (and even faster on machines quite quite a lot
of devices such as servers)
(modalias_init) split it out of modalias_resolve_module()
(modalias_cleanup) move libkmod related cleanups here
(hid_probe,find_modules_through_aliases) only initialize libkmod once
(which reduces user time from 0.26 to 0.08s & elapsed time from 0.28 to
0.9s)
(backported from trunk)
Diffstat (limited to 'modalias.c')
-rw-r--r-- | modalias.c | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -24,7 +24,7 @@ static void get_version(void) { } -char*dirname; +char *dirname, *dkms_file; static void set_default_alias_file(void) { struct utsname rel_buf; @@ -51,11 +51,8 @@ static void set_default_alias_file(void) { } } -char *modalias_resolve_module(const char *modalias) { +struct kmod_ctx* modalias_init() { struct kmod_ctx *ctx; - struct kmod_list *l, *list = NULL; - int err; - char* dkms_file, *str = NULL; if (!aliasdefault) set_default_alias_file(); @@ -78,11 +75,18 @@ char *modalias_resolve_module(const char *modalias) { ctx = kmod_new(dirname, alias_filelist); if (!ctx) { fputs("Error: kmod_new() failed!\n", stderr); - goto exit; + free(dkms_file); + kmod_unref(ctx); + ctx = NULL; } kmod_load_resources(ctx); + return ctx; +} - err = kmod_module_new_from_lookup(ctx, modalias, &list); +char *modalias_resolve_module(struct kmod_ctx *ctx, const char *modalias) { + struct kmod_list *l, *list = NULL; + char *str = NULL; + int err = kmod_module_new_from_lookup(ctx, modalias, &list); if (err < 0) goto exit; @@ -112,12 +116,12 @@ char *modalias_resolve_module(const char *modalias) { kmod_module_unref_list(list); exit: - free(dkms_file); - kmod_unref(ctx); return str; } -void modalias_cleanup(void) { +void modalias_cleanup(struct kmod_ctx *ctx) { ifree(aliasdefault); ifree(version); + free(dkms_file); + kmod_unref(ctx); } |