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

modpost: avoid false-positive file open error

One problem of grab_file() is that it cannot distinguish the following
two cases:

- It cannot read the file (the file does not exist, or read permission
is not set)

- It can read the file, but the file size is zero

This is because grab_file() calls mmap(), which requires the mapped
length is greater than 0. Hence, grab_file() fails for both cases.

If an empty header file were included for checksum calculation, the
following warning would be printed:

WARNING: modpost: could not open ...: Invalid argument

An empty file is a valid source file, so it should not fail.

Use read_text_file() instead. It can read a zero-length file.
Then, parse_file() will succeed with doing nothing.

Going forward, the first case (it cannot read the file) is a fatal
error. If the source file from which an object was compiled is missing,
something went wrong.

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

+3 -4
+3 -4
scripts/mod/sumversion.c
··· 258 258 char *file; 259 259 unsigned long i, len; 260 260 261 - file = grab_file(fname, &len); 262 - if (!file) 263 - return 0; 261 + file = read_text_file(fname); 262 + len = strlen(file); 264 263 265 264 for (i = 0; i < len; i++) { 266 265 /* Collapse and ignore \ and CR. */ ··· 286 287 287 288 add_char(file[i], md); 288 289 } 289 - release_file(file, len); 290 + free(file); 290 291 return 1; 291 292 } 292 293 /* Check whether the file is a static library or not */