[Intel-gfx] [PATCH v2 2/2] drm/i915: Warn in debug builds of incorrect usages of ptr_pack_bits

Tvrtko Ursulin tursulin at ursulin.net
Thu Nov 2 10:16:35 UTC 2017


From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>

GEM_BUG_ON if the packed bits do not fit into the specified width.

v2: Avoid using the macro argument twice.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk> (v1)
---
 drivers/gpu/drm/i915/i915_utils.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index af3d7cc53fa1..c0135fed4282 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -83,8 +83,11 @@
 	(typeof(ptr))(__v & -BIT(n));					\
 })
 
-#define ptr_pack_bits(ptr, bits, n)					\
-	((typeof(ptr))((unsigned long)(ptr) | (bits)))
+#define ptr_pack_bits(ptr, bits, n) ({					\
+	unsigned long __bits = (bits);					\
+	GEM_BUG_ON((__bits) & -BIT(n));					\
+	((typeof(ptr))((unsigned long)(ptr) | (__bits)));		\
+})
 
 #define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
 #define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
-- 
2.9.5



More information about the Intel-gfx mailing list