linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] erofs-utils: use cmpsgn(x, y) for standardized large value comparsion
@ 2019-10-14 11:30 Gao Xiang via Linux-erofs
  2019-10-14 23:55 ` Gao Xiang via Linux-erofs
  0 siblings, 1 reply; 5+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-10-14 11:30 UTC (permalink / raw)
  To: Li Guifu, linux-erofs; +Cc: Miao Xie

Previously, roundup(bb->buffers.off % EROFS_BLKSIZ, alignsize)
+ incr + extrasize is a unsigned 64bit value and sgn(x) didn't
work properly. Fix it.

Signed-off-by: Gao Xiang <hsiangkao@aol.com>
---
 include/erofs/defs.h | 5 +++--
 lib/cache.c          | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/erofs/defs.h b/include/erofs/defs.h
index 15db4e3..db51350 100644
--- a/include/erofs/defs.h
+++ b/include/erofs/defs.h
@@ -136,9 +136,10 @@ typedef int64_t         s64;
 	type __max2 = (y);			\
 	__max1 > __max2 ? __max1: __max2; })
 
-#define sgn(x) ({		\
+#define cmpsgn(x, y) ({		\
 	typeof(x) _x = (x);	\
-(_x > 0) - (_x < 0); })
+	typeof(y) _y = (y);	\
+(_x > _y) - (_x < _y); })
 
 #define ARRAY_SIZE(arr)	(sizeof(arr) / sizeof((arr)[0]))
 
diff --git a/lib/cache.c b/lib/cache.c
index 41d2d5d..e61b201 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -80,9 +80,9 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
 			   bool dryrun)
 {
 	const erofs_off_t alignedoffset = roundup(bb->buffers.off, alignsize);
-	const int oob = sgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
-				    alignsize) + incr + extrasize -
-			    EROFS_BLKSIZ);
+	const int oob = cmpsgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
+				       alignsize) + incr + extrasize,
+			       EROFS_BLKSIZ);
 	bool tailupdate = false;
 	erofs_blk_t blkaddr;
 
-- 
2.17.1


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

* Re: [PATCH] erofs-utils: use cmpsgn(x, y) for standardized large value comparsion
  2019-10-14 11:30 [PATCH] erofs-utils: use cmpsgn(x, y) for standardized large value comparsion Gao Xiang via Linux-erofs
@ 2019-10-14 23:55 ` Gao Xiang via Linux-erofs
  2019-10-15 15:38   ` Li Guifu
  0 siblings, 1 reply; 5+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-10-14 23:55 UTC (permalink / raw)
  To: Li Guifu, linux-erofs; +Cc: Miao Xie

On Mon, Oct 14, 2019 at 07:30:48PM +0800, Gao Xiang wrote:
> Previously, roundup(bb->buffers.off % EROFS_BLKSIZ, alignsize)
> + incr + extrasize is a unsigned 64bit value and sgn(x) didn't
> work properly. Fix it.

Update commit message:

erofs-utils: use cmpsgn(x, y) for standardized large value comparsion
    
Previously, roundup(bb->buffers.off % EROFS_BLKSIZ, alignsize)
+ incr + extrasize is an unsigned 64bit value and sgn(x) didn't
work properly. Fix it.
    
Fixes: b0ca535297b6 ("erofs-utils: support 64-bit internal buffer cache")

Guifu, do you have time reviewing and testing those patches?
I'd like to release erofs-utils 1.0 for upstreaming AOSP these days...

Thanks,
Gao Xiang

> 
> Signed-off-by: Gao Xiang <hsiangkao@aol.com>
> ---
>  include/erofs/defs.h | 5 +++--
>  lib/cache.c          | 6 +++---
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/include/erofs/defs.h b/include/erofs/defs.h
> index 15db4e3..db51350 100644
> --- a/include/erofs/defs.h
> +++ b/include/erofs/defs.h
> @@ -136,9 +136,10 @@ typedef int64_t         s64;
>  	type __max2 = (y);			\
>  	__max1 > __max2 ? __max1: __max2; })
>  
> -#define sgn(x) ({		\
> +#define cmpsgn(x, y) ({		\
>  	typeof(x) _x = (x);	\
> -(_x > 0) - (_x < 0); })
> +	typeof(y) _y = (y);	\
> +(_x > _y) - (_x < _y); })
>  
>  #define ARRAY_SIZE(arr)	(sizeof(arr) / sizeof((arr)[0]))
>  
> diff --git a/lib/cache.c b/lib/cache.c
> index 41d2d5d..e61b201 100644
> --- a/lib/cache.c
> +++ b/lib/cache.c
> @@ -80,9 +80,9 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
>  			   bool dryrun)
>  {
>  	const erofs_off_t alignedoffset = roundup(bb->buffers.off, alignsize);
> -	const int oob = sgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
> -				    alignsize) + incr + extrasize -
> -			    EROFS_BLKSIZ);
> +	const int oob = cmpsgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
> +				       alignsize) + incr + extrasize,
> +			       EROFS_BLKSIZ);
>  	bool tailupdate = false;
>  	erofs_blk_t blkaddr;
>  
> -- 
> 2.17.1
> 

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

* Re: [PATCH] erofs-utils: use cmpsgn(x, y) for standardized large value comparsion
  2019-10-14 23:55 ` Gao Xiang via Linux-erofs
@ 2019-10-15 15:38   ` Li Guifu
  2019-10-15 15:50     ` [PATCH v3] " Gao Xiang via Linux-erofs
  0 siblings, 1 reply; 5+ messages in thread
From: Li Guifu @ 2019-10-15 15:38 UTC (permalink / raw)
  To: Gao Xiang, Li Guifu, linux-erofs; +Cc: Miao Xie

Hi Gao Xiang,

It runs ok, but could you resend it to adjust line algin ?

 >> -#define sgn(x) ({		\
 >> +#define cmpsgn(x, y) ({		\
 >>   	typeof(x) _x = (x);	\
 >> -(_x > 0) - (_x < 0); })
 >> +	typeof(y) _y = (y);	\
 >> +(_x > _y) - (_x < _y); }) ----> here


> On Mon, Oct 14, 2019 at 07:30:48PM +0800, Gao Xiang wrote:
>> Previously, roundup(bb->buffers.off % EROFS_BLKSIZ, alignsize)
>> + incr + extrasize is a unsigned 64bit value and sgn(x) didn't
>> work properly. Fix it.
> 
> Update commit message:
> 
> erofs-utils: use cmpsgn(x, y) for standardized large value comparsion
>      
> Previously, roundup(bb->buffers.off % EROFS_BLKSIZ, alignsize)
> + incr + extrasize is an unsigned 64bit value and sgn(x) didn't
> work properly. Fix it.
>      
> Fixes: b0ca535297b6 ("erofs-utils: support 64-bit internal buffer cache")
> 
> Guifu, do you have time reviewing and testing those patches?
> I'd like to release erofs-utils 1.0 for upstreaming AOSP these days...
> 
> Thanks,
> Gao Xiang
> 
>>
>> Signed-off-by: Gao Xiang <hsiangkao@aol.com>
>> ---
>>   include/erofs/defs.h | 5 +++--
>>   lib/cache.c          | 6 +++---
>>   2 files changed, 6 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/erofs/defs.h b/include/erofs/defs.h
>> index 15db4e3..db51350 100644
>> --- a/include/erofs/defs.h
>> +++ b/include/erofs/defs.h
>> @@ -136,9 +136,10 @@ typedef int64_t         s64;
>>   	type __max2 = (y);			\
>>   	__max1 > __max2 ? __max1: __max2; })
>>   
>> -#define sgn(x) ({		\
>> +#define cmpsgn(x, y) ({		\
>>   	typeof(x) _x = (x);	\
>> -(_x > 0) - (_x < 0); })
>> +	typeof(y) _y = (y);	\
>> +(_x > _y) - (_x < _y); })
>>   
>>   #define ARRAY_SIZE(arr)	(sizeof(arr) / sizeof((arr)[0]))
>>   
>> diff --git a/lib/cache.c b/lib/cache.c
>> index 41d2d5d..e61b201 100644
>> --- a/lib/cache.c
>> +++ b/lib/cache.c
>> @@ -80,9 +80,9 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
>>   			   bool dryrun)
>>   {
>>   	const erofs_off_t alignedoffset = roundup(bb->buffers.off, alignsize);
>> -	const int oob = sgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
>> -				    alignsize) + incr + extrasize -
>> -			    EROFS_BLKSIZ);
>> +	const int oob = cmpsgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
>> +				       alignsize) + incr + extrasize,
>> +			       EROFS_BLKSIZ);
>>   	bool tailupdate = false;
>>   	erofs_blk_t blkaddr;
>>   
>> -- 
>> 2.17.1
>>

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

* [PATCH v3] erofs-utils: use cmpsgn(x, y) for standardized large value comparsion
  2019-10-15 15:38   ` Li Guifu
@ 2019-10-15 15:50     ` Gao Xiang via Linux-erofs
  2019-10-15 15:53       ` Li Guifu
  0 siblings, 1 reply; 5+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-10-15 15:50 UTC (permalink / raw)
  To: Li Guifu, linux-erofs; +Cc: Miao Xie

Previously, roundup(bb->buffers.off % EROFS_BLKSIZ, alignsize)
+ incr + extrasize is an unsigned 64bit value and sgn(x) didn't
work properly. Fix it.

Fixes: b0ca535297b6 ("erofs-utils: support 64-bit internal buffer cache")
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
---
change since v2:
 - update an indention suggested by Guifu.

 include/erofs/defs.h | 5 +++--
 lib/cache.c          | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/erofs/defs.h b/include/erofs/defs.h
index 15db4e3..d3c1156 100644
--- a/include/erofs/defs.h
+++ b/include/erofs/defs.h
@@ -136,9 +136,10 @@ typedef int64_t         s64;
 	type __max2 = (y);			\
 	__max1 > __max2 ? __max1: __max2; })
 
-#define sgn(x) ({		\
+#define cmpsgn(x, y) ({		\
 	typeof(x) _x = (x);	\
-(_x > 0) - (_x < 0); })
+	typeof(y) _y = (y);	\
+	(_x > _y) - (_x < _y); })
 
 #define ARRAY_SIZE(arr)	(sizeof(arr) / sizeof((arr)[0]))
 
diff --git a/lib/cache.c b/lib/cache.c
index 41d2d5d..e61b201 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -80,9 +80,9 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
 			   bool dryrun)
 {
 	const erofs_off_t alignedoffset = roundup(bb->buffers.off, alignsize);
-	const int oob = sgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
-				    alignsize) + incr + extrasize -
-			    EROFS_BLKSIZ);
+	const int oob = cmpsgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
+				       alignsize) + incr + extrasize,
+			       EROFS_BLKSIZ);
 	bool tailupdate = false;
 	erofs_blk_t blkaddr;
 
-- 
2.17.1


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

* Re: [PATCH v3] erofs-utils: use cmpsgn(x, y) for standardized large value comparsion
  2019-10-15 15:50     ` [PATCH v3] " Gao Xiang via Linux-erofs
@ 2019-10-15 15:53       ` Li Guifu
  0 siblings, 0 replies; 5+ messages in thread
From: Li Guifu @ 2019-10-15 15:53 UTC (permalink / raw)
  To: Gao Xiang, Li Guifu, linux-erofs; +Cc: Miao Xie


> Previously, roundup(bb->buffers.off % EROFS_BLKSIZ, alignsize)
> + incr + extrasize is an unsigned 64bit value and sgn(x) didn't
> work properly. Fix it.
> 
> Fixes: b0ca535297b6 ("erofs-utils: support 64-bit internal buffer cache")
> Signed-off-by: Gao Xiang <hsiangkao@aol.com>
> ---

It looks good
Reviewed-by: Li Guifu <blucerlee@gmail.com>
Tested-by: Li Guifu <blucerlee@gmail.com>

Thanks,

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

end of thread, other threads:[~2019-10-15 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 11:30 [PATCH] erofs-utils: use cmpsgn(x, y) for standardized large value comparsion Gao Xiang via Linux-erofs
2019-10-14 23:55 ` Gao Xiang via Linux-erofs
2019-10-15 15:38   ` Li Guifu
2019-10-15 15:50     ` [PATCH v3] " Gao Xiang via Linux-erofs
2019-10-15 15:53       ` Li Guifu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).