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

modpost: use read_text_file() and get_line() for reading text files

grab_file() mmaps a file, but it is not so efficient here because
get_next_line() copies every line to the temporary buffer anyway.

read_text_file() and get_line() are simpler. get_line() exploits the
library function strchr().

Going forward, the missing *.symvers or *.cmd is a fatal error.
This should not happen because scripts/Makefile.modpost guards the
-i option files with $(wildcard $(input-symdump)).

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

+14 -17
+8 -7
scripts/mod/modpost.c
··· 2481 2481 **/ 2482 2482 static void read_dump(const char *fname) 2483 2483 { 2484 - unsigned long size, pos = 0; 2485 - void *file = grab_file(fname, &size); 2486 - char *line; 2484 + char *buf, *pos, *line; 2487 2485 2488 - if (!file) 2486 + buf = read_text_file(fname); 2487 + if (!buf) 2489 2488 /* No symbol versions, silently ignore */ 2490 2489 return; 2491 2490 2492 - while ((line = get_next_line(&pos, file, size))) { 2491 + pos = buf; 2492 + 2493 + while ((line = get_line(&pos))) { 2493 2494 char *symname, *namespace, *modname, *d, *export; 2494 2495 unsigned int crc; 2495 2496 struct module *mod; ··· 2525 2524 sym_set_crc(symname, crc); 2526 2525 sym_update_namespace(symname, namespace); 2527 2526 } 2528 - release_file(file, size); 2527 + free(buf); 2529 2528 return; 2530 2529 fail: 2531 - release_file(file, size); 2530 + free(buf); 2532 2531 fatal("parse error in symbol dump file\n"); 2533 2532 } 2534 2533
+6 -10
scripts/mod/sumversion.c
··· 303 303 * to figure out source files. */ 304 304 static int parse_source_files(const char *objfile, struct md4_ctx *md) 305 305 { 306 - char *cmd, *file, *line, *dir; 306 + char *cmd, *file, *line, *dir, *pos; 307 307 const char *base; 308 - unsigned long flen, pos = 0; 309 308 int dirlen, ret = 0, check_files = 0; 310 309 311 310 cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd"))); ··· 322 323 strncpy(dir, objfile, dirlen); 323 324 dir[dirlen] = '\0'; 324 325 325 - file = grab_file(cmd, &flen); 326 - if (!file) { 327 - warn("could not find %s for %s\n", cmd, objfile); 328 - goto out; 329 - } 326 + file = read_text_file(cmd); 327 + 328 + pos = file; 330 329 331 330 /* Sum all files in the same dir or subdirs. */ 332 - while ((line = get_next_line(&pos, file, flen)) != NULL) { 331 + while ((line = get_line(&pos))) { 333 332 char* p = line; 334 333 335 334 if (strncmp(line, "source_", sizeof("source_")-1) == 0) { ··· 378 381 /* Everyone parsed OK */ 379 382 ret = 1; 380 383 out_file: 381 - release_file(file, flen); 382 - out: 384 + free(file); 383 385 free(dir); 384 386 free(cmd); 385 387 return ret;