scripts/ always open files in binary mode

The spdxcheck script currently falls over when confronted with a binary
file (such as Documentation/logo.gif).  To avoid that, always open files
in binary mode and decode line-by-line, ignoring encoding errors.

One tricky case is when piping data into the script and reading it from
standard input.  By default, standard input will be opened in text mode,
so we need to reopen it in binary mode.

The breakage only happens with python3 and results in a
UnicodeDecodeError (according to Uwe).

Fixes: 6f4d29df66ac ("scripts/ make python3 compliant")
Signed-off-by: Thierry Reding <>
Reviewed-by: Jeremy Cline <>
Cc: Thomas Gleixner <>
Cc: Jonathan Corbet <>
Cc: Joe Perches <>
Cc: Uwe Kleine-K├Ânig <>
Cc: <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
1 file changed