UPSTREAM: drm: Do not set outparam on error during GEM handle allocation

Good practice dictates that we do not leak stale information to our
callers, and should avoid overwriting an outparam on an error path.

Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1451986951-3703-1-git-send-email-chris@chris-wilson.co.uk
Reviewed-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
(cherry picked from commit 9649399e91)

Change-Id: Id6f2a968d66ff463481e8e090522c837b9e12730
Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
This commit is contained in:
Chris Wilson 2016-01-05 09:42:30 +00:00 committed by Tao Huang
parent 3535f99a2d
commit 6fe76ee08e

View File

@ -326,6 +326,7 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
u32 *handlep)
{
struct drm_device *dev = obj->dev;
u32 handle;
int ret;
WARN_ON(!mutex_is_locked(&dev->object_name_lock));
@ -348,7 +349,7 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
if (ret < 0)
goto err_unref;
*handlep = ret;
handle = ret;
ret = drm_vma_node_allow(&obj->vma_node, file_priv->filp);
if (ret)
@ -360,13 +361,14 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
goto err_revoke;
}
*handlep = handle;
return 0;
err_revoke:
drm_vma_node_revoke(&obj->vma_node, file_priv->filp);
err_remove:
spin_lock(&file_priv->table_lock);
idr_remove(&file_priv->object_idr, *handlep);
idr_remove(&file_priv->object_idr, handle);
spin_unlock(&file_priv->table_lock);
err_unref:
drm_gem_object_handle_unreference_unlocked(obj);