diff options
-rw-r--r-- | drivers/gpu/drm/drm_global.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c index 3d2e91c4d78e..b404287abb97 100644 --- a/drivers/gpu/drm/drm_global.c +++ b/drivers/gpu/drm/drm_global.c | |||
@@ -65,30 +65,34 @@ void drm_global_release(void) | |||
65 | 65 | ||
66 | int drm_global_item_ref(struct drm_global_reference *ref) | 66 | int drm_global_item_ref(struct drm_global_reference *ref) |
67 | { | 67 | { |
68 | int ret; | 68 | int ret = 0; |
69 | struct drm_global_item *item = &glob[ref->global_type]; | 69 | struct drm_global_item *item = &glob[ref->global_type]; |
70 | 70 | ||
71 | mutex_lock(&item->mutex); | 71 | mutex_lock(&item->mutex); |
72 | if (item->refcount == 0) { | 72 | if (item->refcount == 0) { |
73 | item->object = kzalloc(ref->size, GFP_KERNEL); | 73 | ref->object = kzalloc(ref->size, GFP_KERNEL); |
74 | if (unlikely(item->object == NULL)) { | 74 | if (unlikely(ref->object == NULL)) { |
75 | ret = -ENOMEM; | 75 | ret = -ENOMEM; |
76 | goto out_err; | 76 | goto error_unlock; |
77 | } | 77 | } |
78 | |||
79 | ref->object = item->object; | ||
80 | ret = ref->init(ref); | 78 | ret = ref->init(ref); |
81 | if (unlikely(ret != 0)) | 79 | if (unlikely(ret != 0)) |
82 | goto out_err; | 80 | goto error_free; |
83 | 81 | ||
82 | item->object = ref->object; | ||
83 | } else { | ||
84 | ref->object = item->object; | ||
84 | } | 85 | } |
86 | |||
85 | ++item->refcount; | 87 | ++item->refcount; |
86 | ref->object = item->object; | ||
87 | mutex_unlock(&item->mutex); | 88 | mutex_unlock(&item->mutex); |
88 | return 0; | 89 | return 0; |
89 | out_err: | 90 | |
91 | error_free: | ||
92 | kfree(ref->object); | ||
93 | ref->object = NULL; | ||
94 | error_unlock: | ||
90 | mutex_unlock(&item->mutex); | 95 | mutex_unlock(&item->mutex); |
91 | item->object = NULL; | ||
92 | return ret; | 96 | return ret; |
93 | } | 97 | } |
94 | EXPORT_SYMBOL(drm_global_item_ref); | 98 | EXPORT_SYMBOL(drm_global_item_ref); |