Commit 70f30cfe authored by Masahiro Yamada's avatar Masahiro Yamada

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: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent 7c8f5662
...@@ -2481,15 +2481,16 @@ static void write_if_changed(struct buffer *b, const char *fname) ...@@ -2481,15 +2481,16 @@ static void write_if_changed(struct buffer *b, const char *fname)
**/ **/
static void read_dump(const char *fname) static void read_dump(const char *fname)
{ {
unsigned long size, pos = 0; char *buf, *pos, *line;
void *file = grab_file(fname, &size);
char *line;
if (!file) buf = read_text_file(fname);
if (!buf)
/* No symbol versions, silently ignore */ /* No symbol versions, silently ignore */
return; return;
while ((line = get_next_line(&pos, file, size))) { pos = buf;
while ((line = get_line(&pos))) {
char *symname, *namespace, *modname, *d, *export; char *symname, *namespace, *modname, *d, *export;
unsigned int crc; unsigned int crc;
struct module *mod; struct module *mod;
...@@ -2524,10 +2525,10 @@ static void read_dump(const char *fname) ...@@ -2524,10 +2525,10 @@ static void read_dump(const char *fname)
sym_set_crc(symname, crc); sym_set_crc(symname, crc);
sym_update_namespace(symname, namespace); sym_update_namespace(symname, namespace);
} }
release_file(file, size); free(buf);
return; return;
fail: fail:
release_file(file, size); free(buf);
fatal("parse error in symbol dump file\n"); fatal("parse error in symbol dump file\n");
} }
......
...@@ -303,9 +303,8 @@ static int is_static_library(const char *objfile) ...@@ -303,9 +303,8 @@ static int is_static_library(const char *objfile)
* to figure out source files. */ * to figure out source files. */
static int parse_source_files(const char *objfile, struct md4_ctx *md) static int parse_source_files(const char *objfile, struct md4_ctx *md)
{ {
char *cmd, *file, *line, *dir; char *cmd, *file, *line, *dir, *pos;
const char *base; const char *base;
unsigned long flen, pos = 0;
int dirlen, ret = 0, check_files = 0; int dirlen, ret = 0, check_files = 0;
cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd"))); cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd")));
...@@ -323,14 +322,12 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md) ...@@ -323,14 +322,12 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
strncpy(dir, objfile, dirlen); strncpy(dir, objfile, dirlen);
dir[dirlen] = '\0'; dir[dirlen] = '\0';
file = grab_file(cmd, &flen); file = read_text_file(cmd);
if (!file) {
warn("could not find %s for %s\n", cmd, objfile); pos = file;
goto out;
}
/* Sum all files in the same dir or subdirs. */ /* Sum all files in the same dir or subdirs. */
while ((line = get_next_line(&pos, file, flen)) != NULL) { while ((line = get_line(&pos))) {
char* p = line; char* p = line;
if (strncmp(line, "source_", sizeof("source_")-1) == 0) { if (strncmp(line, "source_", sizeof("source_")-1) == 0) {
...@@ -381,8 +378,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md) ...@@ -381,8 +378,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
/* Everyone parsed OK */ /* Everyone parsed OK */
ret = 1; ret = 1;
out_file: out_file:
release_file(file, flen); free(file);
out:
free(dir); free(dir);
free(cmd); free(cmd);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment