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 2/3] drm/i915: Fortify ptr_pack_bits against mistakes
Date: Fri, 27 Oct 2017 14:40:13 +0100	[thread overview]
Message-ID: <20171027134014.23961-2-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20171027134014.23961-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@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@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

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

  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 ` Tvrtko Ursulin [this message]
2017-10-27 13:40 ` [PATCH 3/3] drm/i915: Warn in debug builds of incorrect usages of ptr_pack_bits Tvrtko Ursulin
2017-10-27 13:44   ` 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-2-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