All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Shawn Lin <shawn.lin@rock-chips.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf tools: Fix error handling of lzma decompression
Date: Wed, 24 Aug 2016 11:25:04 -0300	[thread overview]
Message-ID: <20160824142504.GD10063@kernel.org> (raw)
In-Reply-To: <1471766253-1964-1-git-send-email-shawn.lin@rock-chips.com>

Em Sun, Aug 21, 2016 at 03:57:33PM +0800, Shawn Lin escreveu:
> lzma_decompress_to_file never actually close the file
> pointer, let's fix it.
> 
> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>

Thanks, I changed the logic a bit to shorten the patch, this is how it
ended up:


commit ffe67c2fabf128122b30fbf0ac498928e171b0b3
Author: Shawn Lin <shawn.lin@rock-chips.com>
Date:   Sun Aug 21 15:57:33 2016 +0800

    perf tools: Fix error handling of lzma decompression
    
    lzma_decompress_to_file() never actually closes the file pointer, let's
    fix it.
    
    Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: http://lkml.kernel.org/r/1471766253-1964-1-git-send-email-shawn.lin@rock-chips.com
    [ Make err = -1, the common case, set it to 0 before the error label ]
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c
index 95a1acb61245..9ddea5cecd94 100644
--- a/tools/perf/util/lzma.c
+++ b/tools/perf/util/lzma.c
@@ -29,6 +29,7 @@ int lzma_decompress_to_file(const char *input, int output_fd)
 	lzma_action action = LZMA_RUN;
 	lzma_stream strm   = LZMA_STREAM_INIT;
 	lzma_ret ret;
+	int err = -1;
 
 	u8 buf_in[BUFSIZE];
 	u8 buf_out[BUFSIZE];
@@ -45,7 +46,7 @@ int lzma_decompress_to_file(const char *input, int output_fd)
 	if (ret != LZMA_OK) {
 		pr_err("lzma: lzma_stream_decoder failed %s (%d)\n",
 			lzma_strerror(ret), ret);
-		return -1;
+		goto err_fclose;
 	}
 
 	strm.next_in   = NULL;
@@ -60,7 +61,7 @@ int lzma_decompress_to_file(const char *input, int output_fd)
 
 			if (ferror(infile)) {
 				pr_err("lzma: read error: %s\n", strerror(errno));
-				return -1;
+				goto err_fclose;
 			}
 
 			if (feof(infile))
@@ -74,7 +75,7 @@ int lzma_decompress_to_file(const char *input, int output_fd)
 
 			if (writen(output_fd, buf_out, write_size) != write_size) {
 				pr_err("lzma: write error: %s\n", strerror(errno));
-				return -1;
+				goto err_fclose;
 			}
 
 			strm.next_out  = buf_out;
@@ -83,13 +84,15 @@ int lzma_decompress_to_file(const char *input, int output_fd)
 
 		if (ret != LZMA_OK) {
 			if (ret == LZMA_STREAM_END)
-				return 0;
+				break;
 
 			pr_err("lzma: failed %s\n", lzma_strerror(ret));
-			return -1;
+			goto err_fclose;
 		}
 	}
 
+	err = 0;
+err_fclose:
 	fclose(infile);
-	return 0;
+	return err;
 }

> 
>  tools/perf/util/lzma.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c
> index 95a1acb..a95d473 100644
> --- a/tools/perf/util/lzma.c
> +++ b/tools/perf/util/lzma.c
> @@ -29,6 +29,7 @@ int lzma_decompress_to_file(const char *input, int output_fd)
>  	lzma_action action = LZMA_RUN;
>  	lzma_stream strm   = LZMA_STREAM_INIT;
>  	lzma_ret ret;
> +	int err = 0;
>  
>  	u8 buf_in[BUFSIZE];
>  	u8 buf_out[BUFSIZE];
> @@ -45,7 +46,8 @@ int lzma_decompress_to_file(const char *input, int output_fd)
>  	if (ret != LZMA_OK) {
>  		pr_err("lzma: lzma_stream_decoder failed %s (%d)\n",
>  			lzma_strerror(ret), ret);
> -		return -1;
> +		err = -1;
> +		goto err_fclose;
>  	}
>  
>  	strm.next_in   = NULL;
> @@ -60,7 +62,8 @@ int lzma_decompress_to_file(const char *input, int output_fd)
>  
>  			if (ferror(infile)) {
>  				pr_err("lzma: read error: %s\n", strerror(errno));
> -				return -1;
> +				err = -1;
> +				goto err_fclose;
>  			}
>  
>  			if (feof(infile))
> @@ -74,7 +77,8 @@ int lzma_decompress_to_file(const char *input, int output_fd)
>  
>  			if (writen(output_fd, buf_out, write_size) != write_size) {
>  				pr_err("lzma: write error: %s\n", strerror(errno));
> -				return -1;
> +				err = -1;
> +				goto err_fclose;
>  			}
>  
>  			strm.next_out  = buf_out;
> @@ -83,13 +87,14 @@ int lzma_decompress_to_file(const char *input, int output_fd)
>  
>  		if (ret != LZMA_OK) {
>  			if (ret == LZMA_STREAM_END)
> -				return 0;
> +				goto err_fclose;
>  
>  			pr_err("lzma: failed %s\n", lzma_strerror(ret));
> -			return -1;
> +			err = -1;
> +			goto err_fclose;
>  		}
>  	}
> -
> +err_fclose:
>  	fclose(infile);
> -	return 0;
> +	return err;
>  }
> -- 
> 2.3.7
> 

  reply	other threads:[~2016-08-24 14:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-21  7:57 [PATCH] perf tools: Fix error handling of lzma decompression Shawn Lin
2016-08-24 14:25 ` Arnaldo Carvalho de Melo [this message]
2016-09-05 13:19 ` [tip:perf/core] " tip-bot for Shawn Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160824142504.GD10063@kernel.org \
    --to=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=shawn.lin@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.