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

Submitted by Huang, Ray on Sept. 5, 2016, 7 a.m.

Details

Message ID 1473058800-2964-1-git-send-email-ray.huang@amd.com
State New
Headers show
Series "drm: modify drm_global_item_ref to avoid two times of writing ref->object" ( rev: 1 ) in AMD X.Org drivers

Not browsing as part of any series.

Commit Message

Huang, Ray Sept. 5, 2016, 7 a.m.
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.

Signed-off-by: Huang Rui <ray.huang@amd.com>
---
 drivers/gpu/drm/drm_global.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
index 3d2e91c..3abe738 100644
--- a/drivers/gpu/drm/drm_global.c
+++ b/drivers/gpu/drm/drm_global.c
@@ -70,25 +70,25 @@  int drm_global_item_ref(struct drm_global_reference *ref)
 
 	mutex_lock(&item->mutex);
 	if (item->refcount == 0) {
-		item->object = kzalloc(ref->size, GFP_KERNEL);
-		if (unlikely(item->object == NULL)) {
+		ref->object = kzalloc(ref->size, GFP_KERNEL);
+		if (unlikely(ref->object == NULL)) {
 			ret = -ENOMEM;
 			goto out_err;
 		}
-
-		ref->object = item->object;
 		ret = ref->init(ref);
 		if (unlikely(ret != 0))
 			goto out_err;
 
-	}
+		item->object = ref->object;
+	} else
+		ref->object = item->object;
+
 	++item->refcount;
-	ref->object = item->object;
 	mutex_unlock(&item->mutex);
 	return 0;
 out_err:
 	mutex_unlock(&item->mutex);
-	item->object = NULL;
+	ref->object = NULL;
 	return ret;
 }
 EXPORT_SYMBOL(drm_global_item_ref);