From 6cf1dd40df721196e6944d1778e8c4902f856d8d Mon Sep 17 00:00:00 2001 From: Stanislav Vorobiov Date: Tue, 30 Apr 2013 17:10:46 +0400 Subject: [PATCH] VIGS: Potential deadlock fixed Change-Id: I6e7bfc824fc637bcc77896919c504da17eddfe2b --- drivers/gpu/drm/vigs/vigs_device.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/vigs/vigs_device.c b/drivers/gpu/drm/vigs/vigs_device.c index aabead480eb5..c1a027fecfbd 100644 --- a/drivers/gpu/drm/vigs/vigs_device.c +++ b/drivers/gpu/drm/vigs/vigs_device.c @@ -9,21 +9,22 @@ #include "vigs_surface.h" #include -/* - * Must be called with drm_device::struct_mutex held. - */ static struct vigs_surface - *vigs_device_reference_surface(struct vigs_device *vigs_dev, - vigsp_surface_id sfc_id) + *vigs_device_reference_surface_unlocked(struct vigs_device *vigs_dev, + vigsp_surface_id sfc_id) { struct vigs_surface *sfc; + mutex_lock(&vigs_dev->drm_dev->struct_mutex); + sfc = idr_find(&vigs_dev->surface_idr, sfc_id); if (sfc) { drm_gem_object_reference(&sfc->gem.base); } + mutex_unlock(&vigs_dev->drm_dev->struct_mutex); + return sfc; } @@ -45,8 +46,6 @@ static int vigs_device_patch_commands(struct vigs_device *vigs_dev, struct vigs_surface *sfc; int ret = 0; - mutex_lock(&vigs_dev->drm_dev->struct_mutex); - /* * GEM is always at least PAGE_SIZE long, so don't check * if batch header is out of bounds. @@ -71,7 +70,7 @@ static int vigs_device_patch_commands(struct vigs_device *vigs_dev, case vigsp_cmd_update_vram: update_vram_request = (struct vigsp_cmd_update_vram_request*)(request_header + 1); - sfc = vigs_device_reference_surface(vigs_dev, update_vram_request->sfc_id); + sfc = vigs_device_reference_surface_unlocked(vigs_dev, update_vram_request->sfc_id); if (!sfc) { DRM_ERROR("Surface %u not found\n", update_vram_request->sfc_id); ret = -EINVAL; @@ -88,7 +87,7 @@ static int vigs_device_patch_commands(struct vigs_device *vigs_dev, case vigsp_cmd_update_gpu: update_gpu_request = (struct vigsp_cmd_update_gpu_request*)(request_header + 1); - sfc = vigs_device_reference_surface(vigs_dev, update_gpu_request->sfc_id); + sfc = vigs_device_reference_surface_unlocked(vigs_dev, update_gpu_request->sfc_id); if (!sfc) { DRM_ERROR("Surface %u not found\n", update_gpu_request->sfc_id); ret = -EINVAL; @@ -111,8 +110,6 @@ static int vigs_device_patch_commands(struct vigs_device *vigs_dev, request_header->size); } - mutex_unlock(&vigs_dev->drm_dev->struct_mutex); - return 0; } -- 2.34.1