Commit 86e61735 authored by Matthew Auld's avatar Matthew Auld Committed by Chris Wilson

drm/i915: introduce range_overflows utility macros

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: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarMatthew Auld <matthew.auld@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161213203222.32564-3-matthew.auld@intel.comReviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
parent 7a0499a4
...@@ -218,6 +218,18 @@ static inline const char *enableddisabled(bool v) ...@@ -218,6 +218,18 @@ static inline const char *enableddisabled(bool v)
return v ? "enabled" : "disabled"; 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 { enum pipe {
INVALID_PIPE = -1, INVALID_PIPE = -1,
PIPE_A = 0, PIPE_A = 0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment