kref_put(&ctx->ref, i915_gem_context_free);
 }
 
+static inline void i915_gem_context_put_unlocked(struct i915_gem_context *ctx)
+{
+       kref_put_mutex(&ctx->ref,
+                      i915_gem_context_free,
+                      &ctx->i915->drm.struct_mutex);
+}
+
 static inline struct intel_timeline *
 i915_gem_context_lookup_timeline(struct i915_gem_context *ctx,
                                 struct intel_engine_cs *engine)
 
  */
 static void i915_perf_destroy_locked(struct i915_perf_stream *stream)
 {
-       struct drm_i915_private *dev_priv = stream->dev_priv;
-
        if (stream->enabled)
                i915_perf_disable_locked(stream);
 
 
        list_del(&stream->link);
 
-       if (stream->ctx) {
-               mutex_lock(&dev_priv->drm.struct_mutex);
-               i915_gem_context_put(stream->ctx);
-               mutex_unlock(&dev_priv->drm.struct_mutex);
-       }
+       if (stream->ctx)
+               i915_gem_context_put_unlocked(stream->ctx);
 
        kfree(stream);
 }
 err_alloc:
        kfree(stream);
 err_ctx:
-       if (specific_ctx) {
-               mutex_lock(&dev_priv->drm.struct_mutex);
-               i915_gem_context_put(specific_ctx);
-               mutex_unlock(&dev_priv->drm.struct_mutex);
-       }
+       if (specific_ctx)
+               i915_gem_context_put_unlocked(specific_ctx);
 err:
        return ret;
 }