[Intel-gfx] [PATCH 2/3] drm/i915: Fortify ptr_pack_bits against mistakes

Tvrtko Ursulin tursulin at ursulin.net
Fri Oct 27 13:40:13 UTC 2017


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

Mask out the bits which do not fit into the specified
width in order to avoid corrupting the stored pointer.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
 drivers/gpu/drm/i915/i915_utils.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index af3d7cc53fa1..402d995b94a5 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -84,7 +84,7 @@
 })
 
 #define ptr_pack_bits(ptr, bits, n)					\
-	((typeof(ptr))((unsigned long)(ptr) | (bits)))
+	((typeof(ptr))((unsigned long)(ptr) | ((bits) & (BIT(n) - 1))))
 
 #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