if (!stat(path, &st) && S_ISDIR(st.st_mode)) {
module_folders = realloc(module_folders, sizeof(p) * (n + 2));
- if (!module_folders)
+ if (!module_folders) {
+ ULOG_ERR("out of memory\n");
return -1;
+ }
module_folders[n++] = strdup(path);
}
int clazz = map[EI_CLASS];
int endian = map[EI_DATA];
-#if defined(__LITTLE_ENDIAN)
+#if __BYTE_ORDER == __LITTLE_ENDIAN
if (endian != ELFDATA2LSB)
-#elif defined(__BIG_ENDIAN)
+#elif __BYTE_ORDER == __BIG_ENDIAN
if (endian != ELFDATA2MSB)
#else
#error "unsupported endian"
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;
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) {
+ ULOG_ERR("out of memory\n");
+ goto out;
+ }
+
+ aliases[naliases++] = sep;
}
strings = &sep[strlen(sep)];
}
if (fd >= 0)
close(fd);
+ free(aliases);
+
return m;
}
struct utsname ver;
char *path;
glob_t gl;
- int j;
+ int j, rv = 0;
uname(&ver);
path = alloca(strlen(dir) + sizeof("*.ko") + 1);
continue;
m = find_module(name);
- if (!m)
- get_module_info(gl.gl_pathv[j], name);
+ if (!m) {
+ if (!get_module_info(gl.gl_pathv[j], name))
+ rv |= -1;
+ }
}
globfree(&gl);
- return 0;
+ return rv;
}
static int scan_module_folders(void)
}
data = malloc(s.st_size);
+ if (!data) {
+ ULOG_ERR("out of memory\n");
+ goto out;
+ }
+
if (read(fd, data, s.st_size) == s.st_size) {
ret = syscall(__NR_init_module, data, (unsigned long) s.st_size, options);
if (errno == EEXIST)
else
ULOG_ERR("failed to read full module %s\n", path);
+out:
close(fd);
free(data);
len += strlen(argv[i]) + 1;
options = malloc(len);
+ if (!options) {
+ ULOG_ERR("out of memory\n");
+ ret = -1;
+ goto err;
+ }
+
options[0] = 0;
cur = options;
for (i = 2; i < argc; i++) {
dir = argv[1];
path = malloc(strlen(dir) + 2);
+ if (!path) {
+ ULOG_ERR("out of memory\n");
+ return -1;
+ }
+
strcpy(path, dir);
strcat(path, "*");