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

Chris Wilson chris at chris-wilson.co.uk
Fri Oct 27 13:44:02 UTC 2017


Quoting Tvrtko Ursulin (2017-10-27 14:40:14)
> From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
> 
> GEM_BUG_ON if the packed bits do not fit into the specified width.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at 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)))); \

With that you do not need the redundant mask. So don't.
-Chris


More information about the Intel-gfx mailing list