From: Dan Carpenter <dan.carpenter@oracle.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] XArray: Fix a math problem in xa_is_err()
Date: Tue, 15 Jan 2019 22:52:41 +0300 [thread overview]
Message-ID: <20190115195241.GB1074@kadam> (raw)
There is a math problem here which leads to a lot of static checker
warnings for me:
net/sunrpc/clnt.c:451 rpc_new_client() error: (-4096) too low for ERR_PTR
Error values are from -1 to -4095 or from 0xffffffff to 0xfffff001 in
hexadecimal. (I am assuming a 32 bit system for simplicity). We are
using the lowest two bits to hold some internal XArray data so the
error is shifted two spaces to the left. 0xfffff001 << 2 is 0xffffc004.
And finally we want to check that BIT(1) is set so we add 2 which gives
us 0xffffc006.
In other words, we should be checking that "entry >= 0xffffc006", but
the check is actually testing if "entry >= 0xffffc002".
Fixes: 76b4e5299565 ("XArray: Permit storing 2-byte-aligned pointers")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
include/linux/xarray.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index 12244aa98a69..4208042f939a 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -177,7 +177,8 @@ static inline bool xa_is_internal(const void *entry)
static inline bool xa_is_err(const void *entry)
{
return unlikely(xa_is_internal(entry) &&
- (unsigned long)entry >= -((MAX_ERRNO << 2) + 2));
+ (unsigned long)entry >=
+ (((unsigned long)(-MAX_ERRNO << 2) + 2)));
}
/**
--
2.17.1
next reply other threads:[~2019-01-15 19:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-15 19:52 Dan Carpenter [this message]
2019-01-15 21:07 ` [PATCH] XArray: Fix a math problem in xa_is_err() Matthew Wilcox
2019-01-15 21:35 ` Dan Carpenter
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=20190115195241.GB1074@kadam \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=willy@infradead.org \
/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).