public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Matthew Auld <matthew.auld@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 3/4] drm/i915: introduce range_overflows utility macros
Date: Tue, 13 Dec 2016 20:32:21 +0000	[thread overview]
Message-ID: <20161213203222.32564-3-matthew.auld@intel.com> (raw)
In-Reply-To: <20161213203222.32564-1-matthew.auld@intel.com>

In a number places we hand-roll the overflow sanity check for ranges, so
roll that into single macro, conceived by Chris, along with its typed
variant.

Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 20bc04d5e617..47b5a9f1c9ed 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -218,6 +218,18 @@ static inline const char *enableddisabled(bool v)
 	return v ? "enabled" : "disabled";
 }
 
+#define range_overflows(start, size, max) ({ \
+	typeof(start) start__ = (start); \
+	typeof(size) size__ = (size); \
+	typeof(max) max__ = (max); \
+	(void)(&start__ == &size__); \
+	(void)(&start__ == &max__); \
+	start > max || size > max - start; \
+})
+
+#define range_overflows_t(type, start, size, max) \
+	range_overflows(((type)start), ((type)size), ((type)max))
+
 enum pipe {
 	INVALID_PIPE = -1,
 	PIPE_A = 0,
-- 
2.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2016-12-13 20:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 20:32 [PATCH 1/4] drm/i915: introduce GEM_WARN_ON Matthew Auld
2016-12-13 20:32 ` [PATCH 2/4] drm/i915: move vma sanity checking into i915_vma_bind Matthew Auld
2016-12-13 21:34   ` Chris Wilson
2016-12-13 20:32 ` Matthew Auld [this message]
2016-12-13 21:31   ` [PATCH 3/4] drm/i915: introduce range_overflows utility macros Chris Wilson
2016-12-13 20:32 ` [PATCH 4/4] drm/i915: convert to using range_overflows Matthew Auld
2016-12-13 21:32   ` Chris Wilson
2016-12-13 21:15 ` ✓ Fi.CI.BAT: success for series starting with [1/4] drm/i915: introduce GEM_WARN_ON Patchwork
2016-12-16 21:28   ` Chris Wilson
2016-12-13 21:35 ` [PATCH 1/4] " Chris Wilson

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=20161213203222.32564-3-matthew.auld@intel.com \
    --to=matthew.auld@intel.com \
    --cc=intel-gfx@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox