From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: <intel-gfx@lists.freedesktop.org>, Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH] drm/i915: use check_add_overflow() and drop local variants
Date: Mon, 8 Apr 2024 08:59:13 -0400 [thread overview]
Message-ID: <ZhPqIejwwbEppXUr@intel.com> (raw)
In-Reply-To: <20240405202625.2525671-1-jani.nikula@intel.com>
On Fri, Apr 05, 2024 at 11:26:25PM +0300, Jani Nikula wrote:
> Prefer common check_add_overflow() from overflow.h over the locally
> rolled versions of it. While check_add_overflow() does require a
> variable to assign to, unlike add_overflows_t(), it's still better than
> having multiple versions around.
>
> Cc: Kees Cook <keescook@chromium.org>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> ---
> drivers/gpu/drm/i915/display/intel_fb.c | 6 +++---
> drivers/gpu/drm/i915/i915_utils.h | 14 --------------
> 2 files changed, 3 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_fb.c b/drivers/gpu/drm/i915/display/intel_fb.c
> index 3ea6470d6d92..86b443433e8b 100644
> --- a/drivers/gpu/drm/i915/display/intel_fb.c
> +++ b/drivers/gpu/drm/i915/display/intel_fb.c
> @@ -1106,7 +1106,7 @@ static int intel_fb_offset_to_xy(int *x, int *y,
> {
> struct drm_i915_private *i915 = to_i915(fb->dev);
> unsigned int height;
> - u32 alignment;
> + u32 alignment, unused;
>
> if (DISPLAY_VER(i915) >= 12 &&
> !intel_fb_needs_pot_stride_remap(to_intel_framebuffer(fb)) &&
> @@ -1128,8 +1128,8 @@ static int intel_fb_offset_to_xy(int *x, int *y,
> height = ALIGN(height, intel_tile_height(fb, color_plane));
>
> /* Catch potential overflows early */
> - if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
> - fb->offsets[color_plane])) {
> + if (check_add_overflow(mul_u32_u32(height, fb->pitches[color_plane]),
> + fb->offsets[color_plane], &unused)) {
> drm_dbg_kms(&i915->drm,
> "Bad offset 0x%08x or pitch %d for color plane %d\n",
> fb->offsets[color_plane], fb->pitches[color_plane],
> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> index b45ef0560611..06ec6ceb61d5 100644
> --- a/drivers/gpu/drm/i915/i915_utils.h
> +++ b/drivers/gpu/drm/i915/i915_utils.h
> @@ -73,20 +73,6 @@ bool i915_error_injected(void);
> __i915_printk(i915, i915_error_injected() ? KERN_DEBUG : KERN_ERR, \
> fmt, ##__VA_ARGS__)
>
> -#if defined(GCC_VERSION) && GCC_VERSION >= 70000
> -#define add_overflows_t(T, A, B) \
> - __builtin_add_overflow_p((A), (B), (T)0)
> -#else
> -#define add_overflows_t(T, A, B) ({ \
> - typeof(A) a = (A); \
> - typeof(B) b = (B); \
> - (T)(a + b) < a; \
> -})
> -#endif
> -
> -#define add_overflows(A, B) \
> - add_overflows_t(typeof((A) + (B)), (A), (B))
> -
> #define range_overflows(start, size, max) ({ \
> typeof(start) start__ = (start); \
> typeof(size) size__ = (size); \
> --
> 2.39.2
>
next prev parent reply other threads:[~2024-04-08 12:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-05 20:26 [PATCH] drm/i915: use check_add_overflow() and drop local variants Jani Nikula
2024-04-05 20:59 ` ✗ Fi.CI.SPARSE: warning for " Patchwork
2024-04-05 21:10 ` ✗ Fi.CI.BAT: failure " Patchwork
2024-04-08 12:59 ` Rodrigo Vivi [this message]
2024-04-09 10:38 ` [PATCH] " Jani Nikula
2024-04-08 17:16 ` ✗ Fi.CI.SPARSE: warning for drm/i915: use check_add_overflow() and drop local variants (rev2) Patchwork
2024-04-08 17:22 ` ✓ Fi.CI.BAT: success " Patchwork
2024-04-09 5:48 ` ✗ Fi.CI.IGT: failure " Patchwork
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=ZhPqIejwwbEppXUr@intel.com \
--to=rodrigo.vivi@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@intel.com \
--cc=keescook@chromium.org \
/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.