Fix the following compilation warning:
kmodloader.c: In function 'main_loader':
kmodloader.c:1027:41: error: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result' [-Werror=unused-result]
make[1]: *** [package/Makefile:116: package/system/ubox/compile] Error 1
1027 | asprintf(&m->opts, "%s %s", prev, opts);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
While at it rework the function to not duplicate too much code with the
error handling.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
struct module *m;
glob_t gl;
char *path;
- int fail, j;
+ int ret = 0, fail, j;
if (argc > 1)
dir = argv[1];
strcat(path, "*");
if (scan_module_folders()) {
- free (path);
- return -1;
+ ret = -1;
+ goto free_path;
}
if (scan_loaded_modules()) {
- free (path);
- return -1;
+ ret = -1;
+ goto free_path;
}
ULOG_INFO("loading kernel modules from %s\n", path);
if (m->opts) {
char *prev = m->opts;
- asprintf(&m->opts, "%s %s", prev, opts);
+ fail = asprintf(&m->opts, "%s %s", prev, opts);
free(prev);
+ if (fail < 0) {
+ ULOG_ERR("out of memory for opts %s\n", opts);
+ free(mod);
+ fclose(fp);
+ ret = -1;
+ goto out;
+ }
} else {
m->opts = strdup(opts);
}
out:
globfree(&gl);
+free_path:
free(path);
- return 0;
+ return ret;
}
static inline char weight(char c)