Commit c2fba936 authored by Chris Wilson's avatar Chris Wilson

drm/i915/perf: Avoid polluting the i915_oa_config with error pointers

Use a local variable to track the allocation errors to avoid polluting
the struct and keep the free simple.
Reported-by: default avatarkbuild test robot <lkp@intel.com>
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: default avatarLionel Landwerlin <lionel.g.landwerlin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191013095211.2922-1-chris@chris-wilson.co.uk
parent 5f5c382e
...@@ -384,12 +384,9 @@ void i915_oa_config_release(struct kref *ref) ...@@ -384,12 +384,9 @@ void i915_oa_config_release(struct kref *ref)
struct i915_oa_config *oa_config = struct i915_oa_config *oa_config =
container_of(ref, typeof(*oa_config), ref); container_of(ref, typeof(*oa_config), ref);
if (!PTR_ERR(oa_config->flex_regs)) kfree(oa_config->flex_regs);
kfree(oa_config->flex_regs); kfree(oa_config->b_counter_regs);
if (!PTR_ERR(oa_config->b_counter_regs)) kfree(oa_config->mux_regs);
kfree(oa_config->b_counter_regs);
if (!PTR_ERR(oa_config->mux_regs))
kfree(oa_config->mux_regs);
kfree_rcu(oa_config, rcu); kfree_rcu(oa_config, rcu);
} }
...@@ -3631,6 +3628,7 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data, ...@@ -3631,6 +3628,7 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
struct i915_perf *perf = &to_i915(dev)->perf; struct i915_perf *perf = &to_i915(dev)->perf;
struct drm_i915_perf_oa_config *args = data; struct drm_i915_perf_oa_config *args = data;
struct i915_oa_config *oa_config, *tmp; struct i915_oa_config *oa_config, *tmp;
static struct i915_oa_reg *regs;
int err, id; int err, id;
if (!perf->i915) { if (!perf->i915) {
...@@ -3676,30 +3674,30 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data, ...@@ -3676,30 +3674,30 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
memcpy(oa_config->uuid, args->uuid, sizeof(args->uuid)); memcpy(oa_config->uuid, args->uuid, sizeof(args->uuid));
oa_config->mux_regs_len = args->n_mux_regs; oa_config->mux_regs_len = args->n_mux_regs;
oa_config->mux_regs = regs = alloc_oa_regs(perf,
alloc_oa_regs(perf, perf->ops.is_valid_mux_reg,
perf->ops.is_valid_mux_reg, u64_to_user_ptr(args->mux_regs_ptr),
u64_to_user_ptr(args->mux_regs_ptr), args->n_mux_regs);
args->n_mux_regs);
if (IS_ERR(oa_config->mux_regs)) { if (IS_ERR(regs)) {
DRM_DEBUG("Failed to create OA config for mux_regs\n"); DRM_DEBUG("Failed to create OA config for mux_regs\n");
err = PTR_ERR(oa_config->mux_regs); err = PTR_ERR(regs);
goto reg_err; goto reg_err;
} }
oa_config->mux_regs = regs;
oa_config->b_counter_regs_len = args->n_boolean_regs; oa_config->b_counter_regs_len = args->n_boolean_regs;
oa_config->b_counter_regs = regs = alloc_oa_regs(perf,
alloc_oa_regs(perf, perf->ops.is_valid_b_counter_reg,
perf->ops.is_valid_b_counter_reg, u64_to_user_ptr(args->boolean_regs_ptr),
u64_to_user_ptr(args->boolean_regs_ptr), args->n_boolean_regs);
args->n_boolean_regs);
if (IS_ERR(oa_config->b_counter_regs)) { if (IS_ERR(regs)) {
DRM_DEBUG("Failed to create OA config for b_counter_regs\n"); DRM_DEBUG("Failed to create OA config for b_counter_regs\n");
err = PTR_ERR(oa_config->b_counter_regs); err = PTR_ERR(regs);
goto reg_err; goto reg_err;
} }
oa_config->b_counter_regs = regs;
if (INTEL_GEN(perf->i915) < 8) { if (INTEL_GEN(perf->i915) < 8) {
if (args->n_flex_regs != 0) { if (args->n_flex_regs != 0) {
...@@ -3708,17 +3706,17 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data, ...@@ -3708,17 +3706,17 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
} }
} else { } else {
oa_config->flex_regs_len = args->n_flex_regs; oa_config->flex_regs_len = args->n_flex_regs;
oa_config->flex_regs = regs = alloc_oa_regs(perf,
alloc_oa_regs(perf, perf->ops.is_valid_flex_reg,
perf->ops.is_valid_flex_reg, u64_to_user_ptr(args->flex_regs_ptr),
u64_to_user_ptr(args->flex_regs_ptr), args->n_flex_regs);
args->n_flex_regs);
if (IS_ERR(oa_config->flex_regs)) { if (IS_ERR(regs)) {
DRM_DEBUG("Failed to create OA config for flex_regs\n"); DRM_DEBUG("Failed to create OA config for flex_regs\n");
err = PTR_ERR(oa_config->flex_regs); err = PTR_ERR(regs);
goto reg_err; goto reg_err;
} }
oa_config->flex_regs = regs;
} }
err = mutex_lock_interruptible(&perf->metrics_lock); err = mutex_lock_interruptible(&perf->metrics_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment