Commit d28d6e6f authored by Huang Rui's avatar Huang Rui Committed by Alex Deucher

drm: modify drm_global_item_ref to avoid two times of writing ref->object

In previous drm_global_item_ref, there are two times of writing
ref->object if item->refcount is 0. So this patch does a minor update
to put alloc and init ref firstly, and then to modify the item of glob
array. Use "else" to avoid two times of writing ref->object. It can
make the code logic more clearly.
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarHuang Rui <ray.huang@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 753ad49c
...@@ -65,30 +65,34 @@ void drm_global_release(void) ...@@ -65,30 +65,34 @@ void drm_global_release(void)
int drm_global_item_ref(struct drm_global_reference *ref) int drm_global_item_ref(struct drm_global_reference *ref)
{ {
int ret; int ret = 0;
struct drm_global_item *item = &glob[ref->global_type]; struct drm_global_item *item = &glob[ref->global_type];
mutex_lock(&item->mutex); mutex_lock(&item->mutex);
if (item->refcount == 0) { if (item->refcount == 0) {
item->object = kzalloc(ref->size, GFP_KERNEL); ref->object = kzalloc(ref->size, GFP_KERNEL);
if (unlikely(item->object == NULL)) { if (unlikely(ref->object == NULL)) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_err; goto error_unlock;
} }
ref->object = item->object;
ret = ref->init(ref); ret = ref->init(ref);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
goto out_err; goto error_free;
item->object = ref->object;
} else {
ref->object = item->object;
} }
++item->refcount; ++item->refcount;
ref->object = item->object;
mutex_unlock(&item->mutex); mutex_unlock(&item->mutex);
return 0; return 0;
out_err:
error_free:
kfree(ref->object);
ref->object = NULL;
error_unlock:
mutex_unlock(&item->mutex); mutex_unlock(&item->mutex);
item->object = NULL;
return ret; return ret;
} }
EXPORT_SYMBOL(drm_global_item_ref); EXPORT_SYMBOL(drm_global_item_ref);
......
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