public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tursulin@ursulin.net>
To: Intel-gfx@lists.freedesktop.org
Subject: [PATCH 3/3] drm/i915: Warn in debug builds of incorrect usages of ptr_pack_bits
Date: Fri, 27 Oct 2017 14:40:14 +0100	[thread overview]
Message-ID: <20171027134014.23961-3-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20171027134014.23961-1-tvrtko.ursulin@linux.intel.com>

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

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

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/i915_utils.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index 402d995b94a5..49b9de753c42 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -83,8 +83,10 @@
 	(typeof(ptr))(__v & -BIT(n));					\
 })
 
-#define ptr_pack_bits(ptr, bits, n)					\
-	((typeof(ptr))((unsigned long)(ptr) | ((bits) & (BIT(n) - 1))))
+#define ptr_pack_bits(ptr, bits, n) ({					 \
+	GEM_BUG_ON((bits) & -BIT(n));					 \
+	((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

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

  parent reply	other threads:[~2017-10-27 13:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-27 13:40 [PATCH 1/3] drm/i915: Reject unknown syncobj flags Tvrtko Ursulin
2017-10-27 13:40 ` [PATCH 2/3] drm/i915: Fortify ptr_pack_bits against mistakes Tvrtko Ursulin
2017-10-27 13:40 ` Tvrtko Ursulin [this message]
2017-10-27 13:44   ` [PATCH 3/3] drm/i915: Warn in debug builds of incorrect usages of ptr_pack_bits Chris Wilson
2017-10-27 13:48 ` [PATCH 1/3] drm/i915: Reject unknown syncobj flags Chris Wilson
2017-10-27 14:12   ` [PATCH v2 " Tvrtko Ursulin
2017-10-27 14:01 ` ✗ Fi.CI.BAT: failure for series starting with [1/3] " Patchwork
2017-10-27 14:57 ` ✗ Fi.CI.BAT: failure for series starting with [v2,1/3] drm/i915: Reject unknown syncobj flags (rev2) Patchwork
2017-10-30  9:14 ` ✓ Fi.CI.BAT: success " 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=20171027134014.23961-3-tvrtko.ursulin@linux.intel.com \
    --to=tursulin@ursulin.net \
    --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