All of lore.kernel.org
 help / color / mirror / Atom feed
From: Justin Stitt <justinstitt@google.com>
To: Arnd Bergmann <arnd@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Nathan Chancellor <nathan@kernel.org>,
	 Arnd Bergmann <arnd@arndb.de>,
	Dmitry Vyukov <dvyukov@google.com>,
	 Andrey Konovalov <andreyknvl@gmail.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	 Bill Wendling <morbo@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	kasan-dev@googlegroups.com,  llvm@lists.linux.dev
Subject: Re: [PATCH 4/9] kcov: avoid clang out-of-range warning
Date: Thu, 28 Mar 2024 15:22:16 -0700	[thread overview]
Message-ID: <CAFhGd8qDCMkP6rZ6A6i3b7DuJ0Rzem=V0TxAkvmMTsZM3NH43A@mail.gmail.com> (raw)
In-Reply-To: <20240328143051.1069575-5-arnd@kernel.org>

On Thu, Mar 28, 2024 at 7:31 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> The area_size is never larger than the maximum on 64-bit architectutes:
>
> kernel/kcov.c:634:29: error: result of comparison of constant 1152921504606846975 with expression of type '__u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
>                 if (remote_arg->area_size > LONG_MAX / sizeof(unsigned long))
>                     ~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The compiler can correctly optimize the check away and the code appears
> correct to me, so just add a cast to avoid the warning.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Justin Stitt <justinstitt@google.com>

> ---
>  kernel/kcov.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/kcov.c b/kernel/kcov.c
> index f9ac2e9e460f..c3124f6d5536 100644
> --- a/kernel/kcov.c
> +++ b/kernel/kcov.c
> @@ -627,7 +627,8 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigned int cmd,
>                 mode = kcov_get_mode(remote_arg->trace_mode);
>                 if (mode < 0)
>                         return mode;
> -               if (remote_arg->area_size > LONG_MAX / sizeof(unsigned long))
> +               if ((unsigned long)remote_arg->area_size >
> +                   LONG_MAX / sizeof(unsigned long))
>                         return -EINVAL;
>                 kcov->mode = mode;
>                 t->kcov = kcov;
> --
> 2.39.2
>

  reply	other threads:[~2024-03-28 22:22 UTC|newest]

Thread overview: 33+ 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 1/9] dm integrity: fix out-of-range warning Arnd Bergmann
2024-03-28 18:36   ` Mikulas Patocka
2024-03-28 21:58   ` Justin Stitt
2024-03-28 14:30 ` [PATCH 2/9] libceph: avoid clang " Arnd Bergmann
2024-03-28 22:53   ` Justin Stitt
2024-03-29  0:06   ` Xiubo Li
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-28 14:30 ` [PATCH 4/9] kcov: avoid clang " Arnd Bergmann
2024-03-28 22:22   ` Justin Stitt [this message]
2024-03-28 14:30 ` [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS Arnd Bergmann
2024-03-28 14:38   ` Eric Dumazet
2024-03-28 16:39     ` Arnd Bergmann
2024-03-28 14:30 ` [PATCH 6/9] nilfs2: fix out-of-range warning Arnd Bergmann
2024-03-28 15:21   ` Philipp Stanner
2024-03-28 16:12     ` Arnd Bergmann
2024-03-28 22:04   ` Justin Stitt
2024-03-28 22:25     ` Arnd Bergmann
2024-03-29  9:20   ` Ryusuke Konishi
2024-04-01  8:50   ` (subset) " Christian Brauner
2024-03-28 14:30 ` [PATCH 7/9] infiniband: uverbs: avoid out-of-range warnings Arnd Bergmann
2024-03-28 22:12   ` Justin Stitt
2024-04-03 15:45   ` Jason Gunthorpe
2024-04-03 20:16     ` Arnd Bergmann
2024-03-28 14:30 ` [PATCH 8/9] mlx5: stop warning for 64KB pages Arnd Bergmann
2024-03-28 15:37   ` Maxim Mikityanskiy
2024-03-28 22:09   ` Justin Stitt
2024-03-28 22:21     ` Arnd Bergmann
2024-03-28 22:39   ` Tariq Toukan
2024-03-28 14:30 ` [PATCH 9/9] kbuild: enable tautological-constant-out-of-range-compare Arnd Bergmann
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='CAFhGd8qDCMkP6rZ6A6i3b7DuJ0Rzem=V0TxAkvmMTsZM3NH43A@mail.gmail.com' \
    --to=justinstitt@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=dvyukov@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.