From 46a33b8be298e1e700e56f05b5ba4f06daf83efa Mon Sep 17 00:00:00 2001 From: Christian Marangi Date: Sun, 17 Jul 2022 02:59:32 +0200 Subject: 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 --- kmodloader.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'kmodloader.c') 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) -- cgit v1.2.1