From: Emil Velikov Date: Wed, 11 Sep 2024 16:30:13 +0000 (+0100) Subject: libkmod: mass convert with clang-format X-Git-Tag: v34~296 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=115bcd529aa70bfb303936a9157fafd32d5c4c2c;p=thirdparty%2Fkmod.git libkmod: mass convert with clang-format Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/118 Signed-off-by: Lucas De Marchi --- diff --git a/libkmod/libkmod-builtin.c b/libkmod/libkmod-builtin.c index cf42cdbd..937fefc8 100644 --- a/libkmod/libkmod-builtin.c +++ b/libkmod/libkmod-builtin.c @@ -32,8 +32,7 @@ struct kmod_builtin_info { char *buf; }; -static bool kmod_builtin_info_init(struct kmod_builtin_info *info, - struct kmod_ctx *ctx) +static bool kmod_builtin_info_init(struct kmod_builtin_info *info, struct kmod_ctx *ctx) { char path[PATH_MAX]; FILE *fp = NULL; @@ -78,7 +77,7 @@ static ssize_t get_string(struct kmod_builtin_info *info) } static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname, - struct strbuf *buf) + struct strbuf *buf) { const size_t modlen = strlen(modname); ssize_t count, n; @@ -100,7 +99,7 @@ static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname, if (dot == NULL) { count = -EINVAL; ERR(info->ctx, "get_strings: " - "unexpected string without modname prefix\n"); + "unexpected string without modname prefix\n"); return count; } if (strncmp(line, modname, modlen) || line[modlen] != '.') { @@ -113,11 +112,10 @@ static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname, continue; break; } - if (!strbuf_pushchars(buf, dot + 1) || - !strbuf_pushchar(buf, '\0')) { + if (!strbuf_pushchars(buf, dot + 1) || !strbuf_pushchar(buf, '\0')) { count = -errno; ERR(info->ctx, "get_strings: " - "failed to append modinfo string\n"); + "failed to append modinfo string\n"); return count; } count++; @@ -126,7 +124,7 @@ static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname, if (count == INTPTR_MAX) { count = -ENOMEM; ERR(info->ctx, "get_strings: " - "too many modinfo strings encountered\n"); + "too many modinfo strings encountered\n"); return count; } @@ -142,8 +140,7 @@ static char **strbuf_to_vector(struct strbuf *buf, size_t count) size_t n; /* make sure that vector and strings fit into memory constraints */ - if (SIZE_MAX / sizeof(char *) - 1 < count || - SIZE_MAX - buf->used < vecsz) { + if (SIZE_MAX / sizeof(char *) - 1 < count || SIZE_MAX - buf->used < vecsz) { errno = ENOMEM; return NULL; } @@ -166,7 +163,7 @@ static char **strbuf_to_vector(struct strbuf *buf, size_t count) /* array will be allocated with strings in a single malloc, just free *array */ ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname, - char ***modinfo) + char ***modinfo) { struct kmod_builtin_info info; struct strbuf buf; diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index 44e62531..c2420fdf 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -55,76 +55,84 @@ const char *kmod_blacklist_get_modname(const struct kmod_list *l) return l->data; } -const char *kmod_alias_get_name(const struct kmod_list *l) { +const char *kmod_alias_get_name(const struct kmod_list *l) +{ const struct kmod_alias *alias = l->data; return alias->name; } -const char *kmod_alias_get_modname(const struct kmod_list *l) { +const char *kmod_alias_get_modname(const struct kmod_list *l) +{ const struct kmod_alias *alias = l->data; return alias->modname; } -const char *kmod_option_get_options(const struct kmod_list *l) { +const char *kmod_option_get_options(const struct kmod_list *l) +{ const struct kmod_options *alias = l->data; return alias->options; } -const char *kmod_option_get_modname(const struct kmod_list *l) { +const char *kmod_option_get_modname(const struct kmod_list *l) +{ const struct kmod_options *alias = l->data; return alias->modname; } -const char *kmod_command_get_command(const struct kmod_list *l) { +const char *kmod_command_get_command(const struct kmod_list *l) +{ const struct kmod_command *alias = l->data; return alias->command; } -const char *kmod_command_get_modname(const struct kmod_list *l) { +const char *kmod_command_get_modname(const struct kmod_list *l) +{ const struct kmod_command *alias = l->data; return alias->modname; } -const char *kmod_softdep_get_name(const struct kmod_list *l) { +const char *kmod_softdep_get_name(const struct kmod_list *l) +{ const struct kmod_softdep *dep = l->data; return dep->name; } -const char * const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count) { +const char *const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count) +{ const struct kmod_softdep *dep = l->data; *count = dep->n_pre; return dep->pre; } -const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count) { +const char *const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count) +{ const struct kmod_softdep *dep = l->data; *count = dep->n_post; return dep->post; } -const char *kmod_weakdep_get_name(const struct kmod_list *l) { +const char *kmod_weakdep_get_name(const struct kmod_list *l) +{ const struct kmod_weakdep *dep = l->data; return dep->name; } -const char * const *kmod_weakdep_get_weak(const struct kmod_list *l, unsigned int *count) { +const char *const *kmod_weakdep_get_weak(const struct kmod_list *l, unsigned int *count) +{ const struct kmod_weakdep *dep = l->data; *count = dep->n_weak; return dep->weak; } -static int kmod_config_add_command(struct kmod_config *config, - const char *modname, - const char *command, - const char *command_name, - struct kmod_list **list) +static int kmod_config_add_command(struct kmod_config *config, const char *modname, + const char *command, const char *command_name, + struct kmod_list **list) { _cleanup_free_ struct kmod_command *cmd; struct kmod_list *l; size_t modnamelen = strlen(modname) + 1; size_t commandlen = strlen(command) + 1; - DBG(config->ctx, "modname='%s' cmd='%s %s'\n", modname, command_name, - command); + DBG(config->ctx, "modname='%s' cmd='%s %s'\n", modname, command_name, command); cmd = malloc(sizeof(*cmd) + modnamelen + commandlen); if (!cmd) @@ -143,9 +151,8 @@ static int kmod_config_add_command(struct kmod_config *config, return 0; } -static void kmod_config_free_command(struct kmod_config *config, - struct kmod_list *l, - struct kmod_list **list) +static void kmod_config_free_command(struct kmod_config *config, struct kmod_list *l, + struct kmod_list **list) { struct kmod_command *cmd = l->data; @@ -153,8 +160,8 @@ static void kmod_config_free_command(struct kmod_config *config, *list = kmod_list_remove(l); } -static int kmod_config_add_options(struct kmod_config *config, - const char *modname, const char *options) +static int kmod_config_add_options(struct kmod_config *config, const char *modname, + const char *options) { _cleanup_free_ struct kmod_options *opt; struct kmod_list *list; @@ -182,8 +189,7 @@ static int kmod_config_add_options(struct kmod_config *config, return 0; } -static void kmod_config_free_options(struct kmod_config *config, - struct kmod_list *l) +static void kmod_config_free_options(struct kmod_config *config, struct kmod_list *l) { struct kmod_options *opt = l->data; @@ -192,8 +198,8 @@ static void kmod_config_free_options(struct kmod_config *config, config->options = kmod_list_remove(l); } -static int kmod_config_add_alias(struct kmod_config *config, - const char *name, const char *modname) +static int kmod_config_add_alias(struct kmod_config *config, const char *name, + const char *modname) { _cleanup_free_ struct kmod_alias *alias; struct kmod_list *list; @@ -219,8 +225,7 @@ static int kmod_config_add_alias(struct kmod_config *config, return 0; } -static void kmod_config_free_alias(struct kmod_config *config, - struct kmod_list *l) +static void kmod_config_free_alias(struct kmod_config *config, struct kmod_list *l) { struct kmod_alias *alias = l->data; @@ -229,8 +234,7 @@ static void kmod_config_free_alias(struct kmod_config *config, config->aliases = kmod_list_remove(l); } -static int kmod_config_add_blacklist(struct kmod_config *config, - const char *modname) +static int kmod_config_add_blacklist(struct kmod_config *config, const char *modname) { _cleanup_free_ char *p; struct kmod_list *list; @@ -250,16 +254,14 @@ static int kmod_config_add_blacklist(struct kmod_config *config, return 0; } -static void kmod_config_free_blacklist(struct kmod_config *config, - struct kmod_list *l) +static void kmod_config_free_blacklist(struct kmod_config *config, struct kmod_list *l) { free(l->data); config->blacklists = kmod_list_remove(l); } -static int kmod_config_add_softdep(struct kmod_config *config, - const char *modname, - const char *line) +static int kmod_config_add_softdep(struct kmod_config *config, const char *modname, + const char *line) { struct kmod_list *list; struct kmod_softdep *dep; @@ -274,7 +276,7 @@ static int kmod_config_add_softdep(struct kmod_config *config, DBG(config->ctx, "modname=%s\n", modname); /* analyze and count */ - for (p = s = line; ; s++) { + for (p = s = line;; s++) { size_t plen; if (*s != '\0') { @@ -295,10 +297,10 @@ static int kmod_config_add_softdep(struct kmod_config *config, plen = s - p; if (plen == sizeof("pre:") - 1 && - memcmp(p, "pre:", sizeof("pre:") - 1) == 0) + memcmp(p, "pre:", sizeof("pre:") - 1) == 0) mode = S_PRE; else if (plen == sizeof("post:") - 1 && - memcmp(p, "post:", sizeof("post:") - 1) == 0) + memcmp(p, "post:", sizeof("post:") - 1) == 0) mode = S_POST; else if (*s != '\0' || (*s == '\0' && !was_space)) { if (mode == S_PRE) { @@ -317,8 +319,7 @@ static int kmod_config_add_softdep(struct kmod_config *config, DBG(config->ctx, "%u pre, %u post\n", n_pre, n_post); dep = malloc(sizeof(struct kmod_softdep) + modnamelen + - n_pre * sizeof(const char *) + - n_post * sizeof(const char *) + + n_pre * sizeof(const char *) + n_post * sizeof(const char *) + buflen); if (dep == NULL) { ERR(config->ctx, "out-of-memory modname=%s\n", modname); @@ -338,7 +339,7 @@ static int kmod_config_add_softdep(struct kmod_config *config, n_post = 0; mode = S_NONE; was_space = false; - for (p = s = line; ; s++) { + for (p = s = line;; s++) { size_t plen; if (*s != '\0') { @@ -359,10 +360,10 @@ static int kmod_config_add_softdep(struct kmod_config *config, plen = s - p; if (plen == sizeof("pre:") - 1 && - memcmp(p, "pre:", sizeof("pre:") - 1) == 0) + memcmp(p, "pre:", sizeof("pre:") - 1) == 0) mode = S_PRE; else if (plen == sizeof("post:") - 1 && - memcmp(p, "post:", sizeof("post:") - 1) == 0) + memcmp(p, "post:", sizeof("post:") - 1) == 0) mode = S_POST; else if (*s != '\0' || (*s == '\0' && !was_space)) { if (mode == S_PRE) { @@ -394,9 +395,8 @@ static int kmod_config_add_softdep(struct kmod_config *config, return 0; } -static int kmod_config_add_weakdep(struct kmod_config *config, - const char *modname, - const char *line) +static int kmod_config_add_weakdep(struct kmod_config *config, const char *modname, + const char *line) { struct kmod_list *list; struct kmod_weakdep *dep; @@ -410,7 +410,7 @@ static int kmod_config_add_weakdep(struct kmod_config *config, DBG(config->ctx, "modname=%s\n", modname); /* analyze and count */ - for (p = s = line; ; s++) { + for (p = s = line;; s++) { size_t plen; if (*s != '\0') { @@ -442,8 +442,7 @@ static int kmod_config_add_weakdep(struct kmod_config *config, DBG(config->ctx, "%u weak\n", n_weak); dep = malloc(sizeof(struct kmod_weakdep) + modnamelen + - n_weak * sizeof(const char *) + - buflen); + n_weak * sizeof(const char *) + buflen); if (dep == NULL) { ERR(config->ctx, "out-of-memory modname=%s\n", modname); return -ENOMEM; @@ -458,7 +457,7 @@ static int kmod_config_add_weakdep(struct kmod_config *config, itr = dep->name + modnamelen; n_weak = 0; was_space = false; - for (p = s = line; ; s++) { + for (p = s = line;; s++) { size_t plen; if (*s != '\0') { @@ -500,7 +499,8 @@ static int kmod_config_add_weakdep(struct kmod_config *config, return 0; } -static char *softdep_to_char(struct kmod_softdep *dep) { +static char *softdep_to_char(struct kmod_softdep *dep) +{ const size_t sz_preprefix = sizeof("pre: ") - 1; const size_t sz_postprefix = sizeof("post: ") - 1; size_t sz = 1; /* at least '\0' */ @@ -514,8 +514,7 @@ static char *softdep_to_char(struct kmod_softdep *dep) { */ if (dep->n_pre > 0) { start = dep->pre[0]; - end = dep->pre[dep->n_pre - 1] - + strlen(dep->pre[dep->n_pre - 1]); + end = dep->pre[dep->n_pre - 1] + strlen(dep->pre[dep->n_pre - 1]); sz_pre = end - start; sz += sz_pre + sz_preprefix; } else @@ -523,8 +522,7 @@ static char *softdep_to_char(struct kmod_softdep *dep) { if (dep->n_post > 0) { start = dep->post[0]; - end = dep->post[dep->n_post - 1] - + strlen(dep->post[dep->n_post - 1]); + end = dep->post[dep->n_post - 1] + strlen(dep->post[dep->n_post - 1]); sz_post = end - start; sz += sz_post + sz_postprefix; } else @@ -569,7 +567,8 @@ static char *softdep_to_char(struct kmod_softdep *dep) { return s; } -static char *weakdep_to_char(struct kmod_weakdep *dep) { +static char *weakdep_to_char(struct kmod_weakdep *dep) +{ size_t sz; const char *start, *end; char *s, *itr; @@ -580,8 +579,7 @@ static char *weakdep_to_char(struct kmod_weakdep *dep) { */ if (dep->n_weak > 0) { start = dep->weak[0]; - end = dep->weak[dep->n_weak - 1] - + strlen(dep->weak[dep->n_weak - 1]); + end = dep->weak[dep->n_weak - 1] + strlen(dep->weak[dep->n_weak - 1]); sz = end - start; } else sz = 0; @@ -607,22 +605,20 @@ static char *weakdep_to_char(struct kmod_weakdep *dep) { return s; } -static void kmod_config_free_softdep(struct kmod_config *config, - struct kmod_list *l) +static void kmod_config_free_softdep(struct kmod_config *config, struct kmod_list *l) { free(l->data); config->softdeps = kmod_list_remove(l); } -static void kmod_config_free_weakdep(struct kmod_config *config, - struct kmod_list *l) +static void kmod_config_free_weakdep(struct kmod_config *config, struct kmod_list *l) { free(l->data); config->weakdeps = kmod_list_remove(l); } -static void kcmdline_parse_result(struct kmod_config *config, char *modname, - char *param, char *value) +static void kcmdline_parse_result(struct kmod_config *config, char *modname, char *param, + char *value) { if (modname == NULL || param == NULL) return; @@ -639,7 +635,8 @@ static void kcmdline_parse_result(struct kmod_config *config, char *modname, } } else { if (underscores(modname) < 0) { - ERR(config->ctx, "Ignoring bad option on kernel command line while parsing module name: '%s'\n", + ERR(config->ctx, + "Ignoring bad option on kernel command line while parsing module name: '%s'\n", modname); } else { kmod_config_add_options(config, modname, param); @@ -651,7 +648,7 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) { char buf[KCMD_LINE_SIZE]; int fd, err; - char *p, *p_quote_start, *modname, *param = NULL, *value = NULL; + char *p, *p_quote_start, *modname, *param = NULL, *value = NULL; bool is_quoted = false, iter = true; enum state { STATE_IGNORE, @@ -661,7 +658,7 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) STATE_COMPLETE, } state; - fd = open("/proc/cmdline", O_RDONLY|O_CLOEXEC); + fd = open("/proc/cmdline", O_RDONLY | O_CLOEXEC); if (fd < 0) { err = -errno; DBG(config->ctx, "could not open '/proc/cmdline' for reading: %m\n"); @@ -672,7 +669,7 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) close(fd); if (err < 0) { ERR(config->ctx, "could not read from '/proc/cmdline': %s\n", - strerror(-err)); + strerror(-err)); return err; } @@ -762,7 +759,9 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) * vv v v * "parport\0dyndbg=file drivers/parport/ieee1284_ops.c +mpf" */ memmove(p_quote_start, modname, value - modname); - value--; modname--; param--; + value--; + modname--; + param--; *value = '"'; } kcmdline_parse_result(config, modname, param, value); @@ -780,8 +779,7 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) * Take an fd and own it. It will be closed on return. filename is used only * for debug messages */ -static int kmod_config_parse(struct kmod_config *config, int fd, - const char *filename) +static int kmod_config_parse(struct kmod_config *config, int fd, const char *filename) { struct kmod_ctx *ctx = config->ctx; char *line; @@ -837,8 +835,8 @@ static int kmod_config_parse(struct kmod_config *config, int fd, if (underscores(modname) < 0 || installcmd == NULL) goto syntax_error; - kmod_config_add_command(config, modname, installcmd, - cmd, &config->install_commands); + kmod_config_add_command(config, modname, installcmd, cmd, + &config->install_commands); } else if (streq(cmd, "remove")) { char *modname = strtok_r(NULL, "\t ", &saveptr); char *removecmd = strtok_r(NULL, "\0", &saveptr); @@ -846,8 +844,8 @@ static int kmod_config_parse(struct kmod_config *config, int fd, if (underscores(modname) < 0 || removecmd == NULL) goto syntax_error; - kmod_config_add_command(config, modname, removecmd, - cmd, &config->remove_commands); + kmod_config_add_command(config, modname, removecmd, cmd, + &config->remove_commands); } else if (streq(cmd, "softdep")) { char *modname = strtok_r(NULL, "\t ", &saveptr); char *softdeps = strtok_r(NULL, "\0", &saveptr); @@ -864,14 +862,13 @@ static int kmod_config_parse(struct kmod_config *config, int fd, goto syntax_error; kmod_config_add_weakdep(config, modname, weakdeps); - } else if (streq(cmd, "include") - || streq(cmd, "config")) { + } else if (streq(cmd, "include") || streq(cmd, "config")) { ERR(ctx, "%s: command %s is deprecated and not parsed anymore\n", - filename, cmd); + filename, cmd); } else { syntax_error: ERR(ctx, "%s line %u: ignoring bad line starting with '%s'\n", - filename, linenum, cmd); + filename, linenum, cmd); } done_next: @@ -896,12 +893,12 @@ void kmod_config_free(struct kmod_config *config) while (config->install_commands) { kmod_config_free_command(config, config->install_commands, - &config->install_commands); + &config->install_commands); } while (config->remove_commands) { kmod_config_free_command(config, config->remove_commands, - &config->remove_commands); + &config->remove_commands); } while (config->softdeps) @@ -910,15 +907,14 @@ void kmod_config_free(struct kmod_config *config) while (config->weakdeps) kmod_config_free_weakdep(config, config->weakdeps); - for (; config->paths != NULL; - config->paths = kmod_list_remove(config->paths)) + for (; config->paths != NULL; config->paths = kmod_list_remove(config->paths)) free(config->paths->data); free(config); } -static bool conf_files_filter_out(struct kmod_ctx *ctx, DIR *d, - const char *path, const char *fn) +static bool conf_files_filter_out(struct kmod_ctx *ctx, DIR *d, const char *path, + const char *fn) { size_t len = strlen(fn); struct stat st; @@ -935,8 +931,10 @@ static bool conf_files_filter_out(struct kmod_ctx *ctx, DIR *d, } if (S_ISDIR(st.st_mode)) { - ERR(ctx, "Directories inside directories are not supported: " - "%s/%s\n", path, fn); + ERR(ctx, + "Directories inside directories are not supported: " + "%s/%s\n", + path, fn); return true; } @@ -949,9 +947,8 @@ struct conf_file { char name[]; }; -static int conf_files_insert_sorted(struct kmod_ctx *ctx, - struct kmod_list **list, - const char *path, const char *name) +static int conf_files_insert_sorted(struct kmod_ctx *ctx, struct kmod_list **list, + const char *path, const char *name) { struct kmod_list *lpos, *tmp; struct conf_file *cf; @@ -972,8 +969,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx, } if (cmp == 0) { - DBG(ctx, "Ignoring duplicate config file: %s/%s\n", path, - name); + DBG(ctx, "Ignoring duplicate config file: %s/%s\n", path, name); return -EEXIST; } @@ -1008,8 +1004,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx, * Insert configuration files in @list, ignoring duplicates */ static int conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list, - const char *path, - unsigned long long *path_stamp) + const char *path, unsigned long long *path_stamp) { DIR *d; int err; @@ -1047,7 +1042,7 @@ static int conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list, } int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config, - const char * const *config_paths) + const char *const *config_paths) { struct kmod_config *config; struct kmod_list *list = NULL; @@ -1098,15 +1093,15 @@ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config, if (cf->is_single) { fn = cf->path; - } else if (snprintf(buf, sizeof(buf), "%s/%s", - cf->path, cf->name) >= (int)sizeof(buf)) { - ERR(ctx, "Error parsing %s/%s: path too long\n", - cf->path, cf->name); + } else if (snprintf(buf, sizeof(buf), "%s/%s", cf->path, cf->name) >= + (int)sizeof(buf)) { + ERR(ctx, "Error parsing %s/%s: path too long\n", cf->path, + cf->name); free(cf); continue; } - fd = open(fn, O_RDONLY|O_CLOEXEC); + fd = open(fn, O_RDONLY | O_CLOEXEC); DBG(ctx, "parsing file '%s' fd=%d\n", fn, fd); if (fd >= 0) @@ -1165,8 +1160,8 @@ static const char *weakdep_get_plain_weakdep(const struct kmod_list *l) return s; } -static struct kmod_config_iter *kmod_config_iter_new(const struct kmod_ctx* ctx, - enum config_type type) +static struct kmod_config_iter *kmod_config_iter_new(const struct kmod_ctx *ctx, + enum config_type type) { struct kmod_config_iter *iter = calloc(1, sizeof(*iter)); const struct kmod_config *config = kmod_get_config(ctx); @@ -1300,7 +1295,7 @@ KMOD_EXPORT const char *kmod_config_iter_get_value(const struct kmod_config_iter struct kmod_config_iter *i = (struct kmod_config_iter *)iter; free(i->data); - s = i->data = (void *) iter->get_value(iter->curr); + s = i->data = (void *)iter->get_value(iter->curr); } else s = iter->get_value(iter->curr); diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index e96fe26f..2954e59a 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -56,17 +56,15 @@ struct kmod_elf { //#define ENABLE_ELFDBG 1 #if defined(ENABLE_LOGGING) && defined(ENABLE_ELFDBG) -#define ELFDBG(elf, ...) \ - _elf_dbg(elf, __FILE__, __LINE__, __func__, __VA_ARGS__); +#define ELFDBG(elf, ...) _elf_dbg(elf, __FILE__, __LINE__, __func__, __VA_ARGS__); -static inline void _elf_dbg(const struct kmod_elf *elf, const char *fname, unsigned line, const char *func, const char *fmt, ...) +static inline void _elf_dbg(const struct kmod_elf *elf, const char *fname, unsigned line, + const char *func, const char *fmt, ...) { va_list args; - fprintf(stderr, "ELFDBG-%d%c: %s:%u %s() ", - (elf->class & KMOD_ELF_32) ? 32 : 64, - (elf->class & KMOD_ELF_MSB) ? 'M' : 'L', - fname, line, func); + fprintf(stderr, "ELFDBG-%d%c: %s:%u %s() ", (elf->class & KMOD_ELF_32) ? 32 : 64, + (elf->class & KMOD_ELF_MSB) ? 'M' : 'L', fname, line, func); va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); @@ -75,7 +73,6 @@ static inline void _elf_dbg(const struct kmod_elf *elf, const char *fname, unsig #define ELFDBG(elf, ...) #endif - static int elf_identify(const void *memory, uint64_t size) { const uint8_t *p = memory; @@ -113,7 +110,8 @@ static int elf_identify(const void *memory, uint64_t size) return class; } -static inline uint64_t elf_get_uint(const struct kmod_elf *elf, uint64_t offset, uint16_t size) +static inline uint64_t elf_get_uint(const struct kmod_elf *elf, uint64_t offset, + uint16_t size) { const uint8_t *p; uint64_t ret = 0; @@ -122,7 +120,9 @@ static inline uint64_t elf_get_uint(const struct kmod_elf *elf, uint64_t offset, assert(size <= sizeof(uint64_t)); assert(offset + size <= elf->size); if (offset + size > elf->size) { - ELFDBG(elf, "out of bounds: %"PRIu64" + %"PRIu16" = %"PRIu64"> %"PRIu64" (ELF size)\n", + ELFDBG(elf, + "out of bounds: %" PRIu64 " + %" PRIu16 " = %" PRIu64 "> %" PRIu64 + " (ELF size)\n", offset, size, offset + size, elf->size); return (uint64_t)-1; } @@ -136,24 +136,28 @@ static inline uint64_t elf_get_uint(const struct kmod_elf *elf, uint64_t offset, ret = (ret << 8) | p[size - i]; } - ELFDBG(elf, "size=%"PRIu16" offset=%"PRIu64" value=%"PRIu64"\n", - size, offset, ret); + ELFDBG(elf, "size=%" PRIu16 " offset=%" PRIu64 " value=%" PRIu64 "\n", size, + offset, ret); return ret; } -static inline int elf_set_uint(struct kmod_elf *elf, uint64_t offset, uint64_t size, uint64_t value) +static inline int elf_set_uint(struct kmod_elf *elf, uint64_t offset, uint64_t size, + uint64_t value) { uint8_t *p; size_t i; - ELFDBG(elf, "size=%"PRIu16" offset=%"PRIu64" value=%"PRIu64" write memory=%p\n", + ELFDBG(elf, + "size=%" PRIu16 " offset=%" PRIu64 " value=%" PRIu64 " write memory=%p\n", size, offset, value, elf->changed); assert(size <= sizeof(uint64_t)); assert(offset + size <= elf->size); if (offset + size > elf->size) { - ELFDBG(elf, "out of bounds: %"PRIu64" + %"PRIu16" = %"PRIu64"> %"PRIu64" (ELF size)\n", + ELFDBG(elf, + "out of bounds: %" PRIu64 " + %" PRIu16 " = %" PRIu64 "> %" PRIu64 + " (ELF size)\n", offset, size, offset + size, elf->size); return -1; } @@ -187,7 +191,7 @@ static inline const void *elf_get_mem(const struct kmod_elf *elf, uint64_t offse { assert(offset < elf->size); if (offset >= elf->size) { - ELFDBG(elf, "out-of-bounds: %"PRIu64" >= %"PRIu64" (ELF size)\n", + ELFDBG(elf, "out-of-bounds: %" PRIu64 " >= %" PRIu64 " (ELF size)\n", offset, elf->size); return NULL; } @@ -199,21 +203,23 @@ static inline const void *elf_get_section_header(const struct kmod_elf *elf, uin assert(idx != SHN_UNDEF); assert(idx < elf->header.section.count); if (idx == SHN_UNDEF || idx >= elf->header.section.count) { - ELFDBG(elf, "invalid section number: %"PRIu16", last=%"PRIu16"\n", + ELFDBG(elf, "invalid section number: %" PRIu16 ", last=%" PRIu16 "\n", idx, elf->header.section.count); return NULL; } return elf_get_mem(elf, elf->header.section.offset + - (uint64_t)(idx * elf->header.section.entry_size)); + (uint64_t)(idx * elf->header.section.entry_size)); } -static inline int elf_get_section_info(const struct kmod_elf *elf, uint16_t idx, uint64_t *offset, uint64_t *size, uint32_t *nameoff) +static inline int elf_get_section_info(const struct kmod_elf *elf, uint16_t idx, + uint64_t *offset, uint64_t *size, + uint32_t *nameoff) { const uint8_t *p = elf_get_section_header(elf, idx); uint64_t min_size, off = p - elf->memory; if (p == NULL) { - ELFDBG(elf, "no section at %"PRIu16"\n", idx); + ELFDBG(elf, "no section at %" PRIu16 "\n", idx); *offset = 0; *size = 0; *nameoff = 0; @@ -236,14 +242,15 @@ static inline int elf_get_section_info(const struct kmod_elf *elf, uint16_t idx, } #undef READV - if (addu64_overflow(*offset, *size, &min_size) - || min_size > elf->size) { - ELFDBG(elf, "out-of-bounds: %"PRIu64" >= %"PRIu64" (ELF size)\n", + if (addu64_overflow(*offset, *size, &min_size) || min_size > elf->size) { + ELFDBG(elf, "out-of-bounds: %" PRIu64 " >= %" PRIu64 " (ELF size)\n", min_size, elf->size); return -EINVAL; } - ELFDBG(elf, "section=%"PRIu16" is: offset=%"PRIu64" size=%"PRIu64" nameoff=%"PRIu32"\n", + ELFDBG(elf, + "section=%" PRIu16 " is: offset=%" PRIu64 " size=%" PRIu64 + " nameoff=%" PRIu32 "\n", idx, *offset, *size, *nameoff); return 0; @@ -288,14 +295,13 @@ struct kmod_elf *kmod_elf_new(const void *memory, off_t size) elf->size = size; elf->class = class; -#define READV(field) \ - elf_get_uint(elf, offsetof(typeof(*hdr), field), sizeof(hdr->field)) +#define READV(field) elf_get_uint(elf, offsetof(typeof(*hdr), field), sizeof(hdr->field)) -#define LOAD_HEADER \ - elf->header.section.offset = READV(e_shoff); \ - elf->header.section.count = READV(e_shnum); \ - elf->header.section.entry_size = READV(e_shentsize); \ - elf->header.strings.section = READV(e_shstrndx); \ +#define LOAD_HEADER \ + elf->header.section.offset = READV(e_shoff); \ + elf->header.section.count = READV(e_shnum); \ + elf->header.section.entry_size = READV(e_shentsize); \ + elf->header.strings.section = READV(e_shstrndx); \ elf->header.machine = READV(e_machine) if (elf->class & KMOD_ELF_32) { const Elf32_Ehdr *hdr _unused_ = elf_get_mem(elf, 0); @@ -309,28 +315,29 @@ struct kmod_elf *kmod_elf_new(const void *memory, off_t size) #undef LOAD_HEADER #undef READV - ELFDBG(elf, "section: offset=%"PRIu64" count=%"PRIu16" entry_size=%"PRIu16" strings index=%"PRIu16"\n", - elf->header.section.offset, - elf->header.section.count, - elf->header.section.entry_size, - elf->header.strings.section); + ELFDBG(elf, + "section: offset=%" PRIu64 " count=%" PRIu16 " entry_size=%" PRIu16 + " strings index=%" PRIu16 "\n", + elf->header.section.offset, elf->header.section.count, + elf->header.section.entry_size, elf->header.strings.section); if (elf->header.section.entry_size != shdr_size) { - ELFDBG(elf, "unexpected section entry size: %"PRIu16", expected %"PRIu16"\n", + ELFDBG(elf, + "unexpected section entry size: %" PRIu16 ", expected %" PRIu16 + "\n", elf->header.section.entry_size, shdr_size); goto invalid; } shdrs_size = shdr_size * elf->header.section.count; - if (addu64_overflow(shdrs_size, elf->header.section.offset, &min_size) - || min_size > elf->size) { + if (addu64_overflow(shdrs_size, elf->header.section.offset, &min_size) || + min_size > elf->size) { ELFDBG(elf, "file is too short to hold sections\n"); goto invalid; } if (elf_get_section_info(elf, elf->header.strings.section, - &elf->header.strings.offset, - &elf->header.strings.size, - &elf->header.strings.nameoff) < 0) { + &elf->header.strings.offset, &elf->header.strings.size, + &elf->header.strings.nameoff) < 0) { ELFDBG(elf, "could not get strings section\n"); goto invalid; } else { @@ -386,7 +393,8 @@ static int elf_find_section(const struct kmod_elf *elf, const char *section) return -ENODATA; } -int kmod_elf_get_section(const struct kmod_elf *elf, const char *section, const void **buf, uint64_t *buf_size) +int kmod_elf_get_section(const struct kmod_elf *elf, const char *section, + const void **buf, uint64_t *buf_size) { uint64_t nameslen; const char *names = elf_get_strings_section(elf, &nameslen); @@ -445,7 +453,7 @@ int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char * if (size <= 1) return 0; - for (i = 0, count = 0; i < size; ) { + for (i = 0, count = 0; i < size;) { if (strings[i] != '\0') { i++; continue; @@ -472,7 +480,7 @@ int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char * a[count] = NULL; a[0] = s; - for (i = 0, j = 1; j < count && i < size; ) { + for (i = 0, j = 1; j < count && i < size;) { if (s[i] != '\0') { i++; continue; @@ -499,8 +507,7 @@ int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion int i, count, err; #define MODVERSION_SEC_SIZE (sizeof(struct kmod_modversion64)) - assert_cc(sizeof(struct kmod_modversion64) == - sizeof(struct kmod_modversion32)); + assert_cc(sizeof(struct kmod_modversion64) == sizeof(struct kmod_modversion32)); if (elf->class & KMOD_ELF_32) offcrc = sizeof(uint32_t); @@ -637,8 +644,7 @@ int kmod_elf_strip_vermagic(struct kmod_elf *elf) } len = strlen(s); - ELFDBG(elf, "clear .modinfo vermagic \"%s\" (%zd bytes)\n", - s, len); + ELFDBG(elf, "clear .modinfo vermagic \"%s\" (%zd bytes)\n", s, len); memset(elf->changed + off, '\0', len); return 0; } @@ -647,8 +653,8 @@ int kmod_elf_strip_vermagic(struct kmod_elf *elf) return -ENODATA; } - -static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf, struct kmod_modversion **array) +static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf, + struct kmod_modversion **array) { uint64_t i, last, size; const void *buf; @@ -738,7 +744,8 @@ static inline uint8_t kmod_symbol_bind_from_elf(uint8_t elf_value) } } -static uint64_t kmod_elf_resolve_crc(const struct kmod_elf *elf, uint64_t crc, uint16_t shndx) +static uint64_t kmod_elf_resolve_crc(const struct kmod_elf *elf, uint64_t crc, + uint16_t shndx) { int err; uint64_t off, size; @@ -749,12 +756,13 @@ static uint64_t kmod_elf_resolve_crc(const struct kmod_elf *elf, uint64_t crc, u err = elf_get_section_info(elf, shndx, &off, &size, &nameoff); if (err < 0) { - ELFDBG("Could not find section index %"PRIu16" for crc", shndx); + ELFDBG("Could not find section index %" PRIu16 " for crc", shndx); return (uint64_t)-1; } if (crc > (size - sizeof(uint32_t))) { - ELFDBG("CRC offset %"PRIu64" is too big, section %"PRIu16" size is %"PRIu64"\n", + ELFDBG("CRC offset %" PRIu64 " is too big, section %" PRIu16 + " size is %" PRIu64 "\n", crc, shndx, size); return (uint64_t)-1; } @@ -793,7 +801,10 @@ int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **ar symlen = sizeof(Elf64_Sym); if (symtablen % symlen != 0) { - ELFDBG(elf, "unexpected .symtab of length %"PRIu64", not multiple of %"PRIu64" as expected.\n", symtablen, symlen); + ELFDBG(elf, + "unexpected .symtab of length %" PRIu64 + ", not multiple of %" PRIu64 " as expected.\n", + symtablen, symlen); goto fallback; } @@ -806,9 +817,8 @@ int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **ar const char *name; uint32_t name_off; -#define READV(field) \ - elf_get_uint(elf, sym_off + offsetof(typeof(*s), field),\ - sizeof(s->field)) +#define READV(field) \ + elf_get_uint(elf, sym_off + offsetof(typeof(*s), field), sizeof(s->field)) if (elf->class & KMOD_ELF_32) { Elf32_Sym *s; name_off = READV(st_name); @@ -818,7 +828,11 @@ int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **ar } #undef READV if (name_off >= strtablen) { - ELFDBG(elf, ".strtab is %"PRIu64" bytes, but .symtab entry %d wants to access offset %"PRIu32".\n", strtablen, i, name_off); + ELFDBG(elf, + ".strtab is %" PRIu64 + " bytes, but .symtab entry %d wants to access offset %" PRIu32 + ".\n", + strtablen, i, name_off); goto fallback; } @@ -848,9 +862,8 @@ int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **ar uint8_t info, bind; uint16_t shndx; -#define READV(field) \ - elf_get_uint(elf, sym_off + offsetof(typeof(*s), field),\ - sizeof(s->field)) +#define READV(field) \ + elf_get_uint(elf, sym_off + offsetof(typeof(*s), field), sizeof(s->field)) if (elf->class & KMOD_ELF_32) { Elf32_Sym *s; name_off = READV(st_name); @@ -891,7 +904,8 @@ fallback: return kmod_elf_get_symbols_symtab(elf, array); } -static int kmod_elf_crc_find(const struct kmod_elf *elf, const void *versions, uint64_t versionslen, const char *name, uint64_t *crc) +static int kmod_elf_crc_find(const struct kmod_elf *elf, const void *versions, + uint64_t versionslen, const char *name, uint64_t *crc) { size_t verlen, crclen, off; uint64_t i; @@ -922,11 +936,12 @@ static int kmod_elf_crc_find(const struct kmod_elf *elf, const void *versions, u /* from module-init-tools:elfops_core.c */ #ifndef STT_REGISTER -#define STT_REGISTER 13 /* Global register reserved to app. */ +#define STT_REGISTER 13 /* Global register reserved to app. */ #endif /* array will be allocated with strings in a single malloc, just free *array */ -int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) +int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, + struct kmod_modversion **array) { uint64_t versionslen, strtablen, symtablen, str_off, sym_off, ver_off; const void *versions, *strtab, *symtab; @@ -955,7 +970,10 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modv crclen = sizeof(mv->crc); } if (versionslen % verlen != 0) { - ELFDBG(elf, "unexpected __versions of length %"PRIu64", not multiple of %zd as expected.\n", versionslen, verlen); + ELFDBG(elf, + "unexpected __versions of length %" PRIu64 + ", not multiple of %zd as expected.\n", + versionslen, verlen); versions = NULL; versionslen = 0; } @@ -979,7 +997,10 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modv symlen = sizeof(Elf64_Sym); if (symtablen % symlen != 0) { - ELFDBG(elf, "unexpected .symtab of length %"PRIu64", not multiple of %"PRIu64" as expected.\n", symtablen, symlen); + ELFDBG(elf, + "unexpected .symtab of length %" PRIu64 + ", not multiple of %" PRIu64 " as expected.\n", + symtablen, symlen); return -EINVAL; } @@ -993,8 +1014,8 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modv return -ENOMEM; } - handle_register_symbols = (elf->header.machine == EM_SPARC || - elf->header.machine == EM_SPARCV9); + handle_register_symbols = + (elf->header.machine == EM_SPARC || elf->header.machine == EM_SPARCV9); symcount = symtablen / symlen; count = 0; @@ -1016,9 +1037,8 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modv uint8_t info; int idx; -#define READV(field) \ - elf_get_uint(elf, sym_off + offsetof(typeof(*s), field),\ - sizeof(s->field)) +#define READV(field) \ + elf_get_uint(elf, sym_off + offsetof(typeof(*s), field), sizeof(s->field)) if (elf->class & KMOD_ELF_32) { Elf32_Sym *s; name_off = READV(st_name); @@ -1051,7 +1071,11 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modv } if (name_off >= strtablen) { - ELFDBG(elf, ".strtab is %"PRIu64" bytes, but .symtab entry %d wants to access offset %"PRIu32".\n", strtablen, i, name_off); + ELFDBG(elf, + ".strtab is %" PRIu64 + " bytes, but .symtab entry %d wants to access offset %" PRIu32 + ".\n", + strtablen, i, name_off); free(visited_versions); free(symcrcs); return -EINVAL; @@ -1059,7 +1083,7 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modv name = elf_get_mem(elf, str_off + name_off); if (name[0] == '\0') { - ELFDBG(elf, "empty symbol name at index %"PRIu64"\n", i); + ELFDBG(elf, "empty symbol name at index %" PRIu64 "\n", i); continue; } @@ -1111,9 +1135,8 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modv uint16_t secidx; uint8_t info, bind; -#define READV(field) \ - elf_get_uint(elf, sym_off + offsetof(typeof(*s), field),\ - sizeof(s->field)) +#define READV(field) \ + elf_get_uint(elf, sym_off + offsetof(typeof(*s), field), sizeof(s->field)) if (elf->class & KMOD_ELF_32) { Elf32_Sym *s; name_off = READV(st_name); @@ -1147,7 +1170,7 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modv name = elf_get_mem(elf, str_off + name_off); if (name[0] == '\0') { - ELFDBG(elf, "empty symbol name at index %"PRIu64"\n", i); + ELFDBG(elf, "empty symbol name at index %" PRIu64 "\n", i); continue; } diff --git a/libkmod/libkmod-file-xz.c b/libkmod/libkmod-file-xz.c index 7285c4b0..636ef707 100644 --- a/libkmod/libkmod-file-xz.c +++ b/libkmod/libkmod-file-xz.c @@ -50,8 +50,8 @@ static int xz_uncompress(lzma_stream *strm, struct kmod_file *file) void *p = NULL; size_t total = 0; - strm->avail_in = 0; - strm->next_out = out_buf; + strm->avail_in = 0; + strm->next_out = out_buf; strm->avail_out = sizeof(out_buf); while (true) { @@ -61,7 +61,7 @@ static int xz_uncompress(lzma_stream *strm, struct kmod_file *file) ret = -errno; goto out; } - strm->next_in = in_buf; + strm->next_in = in_buf; strm->avail_in = rdret; if (rdret == 0) action = LZMA_FINISH; @@ -91,7 +91,7 @@ static int xz_uncompress(lzma_stream *strm, struct kmod_file *file) file->memory = p; file->size = total; return 0; - out: +out: free(p); return ret; } diff --git a/libkmod/libkmod-file-zlib.c b/libkmod/libkmod-file-zlib.c index 80c7bfea..54b39a8e 100644 --- a/libkmod/libkmod-file-zlib.c +++ b/libkmod/libkmod-file-zlib.c @@ -78,4 +78,3 @@ error: gzclose(gzf); /* closes the gzfd */ return err; } - diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index f15998d5..fe2bd05d 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -20,9 +20,9 @@ #include "libkmod-internal.h" #include "libkmod-internal-file.h" -static const char magic_zstd[] = {0x28, 0xB5, 0x2F, 0xFD}; -static const char magic_xz[] = {0xfd, '7', 'z', 'X', 'Z', 0}; -static const char magic_zlib[] = {0x1f, 0x8b}; +static const char magic_zstd[] = { 0x28, 0xB5, 0x2F, 0xFD }; +static const char magic_xz[] = { 0xfd, '7', 'z', 'X', 'Z', 0 }; +static const char magic_zlib[] = { 0x1f, 0x8b }; static int load_reg(struct kmod_file *file) { @@ -35,8 +35,7 @@ static int load_reg(struct kmod_file *file) if ((uintmax_t)file->size > SIZE_MAX) return -ENOMEM; - file->memory = mmap(NULL, file->size, PROT_READ, MAP_PRIVATE, - file->fd, 0); + file->memory = mmap(NULL, file->size, PROT_READ, MAP_PRIVATE, file->fd, 0); if (file->memory == MAP_FAILED) { file->memory = NULL; return -errno; @@ -76,8 +75,7 @@ struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) return file->elf; } -struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, - const char *filename) +struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) { struct kmod_file *file; char buf[7]; @@ -91,7 +89,7 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, if (file == NULL) return NULL; - file->fd = open(filename, O_RDONLY|O_CLOEXEC); + file->fd = open(filename, O_RDONLY | O_CLOEXEC); if (file->fd < 0) { free(file); return NULL; diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index ee9b393d..949a7839 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -35,7 +35,7 @@ #define INDEX_MAGIC 0xB007F457 #define INDEX_VERSION_MAJOR 0x0002 #define INDEX_VERSION_MINOR 0x0001 -#define INDEX_VERSION ((INDEX_VERSION_MAJOR<<16)|INDEX_VERSION_MINOR) +#define INDEX_VERSION ((INDEX_VERSION_MAJOR << 16) | INDEX_VERSION_MINOR) /* The index file maps keys to values. Both keys and values are ASCII strings. * Each key can have multiple values. Values are sorted by an integer priority. @@ -127,12 +127,12 @@ /* Format of node offsets within index file */ enum node_offset { - INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */ - INDEX_NODE_PREFIX = 0x80000000, + INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */ + INDEX_NODE_PREFIX = 0x80000000, INDEX_NODE_VALUES = 0x40000000, - INDEX_NODE_CHILDS = 0x20000000, + INDEX_NODE_CHILDS = 0x20000000, - INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */ + INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */ }; void index_values_free(struct index_value *values) @@ -145,8 +145,8 @@ void index_values_free(struct index_value *values) } } -static int add_value(struct index_value **values, - const char *value, unsigned len, unsigned int priority) +static int add_value(struct index_value **values, const char *value, unsigned len, + unsigned int priority) { struct index_value *v; @@ -210,9 +210,9 @@ static ssize_t buf_freadchars(struct strbuf *buf, FILE *in) */ struct index_node_f { FILE *file; - char *prefix; /* path compression */ + char *prefix; /* path compression */ struct index_value *values; - unsigned char first; /* range of child nodes */ + unsigned char first; /* range of child nodes */ unsigned char last; uint32_t children[0]; }; @@ -257,8 +257,8 @@ static struct index_node_f *index_read(FILE *in, uint32_t offset) if (node == NULL) goto err; - node->first = (unsigned char) first; - node->last = (unsigned char) last; + node->first = (unsigned char)first; + node->last = (unsigned char)last; for (i = 0; i < child_count; i++) if (read_u32(in, &node->children[i]) < 0) @@ -284,8 +284,7 @@ static struct index_node_f *index_read(FILE *in, uint32_t offset) strbuf_init(&buf); while (value_count--) { - if (read_u32(in, &priority) < 0 || - buf_freadchars(&buf, in) < 0) { + if (read_u32(in, &priority) < 0 || buf_freadchars(&buf, in) < 0) { strbuf_release(&buf); goto err; } @@ -331,8 +330,7 @@ struct index_file *index_file_open(const char *filename) if (read_u32(file, &magic) < 0 || magic != INDEX_MAGIC) goto err; - if (read_u32(file, &version) < 0 || - version >> 16 != INDEX_VERSION_MAJOR) + if (read_u32(file, &version) < 0 || version >> 16 != INDEX_VERSION_MAJOR) goto err; new = malloc(sizeof(struct index_file)); @@ -361,19 +359,16 @@ static struct index_node_f *index_readroot(struct index_file *in) return index_read(in->file, in->root_offset); } -static struct index_node_f *index_readchild(const struct index_node_f *parent, - int ch) +static struct index_node_f *index_readchild(const struct index_node_f *parent, int ch) { if (parent->first <= ch && ch <= parent->last) { - return index_read(parent->file, - parent->children[ch - parent->first]); + return index_read(parent->file, parent->children[ch - parent->first]); } return NULL; } -static void index_dump_node(struct index_node_f *node, struct strbuf *buf, - int fd) +static void index_dump_node(struct index_node_f *node, struct strbuf *buf, int fd) { struct index_value *v; size_t pushed; @@ -425,11 +420,11 @@ static char *index_search__node(struct index_node_f *node, const char *key, int int ch; int j; - while(node) { + while (node) { for (j = 0; node->prefix[j]; j++) { ch = node->prefix[j]; - if (ch != key[i+j]) { + if (ch != key[i + j]) { index_close(node); return NULL; } @@ -438,9 +433,8 @@ static char *index_search__node(struct index_node_f *node, const char *key, int i += j; if (key[i] == '\0') { - value = node->values != NULL - ? strdup(node->values[0].value) - : NULL; + value = node->values != NULL ? strdup(node->values[0].value) : + NULL; index_close(node); return value; @@ -464,7 +458,7 @@ static char *index_search__node(struct index_node_f *node, const char *key, int */ char *index_search(struct index_file *in, const char *key) { -// FIXME: return value by reference instead of strdup + // FIXME: return value by reference instead of strdup struct index_node_f *root; char *value; @@ -474,8 +468,6 @@ char *index_search(struct index_file *in, const char *key) return value; } - - /* Level 4: add all the values from a matching node */ static void index_searchwild__allvalues(struct index_node_f *node, struct index_value **out) @@ -492,10 +484,8 @@ static void index_searchwild__allvalues(struct index_node_f *node, * Level 3: traverse a sub-keyspace which starts with a wildcard, * looking for matches. */ -static void index_searchwild__all(struct index_node_f *node, int j, - struct strbuf *buf, - const char *subkey, - struct index_value **out) +static void index_searchwild__all(struct index_node_f *node, int j, struct strbuf *buf, + const char *subkey, struct index_value **out) { size_t pushed = 0; int ch; @@ -532,26 +522,23 @@ static void index_searchwild__all(struct index_node_f *node, int j, } /* Level 2: descend the tree (until we hit a wildcard) */ -static void index_searchwild__node(struct index_node_f *node, - struct strbuf *buf, - const char *key, int i, - struct index_value **out) +static void index_searchwild__node(struct index_node_f *node, struct strbuf *buf, + const char *key, int i, struct index_value **out) { struct index_node_f *child; int j; int ch; - while(node) { + while (node) { for (j = 0; node->prefix[j]; j++) { ch = node->prefix[j]; if (ch == '*' || ch == '?' || ch == '[') { - index_searchwild__all(node, j, buf, - &key[i+j], out); + index_searchwild__all(node, j, buf, &key[i + j], out); return; } - if (ch != key[i+j]) { + if (ch != key[i + j]) { index_close(node); return; } @@ -654,7 +641,7 @@ static inline uint32_t read_u32_mm(void **p) uint32_t v; /* addr may be unalined to uint32_t */ - v = get_unaligned((uint32_t *) addr); + v = get_unaligned((uint32_t *)addr); *p = addr + sizeof(uint32_t); return ntohl(v); @@ -676,8 +663,8 @@ static inline char *read_chars_mm(void **p, unsigned *rlen) return addr; } -static struct index_mm_node *index_mm_read_node(struct index_mm *idx, - uint32_t offset) { +static struct index_mm_node *index_mm_read_node(struct index_mm *idx, uint32_t offset) +{ void *p = idx->mm; struct index_mm_node *node; const char *prefix; @@ -712,17 +699,17 @@ static struct index_mm_node *index_mm_read_node(struct index_mm *idx, child_count = 0; } - children_padding = (sizeof(struct index_mm_node) + - (sizeof(uint32_t) * child_count)) % sizeof(void *); + children_padding = + (sizeof(struct index_mm_node) + (sizeof(uint32_t) * child_count)) % + sizeof(void *); if (offset & INDEX_NODE_VALUES) value_count = read_u32_mm(&p); else value_count = 0; - node = malloc(sizeof(struct index_mm_node) - + sizeof(uint32_t) * child_count + children_padding - + sizeof(struct index_mm_value) * value_count); + node = malloc(sizeof(struct index_mm_node) + sizeof(uint32_t) * child_count + + children_padding + sizeof(struct index_mm_value) * value_count); if (node == NULL) return NULL; @@ -731,9 +718,11 @@ static struct index_mm_node *index_mm_read_node(struct index_mm *idx, if (value_count == 0) node->values.values = NULL; else { - node->values.values = (struct index_mm_value *) - ((char *)node + sizeof(struct index_mm_node) + - sizeof(uint32_t) * child_count + children_padding); + node->values.values = + (struct index_mm_value *)((char *)node + + sizeof(struct index_mm_node) + + sizeof(uint32_t) * child_count + + children_padding); } node->values.len = value_count; node->first = first; @@ -777,13 +766,13 @@ int index_mm_open(const struct kmod_ctx *ctx, const char *filename, return -ENOMEM; } - if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) { + if ((fd = open(filename, O_RDONLY | O_CLOEXEC)) < 0) { DBG(ctx, "open(%s, O_RDONLY|O_CLOEXEC): %m\n", filename); err = -errno; goto fail_open; } - if (fstat(fd, &st) < 0 || st.st_size < (off_t) sizeof(hdr)) { + if (fstat(fd, &st) < 0 || st.st_size < (off_t)sizeof(hdr)) { err = -EINVAL; goto fail_nommap; } @@ -795,8 +784,8 @@ int index_mm_open(const struct kmod_ctx *ctx, const char *filename, idx->mm = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (idx->mm == MAP_FAILED) { - ERR(ctx, "mmap(NULL, %"PRIu64", PROT_READ, MAP_PRIVATE, %d, 0): %m\n", - (uint64_t) st.st_size, fd); + ERR(ctx, "mmap(NULL, %" PRIu64 ", PROT_READ, MAP_PRIVATE, %d, 0): %m\n", + (uint64_t)st.st_size, fd); err = -errno; goto fail_nommap; } @@ -807,15 +796,14 @@ int index_mm_open(const struct kmod_ctx *ctx, const char *filename, hdr.root_offset = read_u32_mm(&p); if (hdr.magic != INDEX_MAGIC) { - ERR(ctx, "magic check fail: %x instead of %x\n", hdr.magic, - INDEX_MAGIC); + ERR(ctx, "magic check fail: %x instead of %x\n", hdr.magic, INDEX_MAGIC); err = -EINVAL; goto fail; } if (hdr.version >> 16 != INDEX_VERSION_MAJOR) { ERR(ctx, "major version check fail: %u instead of %u\n", - hdr.version >> 16, INDEX_VERSION_MAJOR); + hdr.version >> 16, INDEX_VERSION_MAJOR); err = -EINVAL; goto fail; } @@ -850,19 +838,17 @@ static struct index_mm_node *index_mm_readroot(struct index_mm *idx) return index_mm_read_node(idx, idx->root_offset); } -static struct index_mm_node *index_mm_readchild(const struct index_mm_node *parent, - int ch) +static struct index_mm_node *index_mm_readchild(const struct index_mm_node *parent, int ch) { if (parent->first <= ch && ch <= parent->last) { return index_mm_read_node(parent->idx, - parent->children[ch - parent->first]); + parent->children[ch - parent->first]); } return NULL; } -static void index_mm_dump_node(struct index_mm_node *node, struct strbuf *buf, - int fd) +static void index_mm_dump_node(struct index_mm_node *node, struct strbuf *buf, int fd) { struct index_mm_value *itr, *itr_end; size_t pushed; @@ -909,19 +895,18 @@ void index_mm_dump(struct index_mm *idx, int fd, const char *prefix) strbuf_release(&buf); } -static char *index_mm_search_node(struct index_mm_node *node, const char *key, - int i) +static char *index_mm_search_node(struct index_mm_node *node, const char *key, int i) { char *value; struct index_mm_node *child; int ch; int j; - while(node) { + while (node) { for (j = 0; node->prefix[j]; j++) { ch = node->prefix[j]; - if (ch != key[i+j]) { + if (ch != key[i + j]) { index_mm_free_node(node); return NULL; } @@ -930,9 +915,9 @@ static char *index_mm_search_node(struct index_mm_node *node, const char *key, i += j; if (key[i] == '\0') { - value = node->values.len > 0 - ? strdup(node->values.values[0].value) - : NULL; + value = node->values.len > 0 ? + strdup(node->values.values[0].value) : + NULL; index_mm_free_node(node); return value; @@ -956,7 +941,7 @@ static char *index_mm_search_node(struct index_mm_node *node, const char *key, */ char *index_mm_search(struct index_mm *idx, const char *key) { -// FIXME: return value by reference instead of strdup + // FIXME: return value by reference instead of strdup struct index_mm_node *root; char *value; @@ -968,7 +953,7 @@ char *index_mm_search(struct index_mm *idx, const char *key) /* Level 4: add all the values from a matching node */ static void index_mm_searchwild_allvalues(struct index_mm_node *node, - struct index_value **out) + struct index_value **out) { struct index_mm_value *itr, *itr_end; @@ -984,10 +969,8 @@ static void index_mm_searchwild_allvalues(struct index_mm_node *node, * Level 3: traverse a sub-keyspace which starts with a wildcard, * looking for matches. */ -static void index_mm_searchwild_all(struct index_mm_node *node, int j, - struct strbuf *buf, - const char *subkey, - struct index_value **out) +static void index_mm_searchwild_all(struct index_mm_node *node, int j, struct strbuf *buf, + const char *subkey, struct index_value **out) { size_t pushed = 0; int ch; @@ -1024,26 +1007,23 @@ static void index_mm_searchwild_all(struct index_mm_node *node, int j, } /* Level 2: descend the tree (until we hit a wildcard) */ -static void index_mm_searchwild_node(struct index_mm_node *node, - struct strbuf *buf, - const char *key, int i, - struct index_value **out) +static void index_mm_searchwild_node(struct index_mm_node *node, struct strbuf *buf, + const char *key, int i, struct index_value **out) { struct index_mm_node *child; int j; int ch; - while(node) { + while (node) { for (j = 0; node->prefix[j]; j++) { ch = node->prefix[j]; if (ch == '*' || ch == '?' || ch == '[') { - index_mm_searchwild_all(node, j, buf, - &key[i+j], out); + index_mm_searchwild_all(node, j, buf, &key[i + j], out); return; } - if (ch != key[i+j]) { + if (ch != key[i + j]) { index_mm_free_node(node); return; } diff --git a/libkmod/libkmod-internal-file.h b/libkmod/libkmod-internal-file.h index 36cd3277..d633822f 100644 --- a/libkmod/libkmod-internal-file.h +++ b/libkmod/libkmod-internal-file.h @@ -23,17 +23,26 @@ struct kmod_file { #ifdef ENABLE_XZ int kmod_file_load_xz(struct kmod_file *file); #else -static inline int kmod_file_load_xz(struct kmod_file *file) { return -ENOSYS; } +static inline int kmod_file_load_xz(struct kmod_file *file) +{ + return -ENOSYS; +} #endif #ifdef ENABLE_ZLIB int kmod_file_load_zlib(struct kmod_file *file); #else -static inline int kmod_file_load_zlib(struct kmod_file *file) { return -ENOSYS; } +static inline int kmod_file_load_zlib(struct kmod_file *file) +{ + return -ENOSYS; +} #endif #ifdef ENABLE_ZSTD int kmod_file_load_zstd(struct kmod_file *file); #else -static inline int kmod_file_load_zstd(struct kmod_file *file) { return -ENOSYS; } +static inline int kmod_file_load_zstd(struct kmod_file *file) +{ + return -ENOSYS; +} #endif diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h index 7082487c..6210660c 100644 --- a/libkmod/libkmod-internal.h +++ b/libkmod/libkmod-internal.h @@ -10,32 +10,34 @@ #include "libkmod.h" -static _always_inline_ _printf_format_(2, 3) void - kmod_log_null(const struct kmod_ctx *ctx, const char *format, ...) {} - -#define kmod_log_cond(ctx, prio, arg...) \ - do { \ - if (kmod_get_log_priority(ctx) >= prio) \ - kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ## arg);\ +static _always_inline_ _printf_format_(2, 3) void kmod_log_null(const struct kmod_ctx *ctx, + const char *format, ...) +{ +} + +#define kmod_log_cond(ctx, prio, arg...) \ + do { \ + if (kmod_get_log_priority(ctx) >= prio) \ + kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ##arg); \ } while (0) #ifdef ENABLE_LOGGING -# ifdef ENABLE_DEBUG -# define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg) -# else -# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg) -# endif -# define NOTICE(ctx, arg...) kmod_log_cond(ctx, LOG_NOTICE, ## arg) -# define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg) -# define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg) +#ifdef ENABLE_DEBUG +#define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ##arg) +#else +#define DBG(ctx, arg...) kmod_log_null(ctx, ##arg) +#endif +#define NOTICE(ctx, arg...) kmod_log_cond(ctx, LOG_NOTICE, ##arg) +#define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ##arg) +#define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ##arg) #else -# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg) -# define NOTICE(ctx, arg...) kmod_log_null(ctx, ## arg) -# define INFO(ctx, arg...) kmod_log_null(ctx, ## arg) -# define ERR(ctx, arg...) kmod_log_null(ctx, ## arg) +#define DBG(ctx, arg...) kmod_log_null(ctx, ##arg) +#define NOTICE(ctx, arg...) kmod_log_null(ctx, ##arg) +#define INFO(ctx, arg...) kmod_log_null(ctx, ##arg) +#define ERR(ctx, arg...) kmod_log_null(ctx, ##arg) #endif -#define KMOD_EXPORT __attribute__ ((visibility("default"))) +#define KMOD_EXPORT __attribute__((visibility("default"))) #define KCMD_LINE_SIZE 4096 @@ -45,8 +47,9 @@ static _always_inline_ _printf_format_(2, 3) void #endif _printf_format_(6, 7) _nonnull_(1, 3, 5) void kmod_log(const struct kmod_ctx *ctx, - int priority, const char *file, int line, const char *fn, - const char *format, ...); + int priority, const char *file, + int line, const char *fn, + const char *format, ...); struct list_node { struct list_node *next, *prev; diff --git a/libkmod/libkmod-list.c b/libkmod/libkmod-list.c index 5c495707..591fd7e4 100644 --- a/libkmod/libkmod-list.c +++ b/libkmod/libkmod-list.c @@ -16,8 +16,7 @@ static inline struct list_node *list_node_init(struct list_node *node) return node; } -static inline void list_node_append(struct list_node *list, - struct list_node *node) +static inline void list_node_append(struct list_node *list, struct list_node *node) { if (list == NULL) { list_node_init(node); @@ -41,8 +40,7 @@ static inline struct list_node *list_node_remove(struct list_node *node) return node->next; } -static inline void list_node_insert_after(struct list_node *list, - struct list_node *node) +static inline void list_node_insert_after(struct list_node *list, struct list_node *node) { if (list == NULL) { list_node_init(node); @@ -55,8 +53,7 @@ static inline void list_node_insert_after(struct list_node *list, list->next = node; } -static inline void list_node_insert_before(struct list_node *list, - struct list_node *node) +static inline void list_node_insert_before(struct list_node *list, struct list_node *node) { if (list == NULL) { list_node_init(node); @@ -69,8 +66,7 @@ static inline void list_node_insert_before(struct list_node *list, list->prev = node; } -static inline void list_node_append_list(struct list_node *list1, - struct list_node *list2) +static inline void list_node_append_list(struct list_node *list1, struct list_node *list2) { struct list_node *list1_last; @@ -103,8 +99,7 @@ struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) return list ? list : new; } -struct kmod_list *kmod_list_insert_after(struct kmod_list *list, - const void *data) +struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) { struct kmod_list *new; @@ -121,8 +116,7 @@ struct kmod_list *kmod_list_insert_after(struct kmod_list *list, return list; } -struct kmod_list *kmod_list_insert_before(struct kmod_list *list, - const void *data) +struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data) { struct kmod_list *new; @@ -139,8 +133,7 @@ struct kmod_list *kmod_list_insert_before(struct kmod_list *list, return new; } -struct kmod_list *kmod_list_append_list(struct kmod_list *list1, - struct kmod_list *list2) +struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_list *list2) { if (list1 == NULL) return list2; @@ -183,8 +176,7 @@ struct kmod_list *kmod_list_remove(struct kmod_list *list) return container_of(node, struct kmod_list, node); } -struct kmod_list *kmod_list_remove_data(struct kmod_list *list, - const void *data) +struct kmod_list *kmod_list_remove_data(struct kmod_list *list, const void *data) { struct kmod_list *itr; struct list_node *node; @@ -210,8 +202,7 @@ struct kmod_list *kmod_list_remove_data(struct kmod_list *list, * n must be greater to or equal the number of elements (we don't check the * condition) */ -struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, - unsigned int n) +struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, unsigned int n) { struct kmod_list *l = list; unsigned int i; @@ -225,7 +216,7 @@ struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, } KMOD_EXPORT struct kmod_list *kmod_list_prev(const struct kmod_list *list, - const struct kmod_list *curr) + const struct kmod_list *curr) { if (list == NULL || curr == NULL) return NULL; @@ -237,7 +228,7 @@ KMOD_EXPORT struct kmod_list *kmod_list_prev(const struct kmod_list *list, } KMOD_EXPORT struct kmod_list *kmod_list_next(const struct kmod_list *list, - const struct kmod_list *curr) + const struct kmod_list *curr) { if (list == NULL || curr == NULL) return NULL; diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index b4a99a7b..c025e069 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -28,9 +28,9 @@ #include "libkmod-internal.h" enum kmod_module_builtin { - KMOD_MODULE_BUILTIN_UNKNOWN, - KMOD_MODULE_BUILTIN_NO, - KMOD_MODULE_BUILTIN_YES, + KMOD_MODULE_BUILTIN_UNKNOWN, + KMOD_MODULE_BUILTIN_NO, + KMOD_MODULE_BUILTIN_YES, }; struct kmod_module { @@ -40,8 +40,8 @@ struct kmod_module { char *path; struct kmod_list *dep; char *options; - const char *install_commands; /* owned by kmod_config */ - const char *remove_commands; /* owned by kmod_config */ + const char *install_commands; /* owned by kmod_config */ + const char *remove_commands; /* owned by kmod_config */ char *alias; /* only set if this module was created from an alias */ struct kmod_file *file; int n_dep; @@ -80,8 +80,7 @@ struct kmod_module { bool required : 1; }; -static inline const char *path_join(const char *path, size_t prefixlen, - char buf[PATH_MAX]) +static inline const char *path_join(const char *path, size_t prefixlen, char buf[PATH_MAX]) { size_t pathlen; @@ -100,8 +99,7 @@ static inline bool module_is_inkernel(struct kmod_module *mod) { int state = kmod_module_get_initstate(mod); - if (state == KMOD_MODULE_LIVE || - state == KMOD_MODULE_BUILTIN) + if (state == KMOD_MODULE_LIVE || state == KMOD_MODULE_BUILTIN) return true; return false; @@ -148,21 +146,19 @@ int kmod_module_parse_depline(struct kmod_module *mod, char *line) p++; for (p = strtok_r(p, " \t", &saveptr); p != NULL; - p = strtok_r(NULL, " \t", &saveptr)) { + p = strtok_r(NULL, " \t", &saveptr)) { struct kmod_module *depmod = NULL; const char *path; path = path_join(p, dirnamelen, buf); if (path == NULL) { - ERR(ctx, "could not join path '%s' and '%s'.\n", - dirname, p); + ERR(ctx, "could not join path '%s' and '%s'.\n", dirname, p); goto fail; } err = kmod_module_new_from_path(ctx, path, &depmod); if (err < 0) { - ERR(ctx, "ctx=%p path=%s error=%s\n", - ctx, path, strerror(-err)); + ERR(ctx, "ctx=%p path=%s error=%s\n", ctx, path, strerror(-err)); goto fail; } @@ -191,8 +187,7 @@ void kmod_module_set_visited(struct kmod_module *mod, bool visited) void kmod_module_set_builtin(struct kmod_module *mod, bool builtin) { - mod->builtin = - builtin ? KMOD_MODULE_BUILTIN_YES : KMOD_MODULE_BUILTIN_NO; + mod->builtin = builtin ? KMOD_MODULE_BUILTIN_YES : KMOD_MODULE_BUILTIN_NO; } void kmod_module_set_required(struct kmod_module *mod, bool required) @@ -203,8 +198,8 @@ void kmod_module_set_required(struct kmod_module *mod, bool required) bool kmod_module_is_builtin(struct kmod_module *mod) { if (mod->builtin == KMOD_MODULE_BUILTIN_UNKNOWN) { - kmod_module_set_builtin(mod, - kmod_lookup_alias_is_builtin(mod->ctx, mod->name)); + kmod_module_set_builtin(mod, kmod_lookup_alias_is_builtin(mod->ctx, + mod->name)); } return mod->builtin == KMOD_MODULE_BUILTIN_YES; @@ -232,10 +227,9 @@ bool kmod_module_is_builtin(struct kmod_module *mod) * * @key is "name\alias" or "name" (in which case alias == NULL) */ -static int kmod_module_new(struct kmod_ctx *ctx, const char *key, - const char *name, size_t namelen, - const char *alias, size_t aliaslen, - struct kmod_module **mod) +static int kmod_module_new(struct kmod_ctx *ctx, const char *key, const char *name, + size_t namelen, const char *alias, size_t aliaslen, + struct kmod_module **mod) { struct kmod_module *m; size_t keylen; @@ -277,9 +271,8 @@ static int kmod_module_new(struct kmod_ctx *ctx, const char *key, return 0; } -KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx, - const char *name, - struct kmod_module **mod) +KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx, const char *name, + struct kmod_module **mod) { size_t namelen; char name_norm[PATH_MAX]; @@ -292,8 +285,8 @@ KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx, return kmod_module_new(ctx, name_norm, name_norm, namelen, NULL, 0, mod); } -int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, - const char *name, struct kmod_module **mod) +int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name, + struct kmod_module **mod) { int err; char key[PATH_MAX]; @@ -314,9 +307,8 @@ int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, return 0; } -KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx, - const char *path, - struct kmod_module **mod) +KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx, const char *path, + struct kmod_module **mod) { struct kmod_module *m; int err; @@ -355,8 +347,9 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx, else if (streq(m->path, abspath)) free(abspath); else { - ERR(ctx, "kmod_module '%s' already exists with different path: new-path='%s' old-path='%s'\n", - name, abspath, m->path); + ERR(ctx, + "kmod_module '%s' already exists with different path: new-path='%s' old-path='%s'\n", + name, abspath, m->path); free(abspath); return -EEXIST; } @@ -411,7 +404,8 @@ KMOD_EXPORT struct kmod_module *kmod_module_ref(struct kmod_module *mod) return mod; } -typedef _nonnull_all_ int (*lookup_func)(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); +typedef _nonnull_all_ int (*lookup_func)(struct kmod_ctx *ctx, const char *name, + struct kmod_list **list); static int __kmod_module_new_from_lookup(struct kmod_ctx *ctx, const lookup_func lookup[], size_t lookup_count, const char *s, @@ -432,9 +426,8 @@ static int __kmod_module_new_from_lookup(struct kmod_ctx *ctx, const lookup_func return 0; } -KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx, - const char *given_alias, - struct kmod_list **list) +KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx, const char *given_alias, + struct kmod_list **list) { static const lookup_func lookup[] = { kmod_lookup_alias_from_config, @@ -463,8 +456,7 @@ KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx, DBG(ctx, "input alias=%s, normalized=%s\n", given_alias, alias); - err = __kmod_module_new_from_lookup(ctx, lookup, ARRAY_SIZE(lookup), - alias, list); + err = __kmod_module_new_from_lookup(ctx, lookup, ARRAY_SIZE(lookup), alias, list); DBG(ctx, "lookup=%s found=%d\n", alias, err >= 0 && *list); @@ -496,8 +488,8 @@ KMOD_EXPORT int kmod_module_new_from_name_lookup(struct kmod_ctx *ctx, DBG(ctx, "input modname=%s, normalized=%s\n", modname, name_norm); - err = __kmod_module_new_from_lookup(ctx, lookup, ARRAY_SIZE(lookup), - name_norm, &list); + err = __kmod_module_new_from_lookup(ctx, lookup, ARRAY_SIZE(lookup), name_norm, + &list); DBG(ctx, "lookup=%s found=%d\n", name_norm, err >= 0 && list); @@ -518,8 +510,8 @@ KMOD_EXPORT int kmod_module_unref_list(struct kmod_list *list) } KMOD_EXPORT int kmod_module_get_filtered_blacklist(const struct kmod_ctx *ctx, - const struct kmod_list *input, - struct kmod_list **output) + const struct kmod_list *input, + struct kmod_list **output) { return kmod_module_apply_filter(ctx, KMOD_FILTER_BLACKLIST, input, output); } @@ -605,17 +597,15 @@ KMOD_EXPORT const char *kmod_module_get_path(const struct kmod_module *mod) if (line == NULL) return NULL; - kmod_module_parse_depline((struct kmod_module *) mod, line); + kmod_module_parse_depline((struct kmod_module *)mod, line); free(line); return mod->path; } - extern long delete_module(const char *name, unsigned int flags); -KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, - unsigned int flags) +KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, unsigned int flags) { unsigned int libkmod_flags = flags & 0xff; @@ -640,8 +630,7 @@ KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, extern long init_module(const void *mem, unsigned long len, const char *args); -static int do_finit_module(struct kmod_module *mod, unsigned int flags, - const char *args) +static int do_finit_module(struct kmod_module *mod, unsigned int flags, const char *args) { enum kmod_file_compression_type compression, kernel_compression; unsigned int kernel_flags = 0; @@ -674,8 +663,7 @@ static int do_finit_module(struct kmod_module *mod, unsigned int flags, return err; } -static int do_init_module(struct kmod_module *mod, unsigned int flags, - const char *args) +static int do_init_module(struct kmod_module *mod, unsigned int flags, const char *args) { struct kmod_elf *elf; const void *mem; @@ -692,13 +680,15 @@ static int do_init_module(struct kmod_module *mod, unsigned int flags, if (flags & KMOD_INSERT_FORCE_MODVERSION) { err = kmod_elf_strip_section(elf, "__versions"); if (err < 0) - INFO(mod->ctx, "Failed to strip modversion: %s\n", strerror(-err)); + INFO(mod->ctx, "Failed to strip modversion: %s\n", + strerror(-err)); } if (flags & KMOD_INSERT_FORCE_VERMAGIC) { err = kmod_elf_strip_vermagic(elf); if (err < 0) - INFO(mod->ctx, "Failed to strip vermagic: %s\n", strerror(-err)); + INFO(mod->ctx, "Failed to strip vermagic: %s\n", + strerror(-err)); } mem = kmod_elf_get_memory(elf); @@ -718,9 +708,8 @@ static int do_init_module(struct kmod_module *mod, unsigned int flags, return err; } -KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, - unsigned int flags, - const char *options) +KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, unsigned int flags, + const char *options) { int err; const char *path; @@ -748,8 +737,7 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, err = do_init_module(mod, flags, args); if (err < 0) - INFO(mod->ctx, "Failed to insert module '%s': %s\n", - path, strerror(-err)); + INFO(mod->ctx, "Failed to insert module '%s': %s\n", path, strerror(-err)); return err; } @@ -772,9 +760,9 @@ static bool module_is_blacklisted(const struct kmod_module *mod) } KMOD_EXPORT int kmod_module_apply_filter(const struct kmod_ctx *ctx, - enum kmod_filter filter_type, - const struct kmod_list *input, - struct kmod_list **output) + enum kmod_filter filter_type, + const struct kmod_list *input, + struct kmod_list **output) { const struct kmod_list *li; @@ -789,12 +777,10 @@ KMOD_EXPORT int kmod_module_apply_filter(const struct kmod_ctx *ctx, struct kmod_module *mod = li->data; struct kmod_list *node; - if ((filter_type & KMOD_FILTER_BLACKLIST) && - module_is_blacklisted(mod)) + if ((filter_type & KMOD_FILTER_BLACKLIST) && module_is_blacklisted(mod)) continue; - if ((filter_type & KMOD_FILTER_BUILTIN) - && kmod_module_is_builtin(mod)) + if ((filter_type & KMOD_FILTER_BUILTIN) && kmod_module_is_builtin(mod)) continue; node = kmod_list_append(*output, mod); @@ -813,8 +799,7 @@ fail: return -ENOMEM; } -static int command_do(struct kmod_module *mod, const char *type, - const char *cmd) +static int command_do(struct kmod_module *mod, const char *type, const char *cmd) { const char *modname = kmod_module_get_name(mod); int err; @@ -826,8 +811,8 @@ static int command_do(struct kmod_module *mod, const char *type, unsetenv("MODPROBE_MODULE"); if (err == -1) { - ERR(mod->ctx, "Could not run %s command '%s' for module %s: %m\n", - type, cmd, modname); + ERR(mod->ctx, "Could not run %s command '%s' for module %s: %m\n", type, + cmd, modname); return -EINVAL; } @@ -845,9 +830,8 @@ struct probe_insert_cb { void *data; }; -static int module_do_install_commands(struct kmod_module *mod, - const char *options, - struct probe_insert_cb *cb) +static int module_do_install_commands(struct kmod_module *mod, const char *options, + struct probe_insert_cb *cb) { const char *command = kmod_module_get_install_commands(mod); char *p; @@ -921,22 +905,18 @@ static char *module_options_concat(const char *opt, const char *xopt) return r; } -static int __kmod_module_get_probe_list(struct kmod_module *mod, - bool required, - bool ignorecmd, - struct kmod_list **list); +static int __kmod_module_get_probe_list(struct kmod_module *mod, bool required, + bool ignorecmd, struct kmod_list **list); /* re-entrant */ -static int __kmod_module_fill_softdep(struct kmod_module *mod, - struct kmod_list **list) +static int __kmod_module_fill_softdep(struct kmod_module *mod, struct kmod_list **list) { struct kmod_list *pre = NULL, *post = NULL, *l; int err; err = kmod_module_get_softdeps(mod, &pre, &post); if (err < 0) { - ERR(mod->ctx, "could not get softdep: %s\n", - strerror(-err)); + ERR(mod->ctx, "could not get softdep: %s\n", strerror(-err)); goto fail; } @@ -971,17 +951,14 @@ fail: } /* re-entrant */ -static int __kmod_module_get_probe_list(struct kmod_module *mod, - bool required, - bool ignorecmd, - struct kmod_list **list) +static int __kmod_module_get_probe_list(struct kmod_module *mod, bool required, + bool ignorecmd, struct kmod_list **list) { struct kmod_list *dep, *l; int err = 0; if (mod->visited) { - DBG(mod->ctx, "Ignore module '%s': already visited\n", - mod->name); + DBG(mod->ctx, "Ignore module '%s': already visited\n", mod->name); return 0; } mod->visited = true; @@ -1024,9 +1001,8 @@ finish: return err; } -static int kmod_module_get_probe_list(struct kmod_module *mod, - bool ignorecmd, - struct kmod_list **list) +static int kmod_module_get_probe_list(struct kmod_module *mod, bool ignorecmd, + struct kmod_list **list) { int err; @@ -1048,14 +1024,11 @@ static int kmod_module_get_probe_list(struct kmod_module *mod, return err; } -KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod, - unsigned int flags, const char *extra_options, - int (*run_install)(struct kmod_module *m, - const char *cmd, void *data), - const void *data, - void (*print_action)(struct kmod_module *m, - bool install, - const char *options)) +KMOD_EXPORT int kmod_module_probe_insert_module( + struct kmod_module *mod, unsigned int flags, const char *extra_options, + int (*run_install)(struct kmod_module *m, const char *cmd, void *data), + const void *data, + void (*print_action)(struct kmod_module *m, bool install, const char *options)) { struct kmod_list *list = NULL, *l; struct probe_insert_cb cb; @@ -1064,8 +1037,7 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod, if (mod == NULL) return -ENOENT; - if (!(flags & KMOD_PROBE_IGNORE_LOADED) - && module_is_inkernel(mod)) { + if (!(flags & KMOD_PROBE_IGNORE_LOADED) && module_is_inkernel(mod)) { if (flags & KMOD_PROBE_FAIL_ON_LOADED) return -EEXIST; else @@ -1083,16 +1055,16 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod, return KMOD_PROBE_APPLY_BLACKLIST; } - err = kmod_module_get_probe_list(mod, - !!(flags & KMOD_PROBE_IGNORE_COMMAND), &list); + err = kmod_module_get_probe_list(mod, !!(flags & KMOD_PROBE_IGNORE_COMMAND), + &list); if (err < 0) return err; if (flags & KMOD_PROBE_APPLY_BLACKLIST_ALL) { struct kmod_list *filtered = NULL; - err = kmod_module_apply_filter(mod->ctx, - KMOD_FILTER_BLACKLIST, list, &filtered); + err = kmod_module_apply_filter(mod->ctx, KMOD_FILTER_BLACKLIST, list, + &filtered); if (err < 0) return err; @@ -1104,7 +1076,7 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod, } cb.run_install = run_install; - cb.data = (void *) data; + cb.data = (void *)data; kmod_list_foreach(l, list) { struct kmod_module *m = l->data; @@ -1112,31 +1084,27 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod, const char *cmd = kmod_module_get_install_commands(m); char *options; - if (!(flags & KMOD_PROBE_IGNORE_LOADED) - && module_is_inkernel(m)) { - DBG(mod->ctx, "Ignoring module '%s': already loaded\n", - m->name); + if (!(flags & KMOD_PROBE_IGNORE_LOADED) && module_is_inkernel(m)) { + DBG(mod->ctx, "Ignoring module '%s': already loaded\n", m->name); err = -EEXIST; goto finish_module; } - options = module_options_concat(moptions, - m == mod ? extra_options : NULL); + options = + module_options_concat(moptions, m == mod ? extra_options : NULL); if (cmd != NULL && !m->ignorecmd) { if (print_action != NULL) print_action(m, true, options ?: ""); if (!(flags & KMOD_PROBE_DRY_RUN)) - err = module_do_install_commands(m, options, - &cb); + err = module_do_install_commands(m, options, &cb); } else { if (print_action != NULL) print_action(m, false, options ?: ""); if (!(flags & KMOD_PROBE_DRY_RUN)) - err = kmod_module_insert_module(m, flags, - options); + err = kmod_module_insert_module(m, flags, options); } free(options); @@ -1152,8 +1120,7 @@ finish_module: * been loaded between the check and the moment we try to * insert it. */ - if (err == -EEXIST && m == mod && - (flags & KMOD_PROBE_FAIL_ON_LOADED)) + if (err == -EEXIST && m == mod && (flags & KMOD_PROBE_FAIL_ON_LOADED)) break; /* @@ -1191,12 +1158,14 @@ KMOD_EXPORT const char *kmod_module_get_options(const struct kmod_module *mod) size_t len; void *tmp; - DBG(mod->ctx, "modname=%s mod->name=%s mod->alias=%s\n", modname, mod->name, mod->alias); - if (!(streq(modname, mod->name) || (mod->alias != NULL && - streq(modname, mod->alias)))) + DBG(mod->ctx, "modname=%s mod->name=%s mod->alias=%s\n", modname, + mod->name, mod->alias); + if (!(streq(modname, mod->name) || + (mod->alias != NULL && streq(modname, mod->alias)))) continue; - DBG(mod->ctx, "passed = modname=%s mod->name=%s mod->alias=%s\n", modname, mod->name, mod->alias); + DBG(mod->ctx, "passed = modname=%s mod->name=%s mod->alias=%s\n", + modname, mod->name, mod->alias); str = kmod_option_get_options(l); len = strlen(str); if (len < 1) @@ -1271,7 +1240,8 @@ void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd) mod->install_commands = cmd; } -static struct kmod_list *lookup_dep(struct kmod_ctx *ctx, const char * const * array, unsigned int count) +static struct kmod_list *lookup_dep(struct kmod_ctx *ctx, const char *const *array, + unsigned int count) { struct kmod_list *ret = NULL; unsigned i; @@ -1283,7 +1253,8 @@ static struct kmod_list *lookup_dep(struct kmod_ctx *ctx, const char * const * a err = kmod_module_new_from_lookup(ctx, depname, &lst); if (err < 0) { - ERR(ctx, "failed to lookup dependency '%s', continuing anyway.\n", depname); + ERR(ctx, "failed to lookup dependency '%s', continuing anyway.\n", + depname); continue; } else if (lst != NULL) ret = kmod_list_append_list(ret, lst); @@ -1292,8 +1263,7 @@ static struct kmod_list *lookup_dep(struct kmod_ctx *ctx, const char * const * a } KMOD_EXPORT int kmod_module_get_softdeps(const struct kmod_module *mod, - struct kmod_list **pre, - struct kmod_list **post) + struct kmod_list **pre, struct kmod_list **post) { const struct kmod_list *l; const struct kmod_config *config; @@ -1308,7 +1278,7 @@ KMOD_EXPORT int kmod_module_get_softdeps(const struct kmod_module *mod, kmod_list_foreach(l, config->softdeps) { const char *modname = kmod_softdep_get_name(l); - const char * const *array; + const char *const *array; unsigned count; if (fnmatch(modname, mod->name, 0) != 0) @@ -1330,7 +1300,7 @@ KMOD_EXPORT int kmod_module_get_softdeps(const struct kmod_module *mod, } KMOD_EXPORT int kmod_module_get_weakdeps(const struct kmod_module *mod, - struct kmod_list **weak) + struct kmod_list **weak) { const struct kmod_list *l; const struct kmod_config *config; @@ -1344,7 +1314,7 @@ KMOD_EXPORT int kmod_module_get_weakdeps(const struct kmod_module *mod, kmod_list_foreach(l, config->weakdeps) { const char *modname = kmod_weakdep_get_name(l); - const char * const *array; + const char *const *array; unsigned count; if (fnmatch(modname, mod->name, 0) != 0) @@ -1403,8 +1373,7 @@ void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) mod->remove_commands = cmd; } -KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx, - struct kmod_list **list) +KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx, struct kmod_list **list) { struct kmod_list *l = NULL; FILE *fp; @@ -1429,8 +1398,8 @@ KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx, err = kmod_module_new_from_name(ctx, name, &m); if (err < 0) { - ERR(ctx, "could not get module from name '%s': %s\n", - name, strerror(-err)); + ERR(ctx, "could not get module from name '%s': %s\n", name, + strerror(-err)); goto eat_line; } @@ -1480,18 +1449,16 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod) if (kmod_module_is_builtin((struct kmod_module *)mod)) return KMOD_MODULE_BUILTIN; - pathlen = snprintf(path, sizeof(path), - "/sys/module/%s/initstate", mod->name); + pathlen = snprintf(path, sizeof(path), "/sys/module/%s/initstate", mod->name); if (pathlen >= (int)sizeof(path)) { /* Too long path was truncated */ return -ENAMETOOLONG; } - fd = open(path, O_RDONLY|O_CLOEXEC); + fd = open(path, O_RDONLY | O_CLOEXEC); if (fd < 0) { err = -errno; - DBG(mod->ctx, "could not open '%s': %s\n", - path, strerror(-err)); + DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err)); if (pathlen > (int)sizeof("/initstate") - 1) { struct stat st; @@ -1500,16 +1467,14 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod) return KMOD_MODULE_COMING; } - DBG(mod->ctx, "could not open '%s': %s\n", - path, strerror(-err)); + DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err)); return err; } err = read_str_safe(fd, buf, sizeof(buf)); close(fd); if (err < 0) { - ERR(mod->ctx, "could not read from '%s': %s\n", - path, strerror(-err)); + ERR(mod->ctx, "could not read from '%s': %s\n", path, strerror(-err)); return err; } @@ -1540,12 +1505,12 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod) * loaded. */ snprintf(line, sizeof(line), "/sys/module/%s", mod->name); - dfd = open(line, O_RDONLY|O_CLOEXEC); + dfd = open(line, O_RDONLY | O_CLOEXEC); if (dfd < 0) return -errno; /* available as of linux 3.3.x */ - cfd = openat(dfd, "coresize", O_RDONLY|O_CLOEXEC); + cfd = openat(dfd, "coresize", O_RDONLY | O_CLOEXEC); if (cfd >= 0) { if (read_str_long(cfd, &size, 10) < 0) ERR(mod->ctx, "failed to read coresize from %s\n", line); @@ -1557,8 +1522,7 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod) fp = fopen("/proc/modules", "re"); if (fp == NULL) { int err = -errno; - ERR(mod->ctx, - "could not open /proc/modules: %s\n", strerror(errno)); + ERR(mod->ctx, "could not open /proc/modules: %s\n", strerror(errno)); close(dfd); return err; } @@ -1574,15 +1538,13 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod) tok = strtok_r(NULL, " \t", &saveptr); if (tok == NULL) { - ERR(mod->ctx, - "invalid line format at /proc/modules:%d\n", lineno); + ERR(mod->ctx, "invalid line format at /proc/modules:%d\n", lineno); break; } value = strtol(tok, &endptr, 10); if (endptr == tok || *endptr != '\0') { - ERR(mod->ctx, - "invalid line format at /proc/modules:%d\n", lineno); + ERR(mod->ctx, "invalid line format at /proc/modules:%d\n", lineno); break; } @@ -1609,19 +1571,18 @@ KMOD_EXPORT int kmod_module_get_refcnt(const struct kmod_module *mod) return -ENOENT; snprintf(path, sizeof(path), "/sys/module/%s/refcnt", mod->name); - fd = open(path, O_RDONLY|O_CLOEXEC); + fd = open(path, O_RDONLY | O_CLOEXEC); if (fd < 0) { err = -errno; - DBG(mod->ctx, "could not open '%s': %s\n", - path, strerror(errno)); + DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(errno)); return err; } err = read_str_long(fd, &refcnt, 10); close(fd); if (err < 0) { - ERR(mod->ctx, "could not read integer from '%s': '%s'\n", - path, strerror(-err)); + ERR(mod->ctx, "could not read integer from '%s': '%s'\n", path, + strerror(-err)); return err; } @@ -1642,8 +1603,7 @@ KMOD_EXPORT struct kmod_list *kmod_module_get_holders(const struct kmod_module * d = opendir(dname); if (d == NULL) { - ERR(mod->ctx, "could not open '%s': %s\n", - dname, strerror(errno)); + ERR(mod->ctx, "could not open '%s': %s\n", dname, strerror(errno)); return NULL; } @@ -1658,11 +1618,10 @@ KMOD_EXPORT struct kmod_list *kmod_module_get_holders(const struct kmod_module * continue; } - err = kmod_module_new_from_name(mod->ctx, dent->d_name, - &holder); + err = kmod_module_new_from_name(mod->ctx, dent->d_name, &holder); if (err < 0) { ERR(mod->ctx, "could not create module for '%s': %s\n", - dent->d_name, strerror(-err)); + dent->d_name, strerror(-err)); goto fail; } @@ -1710,8 +1669,7 @@ KMOD_EXPORT struct kmod_list *kmod_module_get_sections(const struct kmod_module d = opendir(dname); if (d == NULL) { - ERR(mod->ctx, "could not open '%s': %s\n", - dname, strerror(errno)); + ERR(mod->ctx, "could not open '%s': %s\n", dname, strerror(errno)); return NULL; } @@ -1730,18 +1688,17 @@ KMOD_EXPORT struct kmod_list *kmod_module_get_sections(const struct kmod_module continue; } - fd = openat(dfd, dent->d_name, O_RDONLY|O_CLOEXEC); + fd = openat(dfd, dent->d_name, O_RDONLY | O_CLOEXEC); if (fd < 0) { - ERR(mod->ctx, "could not open '%s/%s': %m\n", - dname, dent->d_name); + ERR(mod->ctx, "could not open '%s/%s': %m\n", dname, dent->d_name); goto fail; } err = read_str_ulong(fd, &address, 16); close(fd); if (err < 0) { - ERR(mod->ctx, "could not read long from '%s/%s': %m\n", - dname, dent->d_name); + ERR(mod->ctx, "could not read long from '%s/%s': %m\n", dname, + dent->d_name); goto fail; } @@ -1815,8 +1772,7 @@ static struct kmod_elf *kmod_module_get_elf(const struct kmod_module *mod) return NULL; } - ((struct kmod_module *)mod)->file = kmod_file_open(mod->ctx, - path); + ((struct kmod_module *)mod)->file = kmod_file_open(mod->ctx, path); if (mod->file == NULL) return NULL; } @@ -1829,7 +1785,8 @@ struct kmod_module_info { char value[]; }; -static struct kmod_module_info *kmod_module_info_new(const char *key, size_t keylen, const char *value, size_t valuelen) +static struct kmod_module_info *kmod_module_info_new(const char *key, size_t keylen, + const char *value, size_t valuelen) { struct kmod_module_info *info; @@ -1837,8 +1794,7 @@ static struct kmod_module_info *kmod_module_info_new(const char *key, size_t key if (info == NULL) return NULL; - info->key = (char *)info + sizeof(struct kmod_module_info) - + valuelen + 1; + info->key = (char *)info + sizeof(struct kmod_module_info) + valuelen + 1; memcpy(info->key, key, keylen); info->key[keylen] = '\0'; memcpy(info->value, value, valuelen); @@ -1851,7 +1807,9 @@ static void kmod_module_info_free(struct kmod_module_info *info) free(info); } -static struct kmod_list *kmod_module_info_append(struct kmod_list **list, const char *key, size_t keylen, const char *value, size_t valuelen) +static struct kmod_list *kmod_module_info_append(struct kmod_list **list, const char *key, + size_t keylen, const char *value, + size_t valuelen) { struct kmod_module_info *info; struct kmod_list *n; @@ -1895,10 +1853,8 @@ static char *kmod_module_hex_to_str(const char *hex, size_t len) } static struct kmod_list *kmod_module_info_append_hex(struct kmod_list **list, - const char *key, - size_t keylen, - const char *value, - size_t valuelen) + const char *key, size_t keylen, + const char *value, size_t valuelen) { char *hex; struct kmod_list *n; @@ -1924,7 +1880,8 @@ list_error: return NULL; } -KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_list **list) +KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, + struct kmod_list **list) { struct kmod_elf *elf; char **strings; @@ -1938,9 +1895,8 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_ /* remove const: this can only change internal state */ if (kmod_module_is_builtin((struct kmod_module *)mod)) { - count = kmod_builtin_get_modinfo(mod->ctx, - kmod_module_get_name(mod), - &strings); + count = kmod_builtin_get_modinfo(mod->ctx, kmod_module_get_name(mod), + &strings); if (count < 0) return count; } else { @@ -1979,28 +1935,26 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_ struct kmod_list *n; n = kmod_module_info_append(list, "sig_id", strlen("sig_id"), - sig_info.id_type, strlen(sig_info.id_type)); + sig_info.id_type, strlen(sig_info.id_type)); if (n == NULL) goto list_error; count++; n = kmod_module_info_append(list, "signer", strlen("signer"), - sig_info.signer, sig_info.signer_len); + sig_info.signer, sig_info.signer_len); if (n == NULL) goto list_error; count++; - n = kmod_module_info_append_hex(list, "sig_key", strlen("sig_key"), - sig_info.key_id, - sig_info.key_id_len); + sig_info.key_id, sig_info.key_id_len); if (n == NULL) goto list_error; count++; - n = kmod_module_info_append(list, - "sig_hashalgo", strlen("sig_hashalgo"), - sig_info.hash_algo, strlen(sig_info.hash_algo)); + n = kmod_module_info_append(list, "sig_hashalgo", strlen("sig_hashalgo"), + sig_info.hash_algo, + strlen(sig_info.hash_algo)); if (n == NULL) goto list_error; count++; @@ -2009,15 +1963,12 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_ * Omit sig_info.algo for now, as these * are currently constant. */ - n = kmod_module_info_append_hex(list, "signature", - strlen("signature"), - sig_info.sig, - sig_info.sig_len); + n = kmod_module_info_append_hex(list, "signature", strlen("signature"), + sig_info.sig, sig_info.sig_len); if (n == NULL) goto list_error; count++; - } ret = count; @@ -2068,7 +2019,8 @@ struct kmod_module_version { char symbol[]; }; -static struct kmod_module_version *kmod_module_versions_new(uint64_t crc, const char *symbol) +static struct kmod_module_version *kmod_module_versions_new(uint64_t crc, + const char *symbol) { struct kmod_module_version *mv; size_t symbollen = strlen(symbol) + 1; @@ -2087,7 +2039,8 @@ static void kmod_module_version_free(struct kmod_module_version *version) free(version); } -KMOD_EXPORT int kmod_module_get_versions(const struct kmod_module *mod, struct kmod_list **list) +KMOD_EXPORT int kmod_module_get_versions(const struct kmod_module *mod, + struct kmod_list **list) { struct kmod_elf *elf; struct kmod_modversion *versions; @@ -2190,7 +2143,8 @@ static void kmod_module_symbol_free(struct kmod_module_symbol *symbol) free(symbol); } -KMOD_EXPORT int kmod_module_get_symbols(const struct kmod_module *mod, struct kmod_list **list) +KMOD_EXPORT int kmod_module_get_symbols(const struct kmod_module *mod, + struct kmod_list **list) { struct kmod_elf *elf; struct kmod_modversion *symbols; @@ -2292,12 +2246,14 @@ static struct kmod_module_dependency_symbol *kmod_module_dependency_symbols_new( return mv; } -static void kmod_module_dependency_symbol_free(struct kmod_module_dependency_symbol *dependency_symbol) +static void kmod_module_dependency_symbol_free( + struct kmod_module_dependency_symbol *dependency_symbol) { free(dependency_symbol); } -KMOD_EXPORT int kmod_module_get_dependency_symbols(const struct kmod_module *mod, struct kmod_list **list) +KMOD_EXPORT int kmod_module_get_dependency_symbols(const struct kmod_module *mod, + struct kmod_list **list) { struct kmod_elf *elf; struct kmod_modversion *symbols; @@ -2320,8 +2276,7 @@ KMOD_EXPORT int kmod_module_get_dependency_symbols(const struct kmod_module *mod struct kmod_module_dependency_symbol *mv; struct kmod_list *n; - mv = kmod_module_dependency_symbols_new(symbols[i].crc, - symbols[i].bind, + mv = kmod_module_dependency_symbols_new(symbols[i].crc, symbols[i].bind, symbols[i].symbol); if (mv == NULL) { ret = -errno; diff --git a/libkmod/libkmod-signature.c b/libkmod/libkmod-signature.c index 9f2de23e..8cb596d6 100644 --- a/libkmod/libkmod-signature.c +++ b/libkmod/libkmod-signature.c @@ -29,8 +29,8 @@ enum pkey_algo { }; static const char *const pkey_algo[PKEY_ALGO__LAST] = { - [PKEY_ALGO_DSA] = "DSA", - [PKEY_ALGO_RSA] = "RSA", + [PKEY_ALGO_DSA] = "DSA", + [PKEY_ALGO_RSA] = "RSA", }; enum pkey_hash_algo { @@ -61,29 +61,29 @@ const char *const pkey_hash_algo[PKEY_HASH__LAST] = { }; enum pkey_id_type { - PKEY_ID_PGP, /* OpenPGP generated key ID */ - PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */ - PKEY_ID_PKCS7, /* Signature in PKCS#7 message */ + PKEY_ID_PGP, /* OpenPGP generated key ID */ + PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */ + PKEY_ID_PKCS7, /* Signature in PKCS#7 message */ PKEY_ID_TYPE__LAST, }; const char *const pkey_id_type[PKEY_ID_TYPE__LAST] = { - [PKEY_ID_PGP] = "PGP", - [PKEY_ID_X509] = "X509", - [PKEY_ID_PKCS7] = "PKCS#7", + [PKEY_ID_PGP] = "PGP", + [PKEY_ID_X509] = "X509", + [PKEY_ID_PKCS7] = "PKCS#7", }; /* * Module signature information block. */ struct module_signature { - uint8_t algo; /* Public-key crypto algorithm [enum pkey_algo] */ - uint8_t hash; /* Digest algorithm [enum pkey_hash_algo] */ - uint8_t id_type; /* Key identifier type [enum pkey_id_type] */ - uint8_t signer_len; /* Length of signer's name */ - uint8_t key_id_len; /* Length of key identifier */ + uint8_t algo; /* Public-key crypto algorithm [enum pkey_algo] */ + uint8_t hash; /* Digest algorithm [enum pkey_hash_algo] */ + uint8_t id_type; /* Key identifier type [enum pkey_id_type] */ + uint8_t signer_len; /* Length of signer's name */ + uint8_t key_id_len; /* Length of key identifier */ uint8_t __pad[3]; - uint32_t sig_len; /* Length of signature data (big endian) */ + uint32_t sig_len; /* Length of signature data (big endian) */ }; static bool fill_default(const char *mem, off_t size, @@ -156,13 +156,12 @@ static const char *x509_name_to_str(X509_NAME *name) return str; } -static bool fill_pkcs7(const char *mem, off_t size, - const struct module_signature *modsig, size_t sig_len, - struct kmod_signature_info *sig_info) +static bool fill_pkcs7(const char *mem, off_t size, const struct module_signature *modsig, + size_t sig_len, struct kmod_signature_info *sig_info) { const char *pkcs7_raw; PKCS7 *pkcs7; - STACK_OF(PKCS7_SIGNER_INFO) *sis; + STACK_OF(PKCS7_SIGNER_INFO) * sis; PKCS7_SIGNER_INFO *si; PKCS7_ISSUER_AND_SERIAL *is; X509_NAME *issuer; @@ -279,9 +278,8 @@ err: #else /* ENABLE OPENSSL */ -static bool fill_pkcs7(const char *mem, off_t size, - const struct module_signature *modsig, size_t sig_len, - struct kmod_signature_info *sig_info) +static bool fill_pkcs7(const char *mem, off_t size, const struct module_signature *modsig, + size_t sig_len, struct kmod_signature_info *sig_info) { sig_info->hash_algo = "unknown"; sig_info->id_type = pkey_id_type[modsig->id_type]; @@ -303,7 +301,8 @@ static bool fill_pkcs7(const char *mem, off_t size, * [ SIG_MAGIC ] */ -bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signature_info *sig_info) +bool kmod_module_signature_info(const struct kmod_file *file, + struct kmod_signature_info *sig_info) { const char *mem; off_t size; @@ -322,9 +321,8 @@ bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signat return false; size -= sizeof(struct module_signature); memcpy(&modsig, mem + size, sizeof(struct module_signature)); - if (modsig.algo >= PKEY_ALGO__LAST || - modsig.hash >= PKEY_HASH__LAST || - modsig.id_type >= PKEY_ID_TYPE__LAST) + if (modsig.algo >= PKEY_ALGO__LAST || modsig.hash >= PKEY_HASH__LAST || + modsig.id_type >= PKEY_ID_TYPE__LAST) return false; sig_len = be32toh(modsig.sig_len); if (sig_len == 0 || diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index 8c71d8a4..d1e5a82c 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -55,9 +55,8 @@ static const char *const default_config_paths[] = { struct kmod_ctx { int refcount; int log_priority; - void (*log_fn)(void *data, - int priority, const char *file, int line, - const char *fn, const char *format, va_list args); + void (*log_fn)(void *data, int priority, const char *file, int line, + const char *fn, const char *format, va_list args); void *log_data; const void *userdata; char *dirname; @@ -68,9 +67,8 @@ struct kmod_ctx { unsigned long long indexes_stamp[_KMOD_INDEX_MODULES_SIZE]; }; -void kmod_log(const struct kmod_ctx *ctx, - int priority, const char *file, int line, const char *fn, - const char *format, ...) +void kmod_log(const struct kmod_ctx *ctx, int priority, const char *file, int line, + const char *fn, const char *format, ...) { va_list args; @@ -82,10 +80,9 @@ void kmod_log(const struct kmod_ctx *ctx, va_end(args); } -_printf_format_(6, 0) -static void log_filep(void *data, - int priority, const char *file, int line, - const char *fn, const char *format, va_list args) +_printf_format_(6, 0) static void log_filep(void *data, int priority, const char *file, + int line, const char *fn, const char *format, + va_list args) { FILE *fp = data; #ifdef ENABLE_DEBUG @@ -192,7 +189,7 @@ static enum kmod_file_compression_type get_kernel_compression(struct kmod_ctx *c int fd; int err; - fd = open(path, O_RDONLY|O_CLOEXEC); + fd = open(path, O_RDONLY | O_CLOEXEC); if (fd < 0) { /* Not having the file is not an error: kernel may be too old */ DBG(ctx, "could not open '%s' for reading: %m\n", path); @@ -202,8 +199,7 @@ static enum kmod_file_compression_type get_kernel_compression(struct kmod_ctx *c err = read_str_safe(fd, buf, sizeof(buf)); close(fd); if (err < 0) { - ERR(ctx, "could not read from '%s': %s\n", - path, strerror(-err)); + ERR(ctx, "could not read from '%s': %s\n", path, strerror(-err)); return KMOD_FILE_COMPRESSION_NONE; } @@ -219,8 +215,7 @@ static enum kmod_file_compression_type get_kernel_compression(struct kmod_ctx *c return KMOD_FILE_COMPRESSION_NONE; } -KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname, - const char * const *config_paths) +KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname, const char *const *config_paths) { const char *env; struct kmod_ctx *ctx; @@ -303,11 +298,10 @@ KMOD_EXPORT struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx) } KMOD_EXPORT void kmod_set_log_fn(struct kmod_ctx *ctx, - void (*log_fn)(void *data, - int priority, const char *file, - int line, const char *fn, + void (*log_fn)(void *data, int priority, + const char *file, int line, const char *fn, const char *format, va_list args), - const void *data) + const void *data) { if (ctx == NULL) return; @@ -330,8 +324,7 @@ KMOD_EXPORT void kmod_set_log_priority(struct kmod_ctx *ctx, int priority) ctx->log_priority = priority; } -struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, - const char *key) +struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key) { struct kmod_module *mod; @@ -342,16 +335,14 @@ struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, return mod; } -void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, - const char *key) +void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) { DBG(ctx, "add %p key='%s'\n", mod, key); hash_add(ctx->modules_by_name, key, mod); } -void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, - const char *key) +void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) { DBG(ctx, "del %p key='%s'\n", mod, key); @@ -359,9 +350,8 @@ void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, } static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx, - enum kmod_index index_number, - const char *name, - struct kmod_list **list) + enum kmod_index index_number, + const char *name, struct kmod_list **list) { int err, nmatch = 0; struct index_file *idx; @@ -369,14 +359,13 @@ static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx, if (ctx->indexes[index_number] != NULL) { DBG(ctx, "use mmapped index '%s' for name=%s\n", - index_files[index_number].fn, name); - realnames = index_mm_searchwild(ctx->indexes[index_number], - name); + index_files[index_number].fn, name); + realnames = index_mm_searchwild(ctx->indexes[index_number], name); } else { char fn[PATH_MAX]; snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, - index_files[index_number].fn); + index_files[index_number].fn); DBG(ctx, "file=%s name=%s\n", fn, name); @@ -409,24 +398,22 @@ fail: *list = kmod_list_remove_n_latest(*list, nmatch); index_values_free(realnames); return err; - } int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, - struct kmod_list **list) + struct kmod_list **list) { if (!strstartswith(name, "symbol:")) return 0; - return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_SYMBOL, - name, list); + return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_SYMBOL, name, + list); } int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, - struct kmod_list **list) + struct kmod_list **list) { - return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_ALIAS, - name, list); + return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_ALIAS, name, list); } static char *lookup_builtin_file(struct kmod_ctx *ctx, const char *name) @@ -435,16 +422,14 @@ static char *lookup_builtin_file(struct kmod_ctx *ctx, const char *name) if (ctx->indexes[KMOD_INDEX_MODULES_BUILTIN]) { DBG(ctx, "use mmapped index '%s' modname=%s\n", - index_files[KMOD_INDEX_MODULES_BUILTIN].fn, - name); - line = index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_BUILTIN], - name); + index_files[KMOD_INDEX_MODULES_BUILTIN].fn, name); + line = index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_BUILTIN], name); } else { struct index_file *idx; char fn[PATH_MAX]; snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, - index_files[KMOD_INDEX_MODULES_BUILTIN].fn); + index_files[KMOD_INDEX_MODULES_BUILTIN].fn); DBG(ctx, "file=%s modname=%s\n", fn, name); idx = index_file_open(fn); @@ -460,17 +445,15 @@ static char *lookup_builtin_file(struct kmod_ctx *ctx, const char *name) return line; } -int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx, - const char *name, - struct kmod_list **list) +int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx, const char *name, + struct kmod_list **list) { struct kmod_list *l; int ret; assert(*list == NULL); - ret = kmod_lookup_alias_from_alias_bin(ctx, - KMOD_INDEX_MODULES_BUILTIN_ALIAS, + ret = kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_BUILTIN_ALIAS, name, list); kmod_list_foreach(l, *list) { @@ -482,7 +465,7 @@ int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx, } int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, - struct kmod_list **list) + struct kmod_list **list) { char *line; int err = 0; @@ -495,8 +478,8 @@ int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, err = kmod_module_new_from_name(ctx, name, &mod); if (err < 0) { - ERR(ctx, "Could not create module from name %s: %s\n", - name, strerror(-err)); + ERR(ctx, "Could not create module from name %s: %s\n", name, + strerror(-err)); goto finish; } @@ -530,13 +513,12 @@ char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) if (ctx->indexes[KMOD_INDEX_MODULES_DEP]) { DBG(ctx, "use mmapped index '%s' modname=%s\n", - index_files[KMOD_INDEX_MODULES_DEP].fn, name); - return index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_DEP], - name); + index_files[KMOD_INDEX_MODULES_DEP].fn, name); + return index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_DEP], name); } snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, - index_files[KMOD_INDEX_MODULES_DEP].fn); + index_files[KMOD_INDEX_MODULES_DEP].fn); DBG(ctx, "file=%s modname=%s\n", fn, name); @@ -553,7 +535,7 @@ char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) } int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, - struct kmod_list **list) + struct kmod_list **list) { char *line; int n = 0; @@ -571,8 +553,8 @@ int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, n = kmod_module_new_from_name(ctx, name, &mod); if (n < 0) { - ERR(ctx, "Could not create module from name %s: %s\n", - name, strerror(-n)); + ERR(ctx, "Could not create module from name %s: %s\n", name, + strerror(-n)); goto finish; } @@ -587,7 +569,7 @@ finish: } int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, - struct kmod_list **list) + struct kmod_list **list) { struct kmod_config *config = ctx->config; struct kmod_list *l; @@ -600,10 +582,10 @@ int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, if (fnmatch(aliasname, name, 0) == 0) { struct kmod_module *mod; - err = kmod_module_new_from_alias(ctx, aliasname, - modname, &mod); + err = kmod_module_new_from_alias(ctx, aliasname, modname, &mod); if (err < 0) { - ERR(ctx, "Could not create module for alias=%s modname=%s: %s\n", + ERR(ctx, + "Could not create module for alias=%s modname=%s: %s\n", name, modname, strerror(-err)); goto fail; } @@ -621,7 +603,7 @@ fail: } int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, - struct kmod_list **list) + struct kmod_list **list) { struct kmod_config *config = ctx->config; struct kmod_list *l, *node; @@ -753,8 +735,7 @@ KMOD_EXPORT int kmod_validate_resources(struct kmod_ctx *ctx) if (ctx->indexes[i] == NULL) continue; - snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname, - index_files[i].fn); + snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname, index_files[i].fn); if (is_cache_invalid(path, ctx->indexes_stamp[i])) return KMOD_RESOURCES_MUST_RELOAD; @@ -775,15 +756,12 @@ KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx) char path[PATH_MAX]; if (ctx->indexes[i] != NULL) { - INFO(ctx, "Index %s already loaded\n", - index_files[i].fn); + INFO(ctx, "Index %s already loaded\n", index_files[i].fn); continue; } - snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname, - index_files[i].fn); - ret = index_mm_open(ctx, path, &ctx->indexes_stamp[i], - &ctx->indexes[i]); + snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname, index_files[i].fn); + ret = index_mm_open(ctx, path, &ctx->indexes_stamp[i], &ctx->indexes[i]); /* * modules.builtin.alias are considered optional since it's @@ -819,8 +797,7 @@ KMOD_EXPORT void kmod_unload_resources(struct kmod_ctx *ctx) } } -KMOD_EXPORT int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, - int fd) +KMOD_EXPORT int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, int fd) { if (ctx == NULL) return -ENOSYS; @@ -830,14 +807,12 @@ KMOD_EXPORT int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, if (ctx->indexes[type] != NULL) { DBG(ctx, "use mmapped index '%s'\n", index_files[type].fn); - index_mm_dump(ctx->indexes[type], fd, - index_files[type].prefix); + index_mm_dump(ctx->indexes[type], fd, index_files[type].prefix); } else { char fn[PATH_MAX]; struct index_file *idx; - snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, - index_files[type].fn); + snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, index_files[type].fn); DBG(ctx, "file=%s\n", fn); diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index 30813a18..b9a93a52 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -55,7 +55,7 @@ struct kmod_ctx; * * Since: 1 */ -struct kmod_ctx *kmod_new(const char *dirname, const char * const *config_paths); +struct kmod_ctx *kmod_new(const char *dirname, const char *const *config_paths); /** * kmod_ref: @@ -82,7 +82,6 @@ struct kmod_ctx *kmod_ref(struct kmod_ctx *ctx); */ struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx); - /** * kmod_load_resources: * @ctx: kmod library context @@ -187,7 +186,6 @@ enum kmod_index { */ int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, int fd); - /** * kmod_set_log_priority: * @ctx: kmod library context @@ -225,11 +223,10 @@ int kmod_get_log_priority(const struct kmod_ctx *ctx); * Since: 1 */ void kmod_set_log_fn(struct kmod_ctx *ctx, - void (*log_fn)(void *log_data, - int priority, const char *file, int line, - const char *fn, const char *format, - va_list args), - const void *data); + void (*log_fn)(void *log_data, int priority, const char *file, + int line, const char *fn, const char *format, + va_list args), + const void *data); /** * kmod_set_userdata: @@ -266,8 +263,6 @@ void *kmod_get_userdata(const struct kmod_ctx *ctx); */ const char *kmod_get_dirname(const struct kmod_ctx *ctx); - - /** * SECTION:libkmod-list * @short_description: general purpose list @@ -290,9 +285,7 @@ struct kmod_list; * Iterate over the list @list. */ #define kmod_list_foreach(curr, list) \ - for (curr = list; \ - curr != NULL; \ - curr = kmod_list_next(list, curr)) + for (curr = list; curr != NULL; curr = kmod_list_next(list, curr)) /** * kmod_list_foreach_reverse: @@ -302,9 +295,7 @@ struct kmod_list; * Iterate in reverse over the list @list. */ #define kmod_list_foreach_reverse(curr, list) \ - for (curr = kmod_list_last(list); \ - curr != NULL; \ - curr = kmod_list_prev(list, curr)) + for (curr = kmod_list_last(list); curr != NULL; curr = kmod_list_prev(list, curr)) /** * kmod_list_last: @@ -339,7 +330,7 @@ struct kmod_list *kmod_list_last(const struct kmod_list *list); * Since: 1 */ struct kmod_list *kmod_list_next(const struct kmod_list *list, - const struct kmod_list *curr); + const struct kmod_list *curr); /** * kmod_list_prev: @@ -357,9 +348,7 @@ struct kmod_list *kmod_list_next(const struct kmod_list *list, * Since: 1 */ struct kmod_list *kmod_list_prev(const struct kmod_list *list, - const struct kmod_list *curr); - - + const struct kmod_list *curr); /** * SECTION:libkmod-config @@ -542,7 +531,6 @@ bool kmod_config_iter_next(struct kmod_config_iter *iter); */ void kmod_config_iter_free_iter(struct kmod_config_iter *iter); - /** * SECTION:libkmod-module * @short_description: operate on kernel modules @@ -588,7 +576,7 @@ struct kmod_module; * Since: 1 */ int kmod_module_new_from_lookup(struct kmod_ctx *ctx, const char *given_alias, - struct kmod_list **list); + struct kmod_list **list); /** * kmod_module_new_from_name_lookup: @@ -616,8 +604,7 @@ int kmod_module_new_from_lookup(struct kmod_ctx *ctx, const char *given_alias, * * Since: 30 */ -int kmod_module_new_from_name_lookup(struct kmod_ctx *ctx, - const char *modname, +int kmod_module_new_from_name_lookup(struct kmod_ctx *ctx, const char *modname, struct kmod_module **mod); /** @@ -645,7 +632,7 @@ int kmod_module_new_from_name_lookup(struct kmod_ctx *ctx, * Since: 1 */ int kmod_module_new_from_name(struct kmod_ctx *ctx, const char *name, - struct kmod_module **mod); + struct kmod_module **mod); /** * kmod_module_new_from_path: @@ -671,8 +658,7 @@ int kmod_module_new_from_name(struct kmod_ctx *ctx, const char *name, * Since: 1 */ int kmod_module_new_from_path(struct kmod_ctx *ctx, const char *path, - struct kmod_module **mod); - + struct kmod_module **mod); /** * kmod_module_ref: @@ -713,7 +699,6 @@ struct kmod_module *kmod_module_unref(struct kmod_module *mod); */ int kmod_module_unref_list(struct kmod_list *list); - /** * kmod_insert: * @KMOD_INSERT_FORCE_VERMAGIC: ignore kernel version magic @@ -742,7 +727,7 @@ enum kmod_insert { * Since: 1 */ int kmod_module_insert_module(struct kmod_module *mod, unsigned int flags, - const char *options); + const char *options); /** * kmod_probe: @@ -768,17 +753,17 @@ int kmod_module_insert_module(struct kmod_module *mod, unsigned int flags, * Bitmask which defines the behaviour of kmod_module_probe_insert_module(). */ enum kmod_probe { - KMOD_PROBE_FORCE_VERMAGIC = 0x00001, - KMOD_PROBE_FORCE_MODVERSION = 0x00002, - KMOD_PROBE_IGNORE_COMMAND = 0x00004, - KMOD_PROBE_IGNORE_LOADED = 0x00008, - KMOD_PROBE_DRY_RUN = 0x00010, - KMOD_PROBE_FAIL_ON_LOADED = 0x00020, + KMOD_PROBE_FORCE_VERMAGIC = 0x00001, + KMOD_PROBE_FORCE_MODVERSION = 0x00002, + KMOD_PROBE_IGNORE_COMMAND = 0x00004, + KMOD_PROBE_IGNORE_LOADED = 0x00008, + KMOD_PROBE_DRY_RUN = 0x00010, + KMOD_PROBE_FAIL_ON_LOADED = 0x00020, /* codes below can be used in return value, too */ - KMOD_PROBE_APPLY_BLACKLIST_ALL = 0x10000, - KMOD_PROBE_APPLY_BLACKLIST = 0x20000, - KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY = 0x40000, + KMOD_PROBE_APPLY_BLACKLIST_ALL = 0x10000, + KMOD_PROBE_APPLY_BLACKLIST = 0x20000, + KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY = 0x40000, }; /** @@ -807,13 +792,11 @@ enum kmod_probe { * * Since: 3 */ -int kmod_module_probe_insert_module(struct kmod_module *mod, - unsigned int flags, const char *extra_options, - int (*run_install)(struct kmod_module *m, - const char *cmdline, void *data), - const void *data, - void (*print_action)(struct kmod_module *m, bool install, - const char *options)); +int kmod_module_probe_insert_module( + struct kmod_module *mod, unsigned int flags, const char *extra_options, + int (*run_install)(struct kmod_module *m, const char *cmdline, void *data), + const void *data, + void (*print_action)(struct kmod_module *m, bool install, const char *options)); /** * kmod_remove: @@ -845,7 +828,6 @@ enum kmod_remove { */ int kmod_module_remove_module(struct kmod_module *mod, unsigned int flags); - /** * kmod_module_get_module: * @entry: an entry in a list of kmod modules. @@ -896,8 +878,8 @@ struct kmod_list *kmod_module_get_dependencies(const struct kmod_module *mod); * * Since: 2 */ -int kmod_module_get_softdeps(const struct kmod_module *mod, - struct kmod_list **pre, struct kmod_list **post); +int kmod_module_get_softdeps(const struct kmod_module *mod, struct kmod_list **pre, + struct kmod_list **post); /** * kmod_module_get_weakdeps: @@ -917,8 +899,7 @@ int kmod_module_get_softdeps(const struct kmod_module *mod, * * Since: 33 */ -int kmod_module_get_weakdeps(const struct kmod_module *mod, - struct kmod_list **weak); +int kmod_module_get_weakdeps(const struct kmod_module *mod, struct kmod_list **weak); /** * kmod_filter: @@ -947,10 +928,8 @@ enum kmod_filter { * * Since: 6 */ -int kmod_module_apply_filter(const struct kmod_ctx *ctx, - enum kmod_filter filter_type, - const struct kmod_list *input, - struct kmod_list **output); +int kmod_module_apply_filter(const struct kmod_ctx *ctx, enum kmod_filter filter_type, + const struct kmod_list *input, struct kmod_list **output); /** * kmod_module_get_filtered_blacklist: @@ -969,8 +948,9 @@ int kmod_module_apply_filter(const struct kmod_ctx *ctx, * Since: 1 */ int kmod_module_get_filtered_blacklist(const struct kmod_ctx *ctx, - const struct kmod_list *input, - struct kmod_list **output) __attribute__ ((deprecated)); + const struct kmod_list *input, + struct kmod_list **output) + __attribute__((deprecated)); /** * kmod_module_get_install_commands: @@ -1052,7 +1032,6 @@ const char *kmod_module_get_options(const struct kmod_module *mod); */ const char *kmod_module_get_path(const struct kmod_module *mod); - /** * kmod_module_get_dependency_symbols: * @mod: kmod module @@ -1071,7 +1050,8 @@ const char *kmod_module_get_path(const struct kmod_module *mod); * * Since: 3 */ -int kmod_module_get_dependency_symbols(const struct kmod_module *mod, struct kmod_list **list); +int kmod_module_get_dependency_symbols(const struct kmod_module *mod, + struct kmod_list **list); /** * kmod_symbol_bind: @@ -1139,7 +1119,6 @@ const char *kmod_module_dependency_symbol_get_symbol(const struct kmod_list *ent */ void kmod_module_dependency_symbols_free_list(struct kmod_list *list); - /** * kmod_module_get_sections: * @mod: kmod module @@ -1194,7 +1173,6 @@ const char *kmod_module_section_get_name(const struct kmod_list *entry); */ void kmod_module_section_free_list(struct kmod_list *list); - /** * kmod_module_get_symbols: * @mod: kmod module @@ -1249,7 +1227,6 @@ const char *kmod_module_symbol_get_symbol(const struct kmod_list *entry); */ void kmod_module_symbols_free_list(struct kmod_list *list); - /** * kmod_module_get_versions: * @mod: kmod module @@ -1304,7 +1281,6 @@ const char *kmod_module_version_get_symbol(const struct kmod_list *entry); */ void kmod_module_versions_free_list(struct kmod_list *list); - /** * kmod_module_get_info: * @mod: kmod module @@ -1364,8 +1340,6 @@ const char *kmod_module_info_get_value(const struct kmod_list *entry); */ void kmod_module_info_free_list(struct kmod_list *list); - - /** * SECTION:libkmod-loaded * @short_description: currently loaded modules @@ -1396,8 +1370,7 @@ void kmod_module_info_free_list(struct kmod_list *list); * * Since: 1 */ -int kmod_module_new_from_loaded(struct kmod_ctx *ctx, - struct kmod_list **list); +int kmod_module_new_from_loaded(struct kmod_ctx *ctx, struct kmod_list **list); /** * kmod_module_initstate: