From 57520f821450d11b55fd214e5474b51dcfd0e767 Mon Sep 17 00:00:00 2001 From: zrj Date: Thu, 28 Apr 2016 16:09:18 +0300 Subject: [PATCH] Use size_t to remove casts. While there, perform some style(9) fixes. No functional change. --- sys/boot/common/module.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/sys/boot/common/module.c b/sys/boot/common/module.c index 72335f85d5..81516a62fd 100644 --- a/sys/boot/common/module.c +++ b/sys/boot/common/module.c @@ -122,7 +122,7 @@ command_load(int argc, char *argv[]) { char *typestr; int dofile, dokld, ch, error; - + dokld = dofile = 0; optind = 1; optreset = 1; @@ -183,7 +183,7 @@ static int command_unload(int argc, char *argv[]) { struct preloaded_file *fp; - + while (preloaded_files != NULL) { fp = preloaded_files; preloaded_files = preloaded_files->f_next; @@ -291,7 +291,7 @@ command_lsmod(int argc, char *argv[]) pager_open(); for (fp = preloaded_files; fp; fp = fp->f_next) { - sprintf(lbuf, " %p: %s (%s, 0x%lx)\n", + sprintf(lbuf, " %p: %s (%s, 0x%lx)\n", (void *) fp->f_addr, fp->f_name, fp->f_type, (long) fp->f_size); pager_output(lbuf); if (fp->f_args != NULL) { @@ -349,7 +349,8 @@ file_load(char *filename, vm_offset_t dest, struct preloaded_file **result) } static int -file_load_dependencies(struct preloaded_file *base_file) { +file_load_dependencies(struct preloaded_file *base_file) +{ struct file_metadata *md; struct preloaded_file *fp; struct mod_depend *verinfo; @@ -394,6 +395,7 @@ file_load_dependencies(struct preloaded_file *base_file) { } return (error); } + /* * We've been asked to load (name) as (type), so just suck it in, * no arguments or anything. @@ -419,7 +421,7 @@ file_loadraw(char *type, char *name) return(CMD_ERROR); } name = cp; - + if ((fd = rel_open(name, NULL, O_RDONLY)) < 0) { sprintf(command_errbuf, "can't open '%s': %s", name, strerror(errno)); free(name); @@ -450,7 +452,7 @@ file_loadraw(char *type, char *name) } laddr += got; } - + /* Looks OK so far; create & populate control structure */ fp = file_alloc(); fp->f_name = name; @@ -526,7 +528,7 @@ mod_loadkld(const char *kldname, int argc, char *argv[]) sprintf(command_errbuf, "can't find '%s'", kldname); return (ENOENT); } - /* + /* * Check if KLD already loaded */ fp = file_findfile(filename, NULL); @@ -535,7 +537,7 @@ mod_loadkld(const char *kldname, int argc, char *argv[]) free(filename); return (0); } - for (last_file = preloaded_files; + for (last_file = preloaded_files; last_file != NULL && last_file->f_next != NULL; last_file = last_file->f_next) ; @@ -594,7 +596,7 @@ file_findmodule(struct preloaded_file *fp, char *modname, if (fp == NULL) { for (fp = preloaded_files; fp; fp = fp->f_next) { mp = file_findmodule(fp, modname, verinfo); - if (mp) + if (mp) return (mp); } return (NULL); @@ -608,7 +610,7 @@ file_findmodule(struct preloaded_file *fp, char *modname, mver = mp->m_version; if (mver == verinfo->md_ver_preferred) return (mp); - if (mver >= verinfo->md_ver_minimum && + if (mver >= verinfo->md_ver_minimum && mver <= verinfo->md_ver_maximum && mver > bestver) { best = mp; @@ -813,7 +815,7 @@ mod_search_hints(struct moduledir *mdp, const char *modname, found = 1; break; } - if (ival >= verinfo->md_ver_minimum && + if (ival >= verinfo->md_ver_minimum && ival <= verinfo->md_ver_maximum && ival > bestver) { bestver = ival; @@ -915,7 +917,7 @@ file_discard(struct preloaded_file *fp) mp1 = mp; mp = mp->m_next; free(mp1); - } + } if (fp->f_name != NULL) free(fp->f_name); if (fp->f_type != NULL) @@ -933,7 +935,7 @@ struct preloaded_file * file_alloc(void) { struct preloaded_file *fp; - + if ((fp = malloc(sizeof(struct preloaded_file))) != NULL) { bzero(fp, sizeof(struct preloaded_file)); } @@ -947,7 +949,7 @@ static void file_insert_tail(struct preloaded_file *fp) { struct preloaded_file *cm; - + /* Append to list of loaded file */ fp->f_next = NULL; if (preloaded_files == NULL) { @@ -986,7 +988,8 @@ moduledir_readhints(struct moduledir *mdp) if (mdp->d_hints != NULL || (mdp->d_flags & MDIR_NOHINTS)) return; path = moduledir_fullpath(mdp, "linker.hints"); - if (rel_stat(path, &st) != 0 || st.st_size < (ssize_t)(sizeof(version) + sizeof(int)) || + if (rel_stat(path, &st) != 0 || + st.st_size < (ssize_t)(sizeof(version) + sizeof(int)) || st.st_size > 100 * 1024 || (fd = rel_open(path, NULL, O_RDONLY)) < 0) { free(path); mdp->d_flags |= MDIR_NOHINTS; @@ -1023,7 +1026,7 @@ moduledir_rebuild(void) { struct moduledir *mdp, *mtmp; const char *path, *cp, *ep, *modlocal; - int cplen; + size_t cplen; path = getenv("module_path"); if (path == NULL) @@ -1044,7 +1047,7 @@ moduledir_rebuild(void) for (cplen = ep - cp; cplen > 1 && cp[cplen - 1] == '/'; cplen--) ; STAILQ_FOREACH(mdp, &moduledir_list, d_link) { - if (strlen(mdp->d_path) != (unsigned)cplen || bcmp(cp, mdp->d_path, cplen) != 0) + if (strlen(mdp->d_path) != cplen || bcmp(cp, mdp->d_path, cplen) != 0) continue; mdp->d_flags &= ~MDIR_REMOVED; break; @@ -1071,7 +1074,7 @@ moduledir_rebuild(void) cp = local_module_path; cplen = strlen(local_module_path); STAILQ_FOREACH(mdp, &moduledir_list, d_link) { - if (strlen(mdp->d_path) != (unsigned)cplen || bcmp(cp, mdp->d_path, cplen) != 0) + if (strlen(mdp->d_path) != cplen || bcmp(cp, mdp->d_path, cplen) != 0) continue; mdp->d_flags &= ~MDIR_REMOVED; break; -- 2.41.0