All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf util: Fix compression checks returning -1 as bool
@ 2025-08-22 16:25 Yunseong Kim
  2025-08-22 16:34 ` Ian Rogers
  0 siblings, 1 reply; 3+ messages in thread
From: Yunseong Kim @ 2025-08-22 16:25 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers,
	Alexander Shishkin, Jiri Olsa
  Cc: Adrian Hunter, Liang, Kan, Stephen Brennan, linux-perf-users,
	linux-kernel, Yunseong Kim

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: 4b57fd44b61b ("perf tools: Add lzma_is_compressed function")
Fixes: 88c74dc76a30 ("perf tools: Add gzip_is_compressed function")
Signed-off-by: Yunseong Kim <ysk@kzalloc.com>
---
 tools/perf/util/lzma.c | 2 +-
 tools/perf/util/zlib.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c
index bbcd2ffcf4bd..c355757ed391 100644
--- a/tools/perf/util/lzma.c
+++ b/tools/perf/util/lzma.c
@@ -120,7 +120,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);
diff --git a/tools/perf/util/zlib.c b/tools/perf/util/zlib.c
index 78d2297c1b67..1f7c06523059 100644
--- a/tools/perf/util/zlib.c
+++ b/tools/perf/util/zlib.c
@@ -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);
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf util: Fix compression checks returning -1 as bool
  2025-08-22 16:25 [PATCH] perf util: Fix compression checks returning -1 as bool Yunseong Kim
@ 2025-08-22 16:34 ` Ian Rogers
  2025-09-12 18:42   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2025-08-22 16:34 UTC (permalink / raw)
  To: Yunseong Kim
  Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, Liang, Kan, Stephen Brennan,
	linux-perf-users, linux-kernel

On Fri, Aug 22, 2025 at 9:28 AM Yunseong Kim <ysk@kzalloc.com> wrote:
>
> 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: 4b57fd44b61b ("perf tools: Add lzma_is_compressed function")
> Fixes: 88c74dc76a30 ("perf tools: Add gzip_is_compressed function")
> Signed-off-by: Yunseong Kim <ysk@kzalloc.com>

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/util/lzma.c | 2 +-
>  tools/perf/util/zlib.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c
> index bbcd2ffcf4bd..c355757ed391 100644
> --- a/tools/perf/util/lzma.c
> +++ b/tools/perf/util/lzma.c
> @@ -120,7 +120,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);
> diff --git a/tools/perf/util/zlib.c b/tools/perf/util/zlib.c
> index 78d2297c1b67..1f7c06523059 100644
> --- a/tools/perf/util/zlib.c
> +++ b/tools/perf/util/zlib.c
> @@ -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);
> --
> 2.50.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf util: Fix compression checks returning -1 as bool
  2025-08-22 16:34 ` Ian Rogers
@ 2025-09-12 18:42   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-09-12 18:42 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Yunseong Kim, Namhyung Kim, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Liang, Kan, Stephen Brennan, linux-perf-users,
	linux-kernel

On Fri, Aug 22, 2025 at 09:34:07AM -0700, Ian Rogers wrote:
> On Fri, Aug 22, 2025 at 9:28 AM Yunseong Kim <ysk@kzalloc.com> wrote:
> >
> > 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: 4b57fd44b61b ("perf tools: Add lzma_is_compressed function")
> > Fixes: 88c74dc76a30 ("perf tools: Add gzip_is_compressed function")
> > Signed-off-by: Yunseong Kim <ysk@kzalloc.com>
> 
> Reviewed-by: Ian Rogers <irogers@google.com>

Thanks, applied to perf-tools-next,

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-12 18:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22 16:25 [PATCH] perf util: Fix compression checks returning -1 as bool Yunseong Kim
2025-08-22 16:34 ` Ian Rogers
2025-09-12 18:42   ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.