Commit 16cabb12 authored by Jani Nikula's avatar Jani Nikula
Browse files

drm/i915: add a helper to free the members of i915_params



Abstract the one user in anticipation of more. Set the dangling pointers
to NULL while at it.

Reviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
Signed-off-by: default avatarJani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/8637d1e5049dc003718772f19d664aeaf9540856.1545920737.git.jani.nikula@intel.com
parent 4081cef9
Loading
Loading
Loading
Loading
+1 −8
Original line number Original line Diff line number Diff line
@@ -963,17 +963,10 @@ static void i915_error_object_free(struct drm_i915_error_object *obj)
	kfree(obj);
	kfree(obj);
}
}


static __always_inline void free_param(const char *type, void *x)
{
	if (!__builtin_strcmp(type, "char *"))
		kfree(*(void **)x);
}


static void cleanup_params(struct i915_gpu_state *error)
static void cleanup_params(struct i915_gpu_state *error)
{
{
#define FREE(T, x, ...) free_param(#T, &error->params.x);
	i915_params_free(&error->params);
	I915_PARAMS_FOR_EACH(FREE);
#undef FREE
}
}


static void cleanup_uc_state(struct i915_gpu_state *error)
static void cleanup_uc_state(struct i915_gpu_state *error)
+16 −0
Original line number Original line Diff line number Diff line
@@ -217,3 +217,19 @@ void i915_params_copy(struct i915_params *dest, const struct i915_params *src)
	I915_PARAMS_FOR_EACH(DUP);
	I915_PARAMS_FOR_EACH(DUP);
#undef DUP
#undef DUP
}
}

static __always_inline void free_param(const char *type, void *x)
{
	if (!__builtin_strcmp(type, "char *")) {
		kfree(*(void **)x);
		*(void **)x = NULL;
	}
}

/* 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);
	I915_PARAMS_FOR_EACH(FREE);
#undef FREE
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -79,6 +79,7 @@ extern struct i915_params i915_modparams __read_mostly;


void i915_params_dump(const struct i915_params *params, struct drm_printer *p);
void i915_params_dump(const struct i915_params *params, struct drm_printer *p);
void i915_params_copy(struct i915_params *dest, const struct i915_params *src);
void i915_params_copy(struct i915_params *dest, const struct i915_params *src);
void i915_params_free(struct i915_params *params);


#endif
#endif