drm/i915/params: use generics for parameter free

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-3-jani.nikula@intel.com
This commit is contained in:
Jani Nikula 2023-01-18 17:17:59 +02:00
parent 7ce59bcf67
commit 7448d336bc
1 changed files with 9 additions and 6 deletions

View File

@ -296,18 +296,21 @@ void i915_params_copy(struct i915_params *dest, const struct i915_params *src)
#undef DUP
}
static __always_inline void free_param(const char *type, void *x)
static void _param_free_charp(char **valp)
{
if (!__builtin_strcmp(type, "char *")) {
kfree(*(void **)x);
*(void **)x = NULL;
}
kfree(*valp);
*valp = NULL;
}
#define _param_free(valp) \
_Generic(valp, \
char **: _param_free_charp, \
default: _param_nop)(valp)
/* free the allocated members, *not* the passed in params itself */
void i915_params_free(struct i915_params *params)
{
#define FREE(T, x, ...) free_param(#T, &params->x);
#define FREE(T, x, ...) _param_free(&params->x);
I915_PARAMS_FOR_EACH(FREE);
#undef FREE
}