Commit 8d59bae5 authored by Chris Wilson's avatar Chris Wilson Committed by Dave Airlie

drm: Do not leak a new reference for flink() on an existing name

The name table should only hold a single reference, so avoid leaking
additional references for secondary calls to flink().
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarEric Anholt <eric@anholt.net>
Signed-off-by: default avatarDave Airlie <airlied@linux.ie>
parent a35f2e2b
...@@ -301,27 +301,25 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data, ...@@ -301,27 +301,25 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
} }
spin_lock(&dev->object_name_lock); spin_lock(&dev->object_name_lock);
if (obj->name) { if (!obj->name) {
args->name = obj->name;
spin_unlock(&dev->object_name_lock);
return 0;
}
ret = idr_get_new_above(&dev->object_name_idr, obj, 1, ret = idr_get_new_above(&dev->object_name_idr, obj, 1,
&obj->name); &obj->name);
args->name = (uint64_t) obj->name;
spin_unlock(&dev->object_name_lock); spin_unlock(&dev->object_name_lock);
if (ret == -EAGAIN) if (ret == -EAGAIN)
goto again; goto again;
if (ret != 0) if (ret != 0)
goto err; goto err;
/* /* Allocate a reference for the name table. */
* Leave the reference from the lookup around as the drm_gem_object_reference(obj);
* name table now holds one } else {
*/
args->name = (uint64_t) obj->name; args->name = (uint64_t) obj->name;
spin_unlock(&dev->object_name_lock);
return 0; ret = 0;
}
err: err:
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
...@@ -452,6 +450,7 @@ drm_gem_object_handle_free(struct kref *kref) ...@@ -452,6 +450,7 @@ drm_gem_object_handle_free(struct kref *kref)
spin_lock(&dev->object_name_lock); spin_lock(&dev->object_name_lock);
if (obj->name) { if (obj->name) {
idr_remove(&dev->object_name_idr, obj->name); idr_remove(&dev->object_name_idr, obj->name);
obj->name = 0;
spin_unlock(&dev->object_name_lock); spin_unlock(&dev->object_name_lock);
/* /*
* The object name held a reference to this object, drop * The object name held a reference to this object, drop
......
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