Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

modpost: replace the use of NOFAIL() with xmalloc() etc.

I think x*alloc() functions are cleaner.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+17 -27
+10 -18
scripts/mod/modpost.c
··· 23 23 24 24 #include <hashtable.h> 25 25 #include <list.h> 26 + #include <xalloc.h> 26 27 #include "modpost.h" 27 28 #include "../../include/linux/license.h" 28 29 ··· 98 97 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; 99 98 } 100 99 101 - void *do_nofail(void *ptr, const char *expr) 102 - { 103 - if (!ptr) 104 - fatal("Memory allocation failure: %s.\n", expr); 105 - 106 - return ptr; 107 - } 108 - 109 100 char *read_text_file(const char *filename) 110 101 { 111 102 struct stat st; ··· 116 123 exit(1); 117 124 } 118 125 119 - buf = NOFAIL(malloc(st.st_size + 1)); 126 + buf = xmalloc(st.st_size + 1); 120 127 121 128 nbytes = st.st_size; 122 129 ··· 174 181 { 175 182 struct module *mod; 176 183 177 - mod = NOFAIL(malloc(sizeof(*mod) + namelen + 1)); 184 + mod = xmalloc(sizeof(*mod) + namelen + 1); 178 185 memset(mod, 0, sizeof(*mod)); 179 186 180 187 INIT_LIST_HEAD(&mod->exported_symbols); ··· 233 240 **/ 234 241 static struct symbol *alloc_symbol(const char *name) 235 242 { 236 - struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1)); 243 + struct symbol *s = xmalloc(sizeof(*s) + strlen(name) + 1); 237 244 238 245 memset(s, 0, sizeof(*s)); 239 246 strcpy(s->name, name); ··· 306 313 struct namespace_list *ns_entry; 307 314 308 315 if (!contains_namespace(head, namespace)) { 309 - ns_entry = NOFAIL(malloc(sizeof(*ns_entry) + 310 - strlen(namespace) + 1)); 316 + ns_entry = xmalloc(sizeof(*ns_entry) + strlen(namespace) + 1); 311 317 strcpy(ns_entry->namespace, namespace); 312 318 list_add_tail(&ns_entry->list, head); 313 319 } ··· 361 369 s = alloc_symbol(name); 362 370 s->module = mod; 363 371 s->is_gpl_only = gpl_only; 364 - s->namespace = NOFAIL(strdup(namespace)); 372 + s->namespace = xstrdup(namespace); 365 373 list_add_tail(&s->list, &mod->exported_symbols); 366 374 hash_add_symbol(s); 367 375 ··· 629 637 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) 630 638 break; 631 639 if (symname[0] == '.') { 632 - char *munged = NOFAIL(strdup(symname)); 640 + char *munged = xstrdup(symname); 633 641 munged[0] = '_'; 634 642 munged[1] = toupper(munged[1]); 635 643 symname = munged; ··· 1669 1677 { 1670 1678 if (buf->size - buf->pos < len) { 1671 1679 buf->size += len + SZ; 1672 - buf->p = NOFAIL(realloc(buf->p, buf->size)); 1680 + buf->p = xrealloc(buf->p, buf->size); 1673 1681 } 1674 1682 strncpy(buf->p + buf->pos, s, len); 1675 1683 buf->pos += len; ··· 1954 1962 if (st.st_size != b->pos) 1955 1963 goto close_write; 1956 1964 1957 - tmp = NOFAIL(malloc(b->pos)); 1965 + tmp = xmalloc(b->pos); 1958 1966 if (fread(tmp, 1, b->pos, file) != b->pos) 1959 1967 goto free_write; 1960 1968 ··· 2159 2167 external_module = true; 2160 2168 break; 2161 2169 case 'i': 2162 - dl = NOFAIL(malloc(sizeof(*dl))); 2170 + dl = xmalloc(sizeof(*dl)); 2163 2171 dl->file = optarg; 2164 2172 list_add_tail(&dl->list, &dump_lists); 2165 2173 break;
-4
scripts/mod/modpost.h
··· 65 65 #define TO_NATIVE(x) \ 66 66 (target_is_big_endian == host_is_big_endian ? x : bswap(x)) 67 67 68 - #define NOFAIL(ptr) do_nofail((ptr), #ptr) 69 - 70 68 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 71 - 72 - void *do_nofail(void *ptr, const char *expr); 73 69 74 70 struct buffer { 75 71 char *p;
+4 -2
scripts/mod/sumversion.c
··· 8 8 #include <errno.h> 9 9 #include <string.h> 10 10 #include <limits.h> 11 + 12 + #include <xalloc.h> 11 13 #include "modpost.h" 12 14 13 15 /* ··· 307 305 const char *base; 308 306 int dirlen, ret = 0, check_files = 0; 309 307 310 - cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd"))); 308 + cmd = xmalloc(strlen(objfile) + sizeof("..cmd")); 311 309 312 310 base = strrchr(objfile, '/'); 313 311 if (base) { ··· 318 316 dirlen = 0; 319 317 sprintf(cmd, ".%s.cmd", objfile); 320 318 } 321 - dir = NOFAIL(malloc(dirlen + 1)); 319 + dir = xmalloc(dirlen + 1); 322 320 strncpy(dir, objfile, dirlen); 323 321 dir[dirlen] = '\0'; 324 322
+3 -3
scripts/mod/symsearch.c
··· 4 4 * Helper functions for finding the symbol in an ELF which is "nearest" 5 5 * to a given address. 6 6 */ 7 - 7 + #include <xalloc.h> 8 8 #include "modpost.h" 9 9 10 10 struct syminfo { ··· 125 125 { 126 126 unsigned int table_size = symbol_count(elf); 127 127 128 - elf->symsearch = NOFAIL(malloc(sizeof(struct symsearch) + 129 - sizeof(struct syminfo) * table_size)); 128 + elf->symsearch = xmalloc(sizeof(struct symsearch) + 129 + sizeof(struct syminfo) * table_size); 130 130 elf->symsearch->table_size = table_size; 131 131 132 132 symsearch_populate(elf, elf->symsearch->table, table_size);