Skip to content

Commit 70f30cf

Browse files
committed
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>
1 parent 7c8f566 commit 70f30cf

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

‎scripts/mod/modpost.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,15 +2481,16 @@ static void write_if_changed(struct buffer *b, const char *fname)
24812481
**/
24822482
static void read_dump(const char *fname)
24832483
{
2484-
unsigned long size, pos = 0;
2485-
void *file = grab_file(fname, &size);
2486-
char *line;
2484+
char *buf, *pos, *line;
24872485

2488-
if (!file)
2486+
buf = read_text_file(fname);
2487+
if (!buf)
24892488
/* No symbol versions, silently ignore */
24902489
return;
24912490

2492-
while ((line = get_next_line(&pos, file, size))) {
2491+
pos = buf;
2492+
2493+
while ((line = get_line(&pos))) {
24932494
char *symname, *namespace, *modname, *d, *export;
24942495
unsigned int crc;
24952496
struct module *mod;
@@ -2524,10 +2525,10 @@ static void read_dump(const char *fname)
25242525
sym_set_crc(symname, crc);
25252526
sym_update_namespace(symname, namespace);
25262527
}
2527-
release_file(file, size);
2528+
free(buf);
25282529
return;
25292530
fail:
2530-
release_file(file, size);
2531+
free(buf);
25312532
fatal("parse error in symbol dump file\n");
25322533
}
25332534

‎scripts/mod/sumversion.c‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ static int is_static_library(const char *objfile)
303303
* to figure out source files. */
304304
static int parse_source_files(const char *objfile, struct md4_ctx *md)
305305
{
306-
char *cmd, *file, *line, *dir;
306+
char *cmd, *file, *line, *dir, *pos;
307307
const char *base;
308-
unsigned long flen, pos = 0;
309308
int dirlen, ret = 0, check_files = 0;
310309

311310
cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd")));
@@ -323,14 +322,12 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
323322
strncpy(dir, objfile, dirlen);
324323
dir[dirlen] = '\0';
325324

326-
file = grab_file(cmd, &flen);
327-
if (!file) {
328-
warn("could not find %s for %s\n", cmd, objfile);
329-
goto out;
330-
}
325+
file = read_text_file(cmd);
326+
327+
pos = file;
331328

332329
/* Sum all files in the same dir or subdirs. */
333-
while ((line = get_next_line(&pos, file, flen)) != NULL) {
330+
while ((line = get_line(&pos))) {
334331
char* p = line;
335332

336333
if (strncmp(line, "source_", sizeof("source_")-1) == 0) {
@@ -381,8 +378,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
381378
/* Everyone parsed OK */
382379
ret = 1;
383380
out_file:
384-
release_file(file, flen);
385-
out:
381+
free(file);
386382
free(dir);
387383
free(cmd);
388384
return ret;

0 commit comments

Comments
 (0)