drm/i915/params: use generics for parameter dup

Replace the __builtin_strcmp() if ladder with generics.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230118151800.3669913-2-jani.nikula@intel.com
This commit is contained in:
Jani Nikula
2023-01-18 17:17:58 +02:00
parent bfe7586b11
commit 7ce59bcf67

View File

@@ -274,16 +274,24 @@ void i915_params_dump(const struct i915_params *params, struct drm_printer *p)
#undef PRINT
}
static __always_inline void dup_param(const char *type, void *x)
static void _param_dup_charp(char **valp)
{
if (!__builtin_strcmp(type, "char *"))
*(void **)x = kstrdup(*(void **)x, GFP_ATOMIC);
*valp = kstrdup(*valp, GFP_ATOMIC);
}
static void _param_nop(void *valp)
{
}
#define _param_dup(valp) \
_Generic(valp, \
char **: _param_dup_charp, \
default: _param_nop)(valp)
void i915_params_copy(struct i915_params *dest, const struct i915_params *src)
{
*dest = *src;
#define DUP(T, x, ...) dup_param(#T, &dest->x);
#define DUP(T, x, ...) _param_dup(&dest->x);
I915_PARAMS_FOR_EACH(DUP);
#undef DUP
}