[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a305940d-723a-4f7e-a54e-cbd84ef8354a@redhat.com>
Date: Fri, 29 Mar 2024 08:06:12 +0800
From: Xiubo Li <xiubli@...hat.com>
To: Arnd Bergmann <arnd@...nel.org>, linux-kernel@...r.kernel.org,
Ilya Dryomov <idryomov@...il.com>, "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Nathan Chancellor <nathan@...nel.org>
Cc: Arnd Bergmann <arnd@...db.de>, Jeff Layton <jlayton@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>, Bill Wendling
<morbo@...gle.com>, Justin Stitt <justinstitt@...gle.com>,
Milind Changire <mchangir@...hat.com>, Patrick Donnelly
<pdonnell@...hat.com>, Christian Brauner <brauner@...nel.org>,
ceph-devel@...r.kernel.org, netdev@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [PATCH 2/9] libceph: avoid clang out-of-range warning
On 3/28/24 22:30, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@...db.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@...db.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@...hat.com>
Thanks
- Xiubo
Powered by blists - more mailing lists