From: Xiubo Li <xiubli@redhat.com>
To: Arnd Bergmann <arnd@kernel.org>,
linux-kernel@vger.kernel.org, Ilya Dryomov <idryomov@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Nathan Chancellor <nathan@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>, Jeff Layton <jlayton@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Milind Changire <mchangir@redhat.com>,
Patrick Donnelly <pdonnell@redhat.com>,
Christian Brauner <brauner@kernel.org>,
ceph-devel@vger.kernel.org, netdev@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH 2/9] libceph: avoid clang out-of-range warning
Date: Fri, 29 Mar 2024 08:06:12 +0800 [thread overview]
Message-ID: <a305940d-723a-4f7e-a54e-cbd84ef8354a@redhat.com> (raw)
In-Reply-To: <20240328143051.1069575-3-arnd@kernel.org>
On 3/28/24 22:30, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang-14 points out that on 64-bit architectures, a u32
> is never larger than constant based on SIZE_MAX:
>
> net/ceph/osdmap.c:1425:10: error: result of comparison of constant 4611686018427387891 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
> ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> net/ceph/osdmap.c:1608:10: error: result of comparison of constant 2305843009213693945 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
> ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The code is correct anyway, so just shut up that warning.
>
> Fixes: 6f428df47dae ("libceph: pg_upmap[_items] infrastructure")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> fs/ceph/snap.c | 2 +-
> net/ceph/osdmap.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
> index c65f2b202b2b..521507ea8260 100644
> --- a/fs/ceph/snap.c
> +++ b/fs/ceph/snap.c
> @@ -374,7 +374,7 @@ static int build_snap_context(struct ceph_mds_client *mdsc,
>
> /* alloc new snap context */
> err = -ENOMEM;
> - if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
> + if ((size_t)num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
> goto fail;
> snapc = ceph_create_snap_context(num, GFP_NOFS);
> if (!snapc)
> diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
> index 295098873861..8e7cb2fde6f1 100644
> --- a/net/ceph/osdmap.c
> +++ b/net/ceph/osdmap.c
> @@ -1438,7 +1438,7 @@ static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end,
> ceph_decode_32_safe(p, end, len, e_inval);
> if (len == 0 && incremental)
> return NULL; /* new_pg_temp: [] to remove */
> - if (len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
> + if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
> return ERR_PTR(-EINVAL);
>
> ceph_decode_need(p, end, len * sizeof(u32), e_inval);
> @@ -1621,7 +1621,7 @@ static struct ceph_pg_mapping *__decode_pg_upmap_items(void **p, void *end,
> u32 len, i;
>
> ceph_decode_32_safe(p, end, len, e_inval);
> - if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
> + if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
> return ERR_PTR(-EINVAL);
>
> ceph_decode_need(p, end, 2 * len * sizeof(u32), e_inval);
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Thanks
- Xiubo
next prev parent reply other threads:[~2024-03-29 0:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-28 14:30 [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare Arnd Bergmann
2024-03-28 14:30 ` [PATCH 2/9] libceph: avoid clang out-of-range warning Arnd Bergmann
2024-03-28 22:53 ` Justin Stitt
2024-03-29 0:06 ` Xiubo Li [this message]
2024-03-28 14:30 ` [PATCH 3/9] rbd: avoid " Arnd Bergmann
2024-03-28 14:53 ` Alex Elder
2024-03-29 0:05 ` Xiubo Li
2024-03-29 20:00 ` [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare patchwork-bot+netdevbpf
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=a305940d-723a-4f7e-a54e-cbd84ef8354a@redhat.com \
--to=xiubli@redhat.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=brauner@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=idryomov@gmail.com \
--cc=jlayton@kernel.org \
--cc=justinstitt@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mchangir@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pdonnell@redhat.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).