linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Nathan Chancellor <natechancellor@gmail.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	intel-gfx@lists.freedesktop.org,
	dri-devel <dri-devel@lists.freedesktop.org>,
	LKML <linux-kernel@vger.kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>
Subject: Re: [PATCH] drm/i915: Remove tautological compare in eb_relocate_vma
Date: Mon, 2 Dec 2019 11:18:20 -0800	[thread overview]
Message-ID: <CAKwvOdniXqn3xt3-W0Pqi-X1nWjJ2vUVofjCm1O-UPXZ7_4rXw@mail.gmail.com> (raw)
In-Reply-To: <157453950786.2524.16955749910067219709@skylake-alporthouse-com>

On Sat, Nov 23, 2019 at 12:05 PM Chris Wilson <chris@chris-wilson.co.uk> wrote:
>
> Quoting Nathan Chancellor (2019-11-23 19:53:22)
> > -Wtautological-compare was recently added to -Wall in LLVM, which
> > exposed an if statement in i915 that is always false:
> >
> > ../drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c:1485:22: warning:
> > result of comparison of constant 576460752303423487 with expression of
> > type 'unsigned int' is always false
> > [-Wtautological-constant-out-of-range-compare]
> >         if (unlikely(remain > N_RELOC(ULONG_MAX)))
> >             ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
> >
> > Since remain is an unsigned int, it can never be larger than UINT_MAX,
> > which is less than ULONG_MAX / sizeof(struct drm_i915_gem_relocation_entry).
> > Remove this statement to fix the warning.
>
> The check should remain as we do want to document the overflow
> calculation, and it should represent the types used -- it's much easier

What do you mean "represent the types used?"  Are you concerned that
the type of drm_i915_gem_exec_object2->relocation_count might change
in the future?

> to review a stub than trying to find a missing overflow check. If the
> overflow cannot happen as the types are wide enough, no problem, the
> compiler can remove the known false branch.

What overflow are you trying to protect against here?

>
> Tautology here has a purpose for conveying information to the reader.

Well leaving a warning unaddressed is also not a solution.  Either
replace it with a comment or turn off the warning for your subdir.

The warning here looks valid to me; you have a guard for something
that's impossible.
-- 
Thanks,
~Nick Desaulniers

  reply	other threads:[~2019-12-02 19:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-23 19:53 [PATCH] drm/i915: Remove tautological compare in eb_relocate_vma Nathan Chancellor
2019-11-23 20:05 ` Chris Wilson
2019-12-02 19:18   ` Nick Desaulniers [this message]
2019-12-03 13:42     ` Chris Wilson
2019-12-03 18:45       ` Nick Desaulniers
2019-12-22  3:09         ` Nathan Chancellor

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=CAKwvOdniXqn3xt3-W0Pqi-X1nWjJ2vUVofjCm1O-UPXZ7_4rXw@mail.gmail.com \
    --to=ndesaulniers@google.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=clang-built-linux@googlegroups.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=natechancellor@gmail.com \
    --cc=rodrigo.vivi@intel.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).