diff mbox series

[U-BOOT,v2,1/3] fs: btrfs: Use LZO_LEN to replace immediate number

Message ID 20200326053556.20492-2-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series fs: btrfs: Fix false LZO decompression error due to missing page boundary check | expand

Commit Message

Qu Wenruo March 26, 2020, 5:35 a.m. UTC
Just a cleanup. These immediate numbers make my eyes hurt.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Cc: Marek Behun <marek.behun@nic.cz>
---
 fs/btrfs/compression.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

Comments

Marek Behún March 26, 2020, 9:02 a.m. UTC | #1
On Thu, 26 Mar 2020 13:35:54 +0800
Qu Wenruo <wqu@suse.com> wrote:

> Just a cleanup. These immediate numbers make my eyes hurt.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> Cc: Marek Behun <marek.behun@nic.cz>
> ---
>  fs/btrfs/compression.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index 346875d45a1b..4ef44ce11485 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -12,36 +12,38 @@
>  #include <u-boot/zlib.h>
>  #include <asm/unaligned.h>
>  
> +/* Header for each segment, LE32, recording the compressed size */
> +#define LZO_LEN		4
>  static u32 decompress_lzo(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
>  {
>  	u32 tot_len, in_len, res;
>  	size_t out_len;
>  	int ret;
>  
> -	if (clen < 4)
> +	if (clen < LZO_LEN)
>  		return -1;
>  
>  	tot_len = le32_to_cpu(get_unaligned((u32 *)cbuf));
> -	cbuf += 4;
> -	clen -= 4;
> -	tot_len -= 4;
> +	cbuf += LZO_LEN;
> +	clen -= LZO_LEN;
> +	tot_len -= LZO_LEN;
>  
>  	if (tot_len == 0 && dlen)
>  		return -1;
> -	if (tot_len < 4)
> +	if (tot_len < LZO_LEN)
>  		return -1;
>  
>  	res = 0;
>  
> -	while (tot_len > 4) {
> +	while (tot_len > LZO_LEN) {
>  		in_len = le32_to_cpu(get_unaligned((u32 *)cbuf));
> -		cbuf += 4;
> -		clen -= 4;
> +		cbuf += LZO_LEN;
> +		clen -= LZO_LEN;
>  
> -		if (in_len > clen || tot_len < 4 + in_len)
> +		if (in_len > clen || tot_len < LZO_LEN + in_len)
>  			return -1;
>  
> -		tot_len -= 4 + in_len;
> +		tot_len -= (LZO_LEN + in_len);
>  
>  		out_len = dlen;
>  		ret = lzo1x_decompress_safe(cbuf, in_len, dbuf, &out_len);

Reviewed-by: Marek Behún <marek.behun@nic.cz>
Tom Rini April 17, 2020, 9:08 p.m. UTC | #2
On Thu, Mar 26, 2020 at 01:35:54PM +0800, Qu Wenruo wrote:

> Just a cleanup. These immediate numbers make my eyes hurt.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> Cc: Marek Behun <marek.behun@nic.cz>
> Reviewed-by: Marek Behún <marek.behun@nic.cz>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 346875d45a1b..4ef44ce11485 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -12,36 +12,38 @@ 
 #include <u-boot/zlib.h>
 #include <asm/unaligned.h>
 
+/* Header for each segment, LE32, recording the compressed size */
+#define LZO_LEN		4
 static u32 decompress_lzo(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
 {
 	u32 tot_len, in_len, res;
 	size_t out_len;
 	int ret;
 
-	if (clen < 4)
+	if (clen < LZO_LEN)
 		return -1;
 
 	tot_len = le32_to_cpu(get_unaligned((u32 *)cbuf));
-	cbuf += 4;
-	clen -= 4;
-	tot_len -= 4;
+	cbuf += LZO_LEN;
+	clen -= LZO_LEN;
+	tot_len -= LZO_LEN;
 
 	if (tot_len == 0 && dlen)
 		return -1;
-	if (tot_len < 4)
+	if (tot_len < LZO_LEN)
 		return -1;
 
 	res = 0;
 
-	while (tot_len > 4) {
+	while (tot_len > LZO_LEN) {
 		in_len = le32_to_cpu(get_unaligned((u32 *)cbuf));
-		cbuf += 4;
-		clen -= 4;
+		cbuf += LZO_LEN;
+		clen -= LZO_LEN;
 
-		if (in_len > clen || tot_len < 4 + in_len)
+		if (in_len > clen || tot_len < LZO_LEN + in_len)
 			return -1;
 
-		tot_len -= 4 + in_len;
+		tot_len -= (LZO_LEN + in_len);
 
 		out_len = dlen;
 		ret = lzo1x_decompress_safe(cbuf, in_len, dbuf, &out_len);