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

perf util: Fix compression checks returning -1 as bool

The lzma_is_compressed and gzip_is_compressed functions are declared
to return a "bool" type, but in case of an error (e.g., file open
failure), they incorrectly returned -1.

A bool type is a boolean value that is either true or false.
Returning -1 for a bool return type can lead to unexpected behavior
and may violate strict type-checking in some compilers.

Fix the return value to be false in error cases, ensuring the function
adheres to its declared return type improves for preventing potential
bugs related to type mismatch.

Fixes: 4b57fd44b61beb51 ("perf tools: Add lzma_is_compressed function")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Yunseong Kim <ysk@kzalloc.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Link: https://lore.kernel.org/r/20250822162506.316844-3-ysk@kzalloc.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Yunseong Kim and committed by
Arnaldo Carvalho de Melo
43fa1141 94d4dfbb

+2 -2
+1 -1
tools/perf/util/lzma.c
··· 120 120 ssize_t rc; 121 121 122 122 if (fd < 0) 123 - return -1; 123 + return false; 124 124 125 125 rc = read(fd, buf, sizeof(buf)); 126 126 close(fd);
+1 -1
tools/perf/util/zlib.c
··· 88 88 ssize_t rc; 89 89 90 90 if (fd < 0) 91 - return -1; 91 + return false; 92 92 93 93 rc = read(fd, buf, sizeof(buf)); 94 94 close(fd);