Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Andrzej Hajda <andrzej.hajda@intel.com>, intel-gfx@lists.freedesktop.org
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: remove struct_member macro
Date: Fri, 9 Dec 2022 13:30:41 +0000	[thread overview]
Message-ID: <64f0cba9-a659-7888-0253-9b5c8a1c440f@linux.intel.com> (raw)
In-Reply-To: <20221209121459.3496148-1-andrzej.hajda@intel.com>


On 09/12/2022 12:14, Andrzej Hajda wrote:
> Since it is used only to get type of member it can be replaced
> with typeof_member.
> 
> Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
> ---
>   drivers/gpu/drm/i915/i915_utils.h       | 4 +---
>   drivers/gpu/drm/i915/intel_runtime_pm.h | 2 +-
>   2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> index 6c14d13364bf78..b64192d9c7daa7 100644
> --- a/drivers/gpu/drm/i915/i915_utils.h
> +++ b/drivers/gpu/drm/i915/i915_utils.h
> @@ -149,8 +149,6 @@ bool i915_error_injected(void);
>   #define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
>   #define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
>   
> -#define struct_member(T, member) (((T *)0)->member)
> -
>   #define fetch_and_zero(ptr) ({						\
>   	typeof(*ptr) __T = *(ptr);					\
>   	*(ptr) = (typeof(*ptr))0;					\
> @@ -170,7 +168,7 @@ static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
>    */
>   #define container_of_user(ptr, type, member) ({				\
>   	void __user *__mptr = (void __user *)(ptr);			\
> -	BUILD_BUG_ON_MSG(!__same_type(*(ptr), struct_member(type, member)) && \
> +	BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \

#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))

#define typeof_member(T, m)	typeof(((T*)0)->m)

So expands to:

__builtin_types_compatible_p(typeof(*(ptr)), typeof(typeof(((type*)0)->m)));

I guess that's okay since infinite number of typeofs is still a typeof.

Regards,

Tvrtko

>   			 !__same_type(*(ptr), void),			\
>   			 "pointer type mismatch in container_of()");	\
>   	((type __user *)(__mptr - offsetof(type, member))); })
> diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.h b/drivers/gpu/drm/i915/intel_runtime_pm.h
> index 98b8b28baaa15e..e592e8d6499a1f 100644
> --- a/drivers/gpu/drm/i915/intel_runtime_pm.h
> +++ b/drivers/gpu/drm/i915/intel_runtime_pm.h
> @@ -96,7 +96,7 @@ struct intel_runtime_pm {
>   };
>   
>   #define BITS_PER_WAKEREF	\
> -	BITS_PER_TYPE(struct_member(struct intel_runtime_pm, wakeref_count))
> +	BITS_PER_TYPE(typeof_member(struct intel_runtime_pm, wakeref_count))
>   #define INTEL_RPM_WAKELOCK_SHIFT	(BITS_PER_WAKEREF / 2)
>   #define INTEL_RPM_WAKELOCK_BIAS		(1 << INTEL_RPM_WAKELOCK_SHIFT)
>   #define INTEL_RPM_RAW_WAKEREF_MASK	(INTEL_RPM_WAKELOCK_BIAS - 1)

  parent reply	other threads:[~2022-12-09 13:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-09 12:14 [Intel-gfx] [PATCH] drm/i915: remove struct_member macro Andrzej Hajda
2022-12-09 13:03 ` [Intel-gfx] ✓ Fi.CI.BAT: success for " Patchwork
2022-12-09 13:18 ` [Intel-gfx] [PATCH] " Jani Nikula
2022-12-09 13:30 ` Tvrtko Ursulin [this message]
2022-12-09 21:02 ` [Intel-gfx] ✗ Fi.CI.IGT: failure for " Patchwork
2022-12-13 15:35 ` [Intel-gfx] [PATCH] " Andi Shyti

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=64f0cba9-a659-7888-0253-9b5c8a1c440f@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=andrzej.hajda@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=rodrigo.vivi@intel.com \
    /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