From: Alex Elder <elder@ieee.org>
To: David Laight <david.laight.linux@gmail.com>,
Rosen Penev <rosenp@gmail.com>
Cc: linux-block@vger.kernel.org, Ilya Dryomov <idryomov@gmail.com>,
Dongsheng Yang <dongsheng.yang@linux.dev>,
Jens Axboe <axboe@kernel.dk>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
"open list:RADOS BLOCK DEVICE (RBD)" <ceph-devel@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b"
<llvm@lists.linux.dev>
Subject: Re: [PATCH] rbd: cast snap_count to size_t to avoid tautological comparison warning
Date: Thu, 28 May 2026 16:20:39 -0500 [thread overview]
Message-ID: <01625bb3-1a91-4d2a-bfc8-7d34ce4b5e5b@ieee.org> (raw)
In-Reply-To: <20260528220505.73eac71a@pumpkin>
On 5/28/26 4:05 PM, David Laight wrote:
> On Thu, 28 May 2026 13:21:51 -0700
> Rosen Penev <rosenp@gmail.com> wrote:
>
>> snap_count is u32 but the comparison is against a SIZE_MAX-derived value
>> (~2^61 on 64-bit), which clang flags as always false with
>> -Wtautological-constant-out-of-range-compare. Cast to size_t so the
>> comparison is done in the correct width.
>
> If that warning makes any sense then the cast shouldn't make any difference.
>
> Why not check against RBD_MAX_SNAP_COUNT - the buffer isn't big enough
> to hold any more than that.
I like that better. Please do that instead (despite my
Reviewed-by provided earlier).
-Alex
>
> -- David
>
>>
>> Assisted-by: Opencode:Big-pickle
>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> ---
>> drivers/block/rbd.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
>> index 94709466ad19..b4ba51db9a28 100644
>> --- a/drivers/block/rbd.c
>> +++ b/drivers/block/rbd.c
>> @@ -6079,7 +6079,7 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev,
>> * make sure the computed size of the snapshot context we
>> * allocate is representable in a size_t.
>> */
>> - if (snap_count > (SIZE_MAX - sizeof (struct ceph_snap_context))
>> + if ((size_t)snap_count > (SIZE_MAX - sizeof (struct ceph_snap_context))
>> / sizeof (u64)) {
>> ret = -EINVAL;
>> goto out;
>
>
prev parent reply other threads:[~2026-05-28 21:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 20:21 Rosen Penev
2026-05-28 20:45 ` Alex Elder
2026-05-28 21:05 ` David Laight
2026-05-28 21:20 ` Alex Elder [this message]
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=01625bb3-1a91-4d2a-bfc8-7d34ce4b5e5b@ieee.org \
--to=elder@ieee.org \
--cc=axboe@kernel.dk \
--cc=ceph-devel@vger.kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=dongsheng.yang@linux.dev \
--cc=idryomov@gmail.com \
--cc=justinstitt@google.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=rosenp@gmail.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
all inboxes | Powered by JetHome®