public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: Joao Marcos Costa <joaomarcos.costa@bootlin.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	u-boot@lists.denx.de
Subject: Re: [PATCH 1/1] fs/squashfs: simplify sqfs_read()
Date: Tue, 12 Apr 2022 08:59:40 +0200	[thread overview]
Message-ID: <20220412085940.55820b05@xps13> (raw)
In-Reply-To: <20220411205444.50898-1-heinrich.schuchardt@canonical.com>

Hi Heinrich,

heinrich.schuchardt@canonical.com wrote on Mon, 11 Apr 2022 22:54:44
+0200:

> * Don't check argument of free(). Free does this itself.
> * Reduce scope of data_buffer. Remove duplicate free().
> * Avoid superfluous NULL assignment.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>

> ---
>  fs/squashfs/sqfs.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
> index 5d9c52af80..b07c41e911 100644
> --- a/fs/squashfs/sqfs.c
> +++ b/fs/squashfs/sqfs.c
> @@ -1310,7 +1310,7 @@ static int sqfs_get_lregfile_info(struct squashfs_lreg_inode *lreg,
>  int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
>  	      loff_t *actread)
>  {
> -	char *dir = NULL, *fragment_block, *datablock = NULL, *data_buffer = NULL;
> +	char *dir = NULL, *fragment_block, *datablock = NULL;
>  	char *fragment = NULL, *file = NULL, *resolved, *data;
>  	u64 start, n_blks, table_size, data_offset, table_offset, sparse_size;
>  	int ret, j, i_number, datablk_count = 0;
> @@ -1440,6 +1440,8 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
>  	}
>  
>  	for (j = 0; j < datablk_count; j++) {
> +		char *data_buffer;
> +
>  		start = data_offset / ctxt.cur_dev->blksz;
>  		table_size = SQFS_BLOCK_SIZE(finfo.blk_sizes[j]);
>  		table_offset = data_offset - (start * ctxt.cur_dev->blksz);
> @@ -1501,9 +1503,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
>  		}
>  
>  		data_offset += table_size;
> -		if (data_buffer)
> -			free(data_buffer);
> -		data_buffer = NULL;
> +		free(data_buffer);
>  		if (*actread >= len)
>  			break;
>  	}
> @@ -1563,10 +1563,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
>  
>  out:
>  	free(fragment);
> -	if (datablk_count) {
> -		free(data_buffer);
> -		free(datablock);
> -	}
> +	free(datablock);
>  	free(file);
>  	free(dir);
>  	free(finfo.blk_sizes);


Thanks,
Miquèl

  reply	other threads:[~2022-04-12  6:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11 20:54 [PATCH 1/1] fs/squashfs: simplify sqfs_read() Heinrich Schuchardt
2022-04-12  6:59 ` Miquel Raynal [this message]
2022-04-20 13:12 ` Tom Rini

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=20220412085940.55820b05@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=heinrich.schuchardt@canonical.com \
    --cc=joaomarcos.costa@bootlin.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=u-boot@lists.denx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox