forked from luck/tmp_suning_uos_patched
Use drm_gem_object_[handle_]unreference_unlocked where possible
Mostly obvious simplifications. The i915 pread/pwrite ioctls, intel_overlay_put_image and nouveau_gem_new were incorrectly using the locked versions without locking: this is also fixed in this patch. Signed-off-by: Luca Barbieri <luca@luca-barbieri.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
parent
c3ae90c099
commit
bc9025bdc4
@ -192,9 +192,7 @@ drm_gem_handle_delete(struct drm_file *filp, u32 handle)
|
||||
idr_remove(&filp->object_idr, handle);
|
||||
spin_unlock(&filp->table_lock);
|
||||
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_handle_unreference(obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_handle_unreference_unlocked(obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -325,9 +323,7 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
|
||||
}
|
||||
|
||||
err:
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -358,9 +354,7 @@ drm_gem_open_ioctl(struct drm_device *dev, void *data,
|
||||
return -ENOENT;
|
||||
|
||||
ret = drm_gem_handle_create(file_priv, obj, &handle);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -390,7 +384,7 @@ drm_gem_object_release_handle(int id, void *ptr, void *data)
|
||||
{
|
||||
struct drm_gem_object *obj = ptr;
|
||||
|
||||
drm_gem_object_handle_unreference(obj);
|
||||
drm_gem_object_handle_unreference_unlocked(obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -403,12 +397,10 @@ drm_gem_object_release_handle(int id, void *ptr, void *data)
|
||||
void
|
||||
drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
|
||||
{
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
idr_for_each(&file_private->object_idr,
|
||||
&drm_gem_object_release_handle, NULL);
|
||||
|
||||
idr_destroy(&file_private->object_idr);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -516,11 +508,8 @@ EXPORT_SYMBOL(drm_gem_vm_open);
|
||||
void drm_gem_vm_close(struct vm_area_struct *vma)
|
||||
{
|
||||
struct drm_gem_object *obj = vma->vm_private_data;
|
||||
struct drm_device *dev = obj->dev;
|
||||
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
}
|
||||
EXPORT_SYMBOL(drm_gem_vm_close);
|
||||
|
||||
|
@ -128,9 +128,7 @@ i915_gem_create_ioctl(struct drm_device *dev, void *data,
|
||||
return -ENOMEM;
|
||||
|
||||
ret = drm_gem_handle_create(file_priv, obj, &handle);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_handle_unreference(obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_handle_unreference_unlocked(obj);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -488,7 +486,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
|
||||
*/
|
||||
if (args->offset > obj->size || args->size > obj->size ||
|
||||
args->offset + args->size > obj->size) {
|
||||
drm_gem_object_unreference(obj);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -501,7 +499,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
|
||||
file_priv);
|
||||
}
|
||||
|
||||
drm_gem_object_unreference(obj);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -961,7 +959,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
|
||||
*/
|
||||
if (args->offset > obj->size || args->size > obj->size ||
|
||||
args->offset + args->size > obj->size) {
|
||||
drm_gem_object_unreference(obj);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -995,7 +993,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
|
||||
DRM_INFO("pwrite failed %d\n", ret);
|
||||
#endif
|
||||
|
||||
drm_gem_object_unreference(obj);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -1138,9 +1136,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
args->offset);
|
||||
up_write(¤t->mm->mmap_sem);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
if (IS_ERR((void *)addr))
|
||||
return addr;
|
||||
|
||||
|
@ -438,9 +438,7 @@ i915_gem_set_tiling(struct drm_device *dev, void *data,
|
||||
obj_priv = obj->driver_private;
|
||||
|
||||
if (!i915_tiling_ok(dev, args->stride, obj->size, args->tiling_mode)) {
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -3434,11 +3434,10 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc,
|
||||
intel_crtc->cursor_bo = bo;
|
||||
|
||||
return 0;
|
||||
fail:
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
fail_locked:
|
||||
drm_gem_object_unreference(bo);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
fail:
|
||||
drm_gem_object_unreference_unlocked(bo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -4351,9 +4350,7 @@ static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
|
||||
intelfb_remove(dev, fb);
|
||||
|
||||
drm_framebuffer_cleanup(fb);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(intel_fb->obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(intel_fb->obj);
|
||||
|
||||
kfree(intel_fb);
|
||||
}
|
||||
@ -4416,9 +4413,7 @@ intel_user_framebuffer_create(struct drm_device *dev,
|
||||
|
||||
ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj);
|
||||
if (ret) {
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1179,7 +1179,7 @@ int intel_overlay_put_image(struct drm_device *dev, void *data,
|
||||
out_unlock:
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
mutex_unlock(&dev->mode_config.mutex);
|
||||
drm_gem_object_unreference(new_bo);
|
||||
drm_gem_object_unreference_unlocked(new_bo);
|
||||
kfree(params);
|
||||
|
||||
return ret;
|
||||
|
@ -39,11 +39,8 @@ nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb)
|
||||
if (drm_fb->fbdev)
|
||||
nouveau_fbcon_remove(dev, drm_fb);
|
||||
|
||||
if (fb->nvbo) {
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(fb->nvbo->gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
}
|
||||
if (fb->nvbo)
|
||||
drm_gem_object_unreference_unlocked(fb->nvbo->gem);
|
||||
|
||||
drm_framebuffer_cleanup(drm_fb);
|
||||
kfree(fb);
|
||||
|
@ -401,10 +401,8 @@ nouveau_fbcon_remove(struct drm_device *dev, struct drm_framebuffer *fb)
|
||||
|
||||
unregister_framebuffer(info);
|
||||
nouveau_bo_unmap(nouveau_fb->nvbo);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(nouveau_fb->nvbo->gem);
|
||||
drm_gem_object_unreference_unlocked(nouveau_fb->nvbo->gem);
|
||||
nouveau_fb->nvbo = NULL;
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
if (par)
|
||||
drm_fb_helper_free(&par->helper);
|
||||
framebuffer_release(info);
|
||||
|
@ -167,12 +167,10 @@ nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
|
||||
|
||||
ret = drm_gem_handle_create(file_priv, nvbo->gem, &req->info.handle);
|
||||
out:
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_handle_unreference(nvbo->gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_handle_unreference_unlocked(nvbo->gem);
|
||||
|
||||
if (ret)
|
||||
drm_gem_object_unreference(nvbo->gem);
|
||||
drm_gem_object_unreference_unlocked(nvbo->gem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -865,9 +863,7 @@ nouveau_gem_ioctl_pin(struct drm_device *dev, void *data,
|
||||
req->domain = NOUVEAU_GEM_DOMAIN_VRAM;
|
||||
|
||||
out:
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gem);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -891,9 +887,7 @@ nouveau_gem_ioctl_unpin(struct drm_device *dev, void *data,
|
||||
|
||||
ret = nouveau_bo_unpin(nouveau_gem_object(gem));
|
||||
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gem);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -935,9 +929,7 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
|
||||
}
|
||||
|
||||
out:
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -965,9 +957,7 @@ nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -986,9 +976,7 @@ nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
|
||||
return -EINVAL;
|
||||
|
||||
ret = nouveau_gem_info(gem, req);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -61,11 +61,8 @@ nouveau_notifier_init_channel(struct nouveau_channel *chan)
|
||||
|
||||
chan->notifier_bo = ntfy;
|
||||
out_err:
|
||||
if (ret) {
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(ntfy->gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
}
|
||||
if (ret)
|
||||
drm_gem_object_unreference_unlocked(ntfy->gem);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -81,8 +78,8 @@ nouveau_notifier_takedown_channel(struct nouveau_channel *chan)
|
||||
nouveau_bo_unmap(chan->notifier_bo);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
nouveau_bo_unpin(chan->notifier_bo);
|
||||
drm_gem_object_unreference(chan->notifier_bo->gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(chan->notifier_bo->gem);
|
||||
nouveau_mem_takedown(&chan->notifier_heap);
|
||||
}
|
||||
|
||||
|
@ -926,9 +926,7 @@ nv04_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
|
||||
nv_crtc->cursor.set_offset(nv_crtc, nv_crtc->cursor.offset);
|
||||
nv_crtc->cursor.show(nv_crtc, true);
|
||||
out:
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -358,9 +358,7 @@ nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
|
||||
nv_crtc->cursor.show(nv_crtc, true);
|
||||
|
||||
out:
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gem);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -196,11 +196,8 @@ static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error)
|
||||
radeon_bo_list_unreserve(&parser->validated);
|
||||
}
|
||||
for (i = 0; i < parser->nrelocs; i++) {
|
||||
if (parser->relocs[i].gobj) {
|
||||
mutex_lock(&parser->rdev->ddev->struct_mutex);
|
||||
drm_gem_object_unreference(parser->relocs[i].gobj);
|
||||
mutex_unlock(&parser->rdev->ddev->struct_mutex);
|
||||
}
|
||||
if (parser->relocs[i].gobj)
|
||||
drm_gem_object_unreference_unlocked(parser->relocs[i].gobj);
|
||||
}
|
||||
kfree(parser->track);
|
||||
kfree(parser->relocs);
|
||||
|
@ -169,17 +169,13 @@ int radeon_crtc_cursor_set(struct drm_crtc *crtc,
|
||||
unpin:
|
||||
if (radeon_crtc->cursor_bo) {
|
||||
radeon_gem_object_unpin(radeon_crtc->cursor_bo);
|
||||
mutex_lock(&crtc->dev->struct_mutex);
|
||||
drm_gem_object_unreference(radeon_crtc->cursor_bo);
|
||||
mutex_unlock(&crtc->dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(radeon_crtc->cursor_bo);
|
||||
}
|
||||
|
||||
radeon_crtc->cursor_bo = obj;
|
||||
return 0;
|
||||
fail:
|
||||
mutex_lock(&crtc->dev->struct_mutex);
|
||||
drm_gem_object_unreference(obj);
|
||||
mutex_unlock(&crtc->dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -679,11 +679,8 @@ static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb)
|
||||
if (fb->fbdev)
|
||||
radeonfb_remove(dev, fb);
|
||||
|
||||
if (radeon_fb->obj) {
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(radeon_fb->obj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
}
|
||||
if (radeon_fb->obj)
|
||||
drm_gem_object_unreference_unlocked(radeon_fb->obj);
|
||||
drm_framebuffer_cleanup(fb);
|
||||
kfree(radeon_fb);
|
||||
}
|
||||
|
@ -69,9 +69,7 @@ int radeon_gem_object_create(struct radeon_device *rdev, int size,
|
||||
if (r != -ERESTARTSYS)
|
||||
DRM_ERROR("Failed to allocate GEM object (%d, %d, %u, %d)\n",
|
||||
size, initial_domain, alignment, r);
|
||||
mutex_lock(&rdev->ddev->struct_mutex);
|
||||
drm_gem_object_unreference(gobj);
|
||||
mutex_unlock(&rdev->ddev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gobj);
|
||||
return r;
|
||||
}
|
||||
gobj->driver_private = robj;
|
||||
@ -202,14 +200,10 @@ int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
|
||||
}
|
||||
r = drm_gem_handle_create(filp, gobj, &handle);
|
||||
if (r) {
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gobj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gobj);
|
||||
return r;
|
||||
}
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_handle_unreference(gobj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_handle_unreference_unlocked(gobj);
|
||||
args->handle = handle;
|
||||
return 0;
|
||||
}
|
||||
@ -236,9 +230,7 @@ int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
|
||||
|
||||
r = radeon_gem_set_domain(gobj, args->read_domains, args->write_domain);
|
||||
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gobj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gobj);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -255,9 +247,7 @@ int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
|
||||
}
|
||||
robj = gobj->driver_private;
|
||||
args->addr_ptr = radeon_bo_mmap_offset(robj);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gobj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gobj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -288,9 +278,7 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gobj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gobj);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -311,9 +299,7 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
|
||||
/* callback hw specific functions if any */
|
||||
if (robj->rdev->asic->ioctl_wait_idle)
|
||||
robj->rdev->asic->ioctl_wait_idle(robj->rdev, robj);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gobj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gobj);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -331,9 +317,7 @@ int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
|
||||
return -EINVAL;
|
||||
robj = gobj->driver_private;
|
||||
r = radeon_bo_set_tiling_flags(robj, args->tiling_flags, args->pitch);
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gobj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gobj);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -356,8 +340,6 @@ int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
|
||||
radeon_bo_get_tiling_flags(rbo, &args->tiling_flags, &args->pitch);
|
||||
radeon_bo_unreserve(rbo);
|
||||
out:
|
||||
mutex_lock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference(gobj);
|
||||
mutex_unlock(&dev->struct_mutex);
|
||||
drm_gem_object_unreference_unlocked(gobj);
|
||||
return r;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user