[PATCH] perf lzma: Fix return value in lzma_is_compressed()

Miaoqian Lin posted 1 patch 5 months, 1 week ago
tools/perf/util/lzma.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] perf lzma: Fix return value in lzma_is_compressed()
Posted by Miaoqian Lin 5 months, 1 week ago
lzma_is_compressed() returns -1 on error but is declared as bool.
And -1 gets converted to true, which could be misleading.
Return false instead to match the declared type.

Fixes: 4b57fd44b61b ("perf tools: Add lzma_is_compressed function")
Cc: <stable@vger.kernel.org>
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 tools/perf/util/lzma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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);
-- 
2.39.5 (Apple Git-154)
Re: [PATCH] perf lzma: Fix return value in lzma_is_compressed()
Posted by Mi, Dapeng 3 months, 4 weeks ago
On 8/28/2025 6:50 PM, Miaoqian Lin wrote:
> lzma_is_compressed() returns -1 on error but is declared as bool.
> And -1 gets converted to true, which could be misleading.
> Return false instead to match the declared type.
>
> Fixes: 4b57fd44b61b ("perf tools: Add lzma_is_compressed function")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  tools/perf/util/lzma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> 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);

Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>