On Wed, Aug 30, 2017 at 4:09 PM, Yousong Zhou <yszhou4t...@gmail.com> wrote: > On 30 August 2017 at 21:24, Hans Dedecker <dedec...@gmail.com> wrote: >> kmodloader has a restriction of storing only 32 aliases for a given >> module; as modules can have easily more than 32 aliases let's remove >> the restriction by using a dynamic allocation mechanism when retrieving >> the aliases. >> >> Signed-off-by: Hans Dedecker <dedec...@gmail.com> >> --- >> kmodloader.c | 14 ++++++++------ >> 1 file changed, 8 insertions(+), 6 deletions(-) >> >> diff --git a/kmodloader.c b/kmodloader.c >> index a4d492d..2ece0c2 100644 >> --- a/kmodloader.c >> +++ b/kmodloader.c >> @@ -340,7 +340,7 @@ static struct module* get_module_info(const char >> *module, const char *name) >> int fd = open(module, O_RDONLY); >> unsigned int offset, size; >> char *map = MAP_FAILED, *strings, *dep = NULL; >> - const char *aliases[32] = { 0 }; >> + const char **aliases = NULL; >> int naliases = 0; >> struct module *m = NULL; >> struct stat s; >> @@ -383,11 +383,11 @@ static struct module* get_module_info(const char >> *module, const char *name) >> if (!strncmp(strings, "depends=", len + 1)) >> dep = sep; >> else if (!strncmp(strings, "alias=", len + 1)) { >> - if (naliases < ARRAY_SIZE(aliases)) >> - aliases[naliases++] = sep; >> - else >> - ULOG_WARN("module %s has more than %d >> aliases: truncated", >> - name, ARRAY_SIZE(aliases)); >> + aliases = realloc(aliases, sizeof(sep) * (naliases + >> 1)); >> + if (!aliases) >> + goto out; > > We should probably just die("out of memory") in this case. Other than > that, ACK from me ;) My aim was to keep the code consistent when doing OOM error handling as another realloc failure also returned an error code which is handled by the calling function. Having said that I notice the get_module_info return code is not handled by scan_module_folder; would it be ok for you if in the follow-up patch the error code is handled instead of just die ?
Hans > > Regards, > yousong > >> + >> + aliases[naliases++] = sep; >> } >> strings = &sep[strlen(sep)]; >> } >> @@ -404,6 +404,8 @@ out: >> if (fd >= 0) >> close(fd); >> >> + free(aliases); >> + >> return m; >> } >> >> -- >> 1.9.1 >> _______________________________________________ Lede-dev mailing list Lede-dev@lists.infradead.org http://lists.infradead.org/mailman/listinfo/lede-dev