[PATCH v2 2/5] drm/xe/sriov: Prepare IS_SRIOV_PF to accept const pointer
Matt Roper
matthew.d.roper at intel.com
Mon Feb 24 22:39:06 UTC 2025
On Mon, Feb 24, 2025 at 04:06:57PM +0100, Michal Wajdeczko wrote:
> For builds without CONFIG_PCI_IOV we have an optimized variant
> of the IS_SRIOV_PF(xe) macro that always evaluates to false,
> but we still try to validate corectness of the xe argument.
> Unfortunately typecheck() alone doesn't work well for cases
> where xe could be a const pointer. Try use _Generic() instead.
>
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
I wonder if it would be any more intuitive to just make a static inline
function to get the type-checking? E.g.,
static inline bool IS_SRIOV_PF(struct xe_device *xe) { return false; }
But if _Generic works, that's fine too.
Reviewed-by: Matt Roper <matthew.d.roper at intel.com>
> ---
> drivers/gpu/drm/xe/xe_sriov.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_sriov.h b/drivers/gpu/drm/xe/xe_sriov.h
> index 688fbabf08f1..cba6a608bf27 100644
> --- a/drivers/gpu/drm/xe/xe_sriov.h
> +++ b/drivers/gpu/drm/xe/xe_sriov.h
> @@ -38,7 +38,7 @@ static inline bool xe_device_is_sriov_vf(const struct xe_device *xe)
> #ifdef CONFIG_PCI_IOV
> #define IS_SRIOV_PF(xe) xe_device_is_sriov_pf(xe)
> #else
> -#define IS_SRIOV_PF(xe) (typecheck(struct xe_device *, (xe)) && false)
> +#define IS_SRIOV_PF(xe) _Generic((xe), const struct xe_device * : false, struct xe_device * : false)
> #endif
> #define IS_SRIOV_VF(xe) xe_device_is_sriov_vf(xe)
>
> --
> 2.47.1
>
--
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation
More information about the Intel-xe
mailing list