diff options
author | Christian Marangi <ansuelsmth@gmail.com> | 2022-07-17 02:59:32 +0200 |
---|---|---|
committer | Christian Marangi <ansuelsmth@gmail.com> | 2022-07-17 02:59:32 +0200 |
commit | 46a33b8be298e1e700e56f05b5ba4f06daf83efa (patch) | |
tree | 361cddc2ab15141dda773db31735b50fa1836693 | |
parent | b87a4fdca6346a01c19e94fe0461fb9ef7493815 (diff) | |
download | ubox-46a33b8be298e1e700e56f05b5ba4f06daf83efa.tar.gz |
kmodloader: fix compilation warning with not checking return of asprintf
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>
-rw-r--r-- | kmodloader.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/kmodloader.c b/kmodloader.c index 26926a0..63bae5e 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -965,7 +965,7 @@ static int main_loader(int argc, char **argv) struct module *m; glob_t gl; char *path; - int fail, j; + int ret = 0, fail, j; if (argc > 1) dir = argv[1]; @@ -980,13 +980,13 @@ static int main_loader(int argc, char **argv) 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); @@ -1024,8 +1024,15 @@ static int main_loader(int argc, char **argv) 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); } @@ -1058,9 +1065,10 @@ static int main_loader(int argc, char **argv) out: globfree(&gl); +free_path: free(path); - return 0; + return ret; } static inline char weight(char c) |