From: Gao Xiang via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: Li Guifu <bluce.liguifu@huawei.com>, linux-erofs@lists.ozlabs.org
Cc: Miao Xie <miaoxie@huawei.com>
Subject: [PATCH] erofs-utils: use cmpsgn(x, y) for standardized large value comparsion
Date: Mon, 14 Oct 2019 19:30:48 +0800 [thread overview]
Message-ID: <20191014113048.32067-1-hsiangkao@aol.com> (raw)
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
next reply other threads:[~2019-10-14 11:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-14 11:30 Gao Xiang via Linux-erofs [this message]
2019-10-14 23:55 ` [PATCH] erofs-utils: use cmpsgn(x, y) for standardized large value comparsion 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
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=20191014113048.32067-1-hsiangkao@aol.com \
--to=linux-erofs@lists.ozlabs.org \
--cc=bluce.liguifu@huawei.com \
--cc=hsiangkao@aol.com \
--cc=miaoxie@huawei.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 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).