]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf util: Fix compression checks returning -1 as bool
authorYunseong Kim <ysk@kzalloc.com>
Fri, 22 Aug 2025 16:25:08 +0000 (16:25 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 19 Oct 2025 14:33:36 +0000 (16:33 +0200)
[ Upstream commit 43fa1141e2c1af79c91aaa4df03e436c415a6fc3 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/perf/util/lzma.c
tools/perf/util/zlib.c

index af9a97612f9df39206031b7b8dcbe86114ebe5c6..f61574d1581e3c01961f076131d34c2092d2c08d 100644 (file)
@@ -113,7 +113,7 @@ bool lzma_is_compressed(const char *input)
        ssize_t rc;
 
        if (fd < 0)
-               return -1;
+               return false;
 
        rc = read(fd, buf, sizeof(buf));
        close(fd);
index 78d2297c1b67463be02d2f7145da54d2b4dbf32d..1f7c065230599d8a37b51bcf4e27780b5856ef38 100644 (file)
@@ -88,7 +88,7 @@ bool gzip_is_compressed(const char *input)
        ssize_t rc;
 
        if (fd < 0)
-               return -1;
+               return false;
 
        rc = read(fd, buf, sizeof(buf));
        close(fd);