Skip to content

Commit

Permalink
modpost: remove use of non-standard strsep() in HOSTCC code
Browse files Browse the repository at this point in the history
strsep() is neither standard C nor POSIX and used outside
the kernel code here. Using it here requires that the
build host supports it out of the box which is e.g.
not true for a Darwin build host and using a cross-compiler.
This leads to:

scripts/mod/modpost.c:145:2: warning: implicit declaration of function 'strsep' [-Wimplicit-function-declaration]
  return strsep(stringp, "\n");
  ^

and a segfault when running MODPOST.

See also: https://stackoverflow.com/a/7219504

So let's replace this by strchr() instead of using strsep().
It does not hurt kernel size or speed since this code is run
on the build host.

Fixes: ac5100f ("modpost: add read_text_file() and get_line() helpers")
Co-developed-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
  • Loading branch information
H. Nikolaus Schaller authored and Masahiro Yamada committed Jul 7, 2020
1 parent dcb7fd8 commit 736bb11
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
@@ -138,11 +138,19 @@ char *read_text_file(const char *filename)

char *get_line(char **stringp)
{
char *orig = *stringp, *next;

/* do not return the unwanted extra line at EOF */
if (*stringp && **stringp == '\0')
if (!orig || *orig == '\0')
return NULL;

return strsep(stringp, "\n");
next = strchr(orig, '\n');
if (next)
*next++ = '\0';

*stringp = next;

return orig;
}

/* A list of all modules we processed */

0 comments on commit 736bb11

Please sign in to comment.