Skip to contentSkip to conversation

erofs-utils: use cmpsgn(x, y) for standardized large value comparsion

PATCH Superseded Gao Xiang via Linux-erofs 2 participants 5 messages Oct 14, 2019 – Oct 15, 2019 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: use cmpsgn(x, y) for standardized large value comparsion

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

---
 include/erofs/defs.h | 5 +++--
 lib/cache.c          | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)
include/erofs/defs.h +3 -2
index 15db4e3..db51350 100644
@@ -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]))
 
lib/cache.c +3 -3
index 41d2d5d..e61b201 100644
@@ -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;
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Gao Xiang

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

Quoted 44 lines
---
 include/erofs/defs.h | 5 +++--
 lib/cache.c          | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)
include/erofs/defs.h +3 -2
index 15db4e3..db51350 100644
@@ -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]))
 
lib/cache.c +3 -3
index 41d2d5d..e61b201 100644
@@ -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;
 
Signature · 1 line
2.17.1
#2 lore raw

Hi Gao Xiang,

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

Quoted 73 lines
Quoted 6 lines
include/erofs/defs.h +3 -2
-#define sgn(x) ({		\
+#define cmpsgn(x, y) ({		\
  	typeof(x) _x = (x);	\
-(_x > 0) - (_x < 0); })
+	typeof(y) _y = (y);	\
+(_x > _y) - (_x < _y); }) ----> here
Quoted 3 lines · Gao Xiang

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

Quoted 44 lines
---
  include/erofs/defs.h | 5 +++--
  lib/cache.c          | 6 +++---
  2 files changed, 6 insertions(+), 5 deletions(-)
include/erofs/defs.h +3 -2
index 15db4e3..db51350 100644
@@ -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]))
 
lib/cache.c +3 -3
index 41d2d5d..e61b201 100644
@@ -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;
 
Signature · 1 line
2.17.1
#3 lore raw

PATCH v3 1/1 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")

---
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(-)
include/erofs/defs.h +3 -2
index 15db4e3..d3c1156 100644
@@ -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]))
 
lib/cache.c +3 -3
index 41d2d5d..e61b201 100644
@@ -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;
 
Signature · 1 line
2.17.1