aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 23:58:09 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 23:58:09 -0500
commit2a7d2b96d5cba7568139d9ab157a0e97ab32440f (patch)
treead029d8cc7b7068b7250e914360ec6315fdfa114 /drivers/gpu
parente3c4877de8b9d93bd47b6ee88eb594b1c1e10da5 (diff)
parentb67bfe0d42cac56c512dd5da4b1b347a23f4b70a (diff)
Merge branch 'akpm' (final batch from Andrew)
Merge third patch-bumb from Andrew Morton: "This wraps me up for -rc1. - Lots of misc stuff and things which were deferred/missed from patchbombings 1 & 2. - ocfs2 things - lib/scatterlist - hfsplus - fatfs - documentation - signals - procfs - lockdep - coredump - seqfile core - kexec - Tejun's large IDR tree reworkings - ipmi - partitions - nbd - random() things - kfifo - tools/testing/selftests updates - Sasha's large and pointless hlist cleanup" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (163 commits) hlist: drop the node parameter from iterators kcmp: make it depend on CHECKPOINT_RESTORE selftests: add a simple doc tools/testing/selftests/Makefile: rearrange targets selftests/efivarfs: add create-read test selftests/efivarfs: add empty file creation test selftests: add tests for efivarfs kfifo: fix kfifo_alloc() and kfifo_init() kfifo: move kfifo.c from kernel/ to lib/ arch Kconfig: centralise CONFIG_ARCH_NO_VIRT_TO_BUS w1: add support for DS2413 Dual Channel Addressable Switch memstick: move the dereference below the NULL test drivers/pps/clients/pps-gpio.c: use devm_kzalloc Documentation/DMA-API-HOWTO.txt: fix typo include/linux/eventfd.h: fix incorrect filename is a comment mtd: mtd_stresstest: use prandom_bytes() mtd: mtd_subpagetest: convert to use prandom library mtd: mtd_speedtest: use prandom_bytes mtd: mtd_pagetest: convert to use prandom library mtd: mtd_oobtest: convert to use prandom library ...
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/drm_context.c19
-rw-r--r--drivers/gpu/drm/drm_crtc.c20
-rw-r--r--drivers/gpu/drm/drm_drv.c1
-rw-r--r--drivers/gpu/drm/drm_gem.c40
-rw-r--r--drivers/gpu/drm/drm_hashtab.c19
-rw-r--r--drivers/gpu/drm/drm_stub.c19
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_ipp.c20
-rw-r--r--drivers/gpu/drm/i915/i915_gem_context.c21
-rw-r--r--drivers/gpu/drm/sis/sis_drv.c1
-rw-r--r--drivers/gpu/drm/sis/sis_mm.c13
-rw-r--r--drivers/gpu/drm/via/via_map.c1
-rw-r--r--drivers/gpu/drm/via/via_mm.c13
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c17
13 files changed, 58 insertions, 146 deletions
diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
index 45adf97e678f..725968d38976 100644
--- a/drivers/gpu/drm/drm_context.c
+++ b/drivers/gpu/drm/drm_context.c
@@ -74,24 +74,13 @@ void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
74 */ 74 */
75static int drm_ctxbitmap_next(struct drm_device * dev) 75static int drm_ctxbitmap_next(struct drm_device * dev)
76{ 76{
77 int new_id;
78 int ret; 77 int ret;
79 78
80again:
81 if (idr_pre_get(&dev->ctx_idr, GFP_KERNEL) == 0) {
82 DRM_ERROR("Out of memory expanding drawable idr\n");
83 return -ENOMEM;
84 }
85 mutex_lock(&dev->struct_mutex); 79 mutex_lock(&dev->struct_mutex);
86 ret = idr_get_new_above(&dev->ctx_idr, NULL, 80 ret = idr_alloc(&dev->ctx_idr, NULL, DRM_RESERVED_CONTEXTS, 0,
87 DRM_RESERVED_CONTEXTS, &new_id); 81 GFP_KERNEL);
88 mutex_unlock(&dev->struct_mutex); 82 mutex_unlock(&dev->struct_mutex);
89 if (ret == -EAGAIN) 83 return ret;
90 goto again;
91 else if (ret)
92 return ret;
93
94 return new_id;
95} 84}
96 85
97/** 86/**
@@ -118,7 +107,7 @@ int drm_ctxbitmap_init(struct drm_device * dev)
118void drm_ctxbitmap_cleanup(struct drm_device * dev) 107void drm_ctxbitmap_cleanup(struct drm_device * dev)
119{ 108{
120 mutex_lock(&dev->struct_mutex); 109 mutex_lock(&dev->struct_mutex);
121 idr_remove_all(&dev->ctx_idr); 110 idr_destroy(&dev->ctx_idr);
122 mutex_unlock(&dev->struct_mutex); 111 mutex_unlock(&dev->struct_mutex);
123} 112}
124 113
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 3bdf2a650d9c..792c3e3795ca 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -266,32 +266,21 @@ char *drm_get_connector_status_name(enum drm_connector_status status)
266static int drm_mode_object_get(struct drm_device *dev, 266static int drm_mode_object_get(struct drm_device *dev,
267 struct drm_mode_object *obj, uint32_t obj_type) 267 struct drm_mode_object *obj, uint32_t obj_type)
268{ 268{
269 int new_id = 0;
270 int ret; 269 int ret;
271 270
272again:
273 if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) {
274 DRM_ERROR("Ran out memory getting a mode number\n");
275 return -ENOMEM;
276 }
277
278 mutex_lock(&dev->mode_config.idr_mutex); 271 mutex_lock(&dev->mode_config.idr_mutex);
279 ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id); 272 ret = idr_alloc(&dev->mode_config.crtc_idr, obj, 1, 0, GFP_KERNEL);
280 273 if (ret >= 0) {
281 if (!ret) {
282 /* 274 /*
283 * Set up the object linking under the protection of the idr 275 * Set up the object linking under the protection of the idr
284 * lock so that other users can't see inconsistent state. 276 * lock so that other users can't see inconsistent state.
285 */ 277 */
286 obj->id = new_id; 278 obj->id = ret;
287 obj->type = obj_type; 279 obj->type = obj_type;
288 } 280 }
289 mutex_unlock(&dev->mode_config.idr_mutex); 281 mutex_unlock(&dev->mode_config.idr_mutex);
290 282
291 if (ret == -EAGAIN) 283 return ret < 0 ? ret : 0;
292 goto again;
293
294 return ret;
295} 284}
296 285
297/** 286/**
@@ -1272,7 +1261,6 @@ void drm_mode_config_cleanup(struct drm_device *dev)
1272 crtc->funcs->destroy(crtc); 1261 crtc->funcs->destroy(crtc);
1273 } 1262 }
1274 1263
1275 idr_remove_all(&dev->mode_config.crtc_idr);
1276 idr_destroy(&dev->mode_config.crtc_idr); 1264 idr_destroy(&dev->mode_config.crtc_idr);
1277} 1265}
1278EXPORT_SYMBOL(drm_mode_config_cleanup); 1266EXPORT_SYMBOL(drm_mode_config_cleanup);
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index be174cab105a..25f91cd23e60 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -297,7 +297,6 @@ static void __exit drm_core_exit(void)
297 297
298 unregister_chrdev(DRM_MAJOR, "drm"); 298 unregister_chrdev(DRM_MAJOR, "drm");
299 299
300 idr_remove_all(&drm_minors_idr);
301 idr_destroy(&drm_minors_idr); 300 idr_destroy(&drm_minors_idr);
302} 301}
303 302
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 24efae464e2c..af779ae19ebf 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -270,21 +270,19 @@ drm_gem_handle_create(struct drm_file *file_priv,
270 int ret; 270 int ret;
271 271
272 /* 272 /*
273 * Get the user-visible handle using idr. 273 * Get the user-visible handle using idr. Preload and perform
274 * allocation under our spinlock.
274 */ 275 */
275again: 276 idr_preload(GFP_KERNEL);
276 /* ensure there is space available to allocate a handle */
277 if (idr_pre_get(&file_priv->object_idr, GFP_KERNEL) == 0)
278 return -ENOMEM;
279
280 /* do the allocation under our spinlock */
281 spin_lock(&file_priv->table_lock); 277 spin_lock(&file_priv->table_lock);
282 ret = idr_get_new_above(&file_priv->object_idr, obj, 1, (int *)handlep); 278
279 ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_NOWAIT);
280
283 spin_unlock(&file_priv->table_lock); 281 spin_unlock(&file_priv->table_lock);
284 if (ret == -EAGAIN) 282 idr_preload_end();
285 goto again; 283 if (ret < 0)
286 else if (ret)
287 return ret; 284 return ret;
285 *handlep = ret;
288 286
289 drm_gem_object_handle_reference(obj); 287 drm_gem_object_handle_reference(obj);
290 288
@@ -451,29 +449,25 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
451 if (obj == NULL) 449 if (obj == NULL)
452 return -ENOENT; 450 return -ENOENT;
453 451
454again: 452 idr_preload(GFP_KERNEL);
455 if (idr_pre_get(&dev->object_name_idr, GFP_KERNEL) == 0) {
456 ret = -ENOMEM;
457 goto err;
458 }
459
460 spin_lock(&dev->object_name_lock); 453 spin_lock(&dev->object_name_lock);
461 if (!obj->name) { 454 if (!obj->name) {
462 ret = idr_get_new_above(&dev->object_name_idr, obj, 1, 455 ret = idr_alloc(&dev->object_name_idr, obj, 1, 0, GFP_NOWAIT);
463 &obj->name); 456 obj->name = ret;
464 args->name = (uint64_t) obj->name; 457 args->name = (uint64_t) obj->name;
465 spin_unlock(&dev->object_name_lock); 458 spin_unlock(&dev->object_name_lock);
459 idr_preload_end();
466 460
467 if (ret == -EAGAIN) 461 if (ret < 0)
468 goto again;
469 else if (ret)
470 goto err; 462 goto err;
463 ret = 0;
471 464
472 /* Allocate a reference for the name table. */ 465 /* Allocate a reference for the name table. */
473 drm_gem_object_reference(obj); 466 drm_gem_object_reference(obj);
474 } else { 467 } else {
475 args->name = (uint64_t) obj->name; 468 args->name = (uint64_t) obj->name;
476 spin_unlock(&dev->object_name_lock); 469 spin_unlock(&dev->object_name_lock);
470 idr_preload_end();
477 ret = 0; 471 ret = 0;
478 } 472 }
479 473
@@ -561,8 +555,6 @@ drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
561{ 555{
562 idr_for_each(&file_private->object_idr, 556 idr_for_each(&file_private->object_idr,
563 &drm_gem_object_release_handle, file_private); 557 &drm_gem_object_release_handle, file_private);
564
565 idr_remove_all(&file_private->object_idr);
566 idr_destroy(&file_private->object_idr); 558 idr_destroy(&file_private->object_idr);
567} 559}
568 560
diff --git a/drivers/gpu/drm/drm_hashtab.c b/drivers/gpu/drm/drm_hashtab.c
index 80254547a3f8..7e4bae760e27 100644
--- a/drivers/gpu/drm/drm_hashtab.c
+++ b/drivers/gpu/drm/drm_hashtab.c
@@ -60,14 +60,13 @@ void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key)
60{ 60{
61 struct drm_hash_item *entry; 61 struct drm_hash_item *entry;
62 struct hlist_head *h_list; 62 struct hlist_head *h_list;
63 struct hlist_node *list;
64 unsigned int hashed_key; 63 unsigned int hashed_key;
65 int count = 0; 64 int count = 0;
66 65
67 hashed_key = hash_long(key, ht->order); 66 hashed_key = hash_long(key, ht->order);
68 DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key); 67 DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
69 h_list = &ht->table[hashed_key]; 68 h_list = &ht->table[hashed_key];
70 hlist_for_each_entry(entry, list, h_list, head) 69 hlist_for_each_entry(entry, h_list, head)
71 DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key); 70 DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
72} 71}
73 72
@@ -76,14 +75,13 @@ static struct hlist_node *drm_ht_find_key(struct drm_open_hash *ht,
76{ 75{
77 struct drm_hash_item *entry; 76 struct drm_hash_item *entry;
78 struct hlist_head *h_list; 77 struct hlist_head *h_list;
79 struct hlist_node *list;
80 unsigned int hashed_key; 78 unsigned int hashed_key;
81 79
82 hashed_key = hash_long(key, ht->order); 80 hashed_key = hash_long(key, ht->order);
83 h_list = &ht->table[hashed_key]; 81 h_list = &ht->table[hashed_key];
84 hlist_for_each_entry(entry, list, h_list, head) { 82 hlist_for_each_entry(entry, h_list, head) {
85 if (entry->key == key) 83 if (entry->key == key)
86 return list; 84 return &entry->head;
87 if (entry->key > key) 85 if (entry->key > key)
88 break; 86 break;
89 } 87 }
@@ -95,14 +93,13 @@ static struct hlist_node *drm_ht_find_key_rcu(struct drm_open_hash *ht,
95{ 93{
96 struct drm_hash_item *entry; 94 struct drm_hash_item *entry;
97 struct hlist_head *h_list; 95 struct hlist_head *h_list;
98 struct hlist_node *list;
99 unsigned int hashed_key; 96 unsigned int hashed_key;
100 97
101 hashed_key = hash_long(key, ht->order); 98 hashed_key = hash_long(key, ht->order);
102 h_list = &ht->table[hashed_key]; 99 h_list = &ht->table[hashed_key];
103 hlist_for_each_entry_rcu(entry, list, h_list, head) { 100 hlist_for_each_entry_rcu(entry, h_list, head) {
104 if (entry->key == key) 101 if (entry->key == key)
105 return list; 102 return &entry->head;
106 if (entry->key > key) 103 if (entry->key > key)
107 break; 104 break;
108 } 105 }
@@ -113,19 +110,19 @@ int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item)
113{ 110{
114 struct drm_hash_item *entry; 111 struct drm_hash_item *entry;
115 struct hlist_head *h_list; 112 struct hlist_head *h_list;
116 struct hlist_node *list, *parent; 113 struct hlist_node *parent;
117 unsigned int hashed_key; 114 unsigned int hashed_key;
118 unsigned long key = item->key; 115 unsigned long key = item->key;
119 116
120 hashed_key = hash_long(key, ht->order); 117 hashed_key = hash_long(key, ht->order);
121 h_list = &ht->table[hashed_key]; 118 h_list = &ht->table[hashed_key];
122 parent = NULL; 119 parent = NULL;
123 hlist_for_each_entry(entry, list, h_list, head) { 120 hlist_for_each_entry(entry, h_list, head) {
124 if (entry->key == key) 121 if (entry->key == key)
125 return -EINVAL; 122 return -EINVAL;
126 if (entry->key > key) 123 if (entry->key > key)
127 break; 124 break;
128 parent = list; 125 parent = &entry->head;
129 } 126 }
130 if (parent) { 127 if (parent) {
131 hlist_add_after_rcu(parent, &item->head); 128 hlist_add_after_rcu(parent, &item->head);
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index 200e104f1fa0..7d30802a018f 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -109,7 +109,6 @@ EXPORT_SYMBOL(drm_ut_debug_printk);
109 109
110static int drm_minor_get_id(struct drm_device *dev, int type) 110static int drm_minor_get_id(struct drm_device *dev, int type)
111{ 111{
112 int new_id;
113 int ret; 112 int ret;
114 int base = 0, limit = 63; 113 int base = 0, limit = 63;
115 114
@@ -121,25 +120,11 @@ static int drm_minor_get_id(struct drm_device *dev, int type)
121 limit = base + 255; 120 limit = base + 255;
122 } 121 }
123 122
124again:
125 if (idr_pre_get(&drm_minors_idr, GFP_KERNEL) == 0) {
126 DRM_ERROR("Out of memory expanding drawable idr\n");
127 return -ENOMEM;
128 }
129 mutex_lock(&dev->struct_mutex); 123 mutex_lock(&dev->struct_mutex);
130 ret = idr_get_new_above(&drm_minors_idr, NULL, 124 ret = idr_alloc(&drm_minors_idr, NULL, base, limit, GFP_KERNEL);
131 base, &new_id);
132 mutex_unlock(&dev->struct_mutex); 125 mutex_unlock(&dev->struct_mutex);
133 if (ret == -EAGAIN)
134 goto again;
135 else if (ret)
136 return ret;
137 126
138 if (new_id >= limit) { 127 return ret == -ENOSPC ? -EINVAL : ret;
139 idr_remove(&drm_minors_idr, new_id);
140 return -EINVAL;
141 }
142 return new_id;
143} 128}
144 129
145struct drm_master *drm_master_create(struct drm_minor *minor) 130struct drm_master *drm_master_create(struct drm_minor *minor)
diff --git a/drivers/gpu/drm/exynos/exynos_drm_ipp.c b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
index 1a556354e92f..1adce07ecb5b 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_ipp.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
@@ -137,21 +137,15 @@ static int ipp_create_id(struct idr *id_idr, struct mutex *lock, void *obj,
137 137
138 DRM_DEBUG_KMS("%s\n", __func__); 138 DRM_DEBUG_KMS("%s\n", __func__);
139 139
140again:
141 /* ensure there is space available to allocate a handle */
142 if (idr_pre_get(id_idr, GFP_KERNEL) == 0) {
143 DRM_ERROR("failed to get idr.\n");
144 return -ENOMEM;
145 }
146
147 /* do the allocation under our mutexlock */ 140 /* do the allocation under our mutexlock */
148 mutex_lock(lock); 141 mutex_lock(lock);
149 ret = idr_get_new_above(id_idr, obj, 1, (int *)idp); 142 ret = idr_alloc(id_idr, obj, 1, 0, GFP_KERNEL);
150 mutex_unlock(lock); 143 mutex_unlock(lock);
151 if (ret == -EAGAIN) 144 if (ret < 0)
152 goto again; 145 return ret;
153 146
154 return ret; 147 *idp = ret;
148 return 0;
155} 149}
156 150
157static void *ipp_find_obj(struct idr *id_idr, struct mutex *lock, u32 id) 151static void *ipp_find_obj(struct idr *id_idr, struct mutex *lock, u32 id)
@@ -1786,8 +1780,6 @@ err_iommu:
1786 drm_iommu_detach_device(drm_dev, ippdrv->dev); 1780 drm_iommu_detach_device(drm_dev, ippdrv->dev);
1787 1781
1788err_idr: 1782err_idr:
1789 idr_remove_all(&ctx->ipp_idr);
1790 idr_remove_all(&ctx->prop_idr);
1791 idr_destroy(&ctx->ipp_idr); 1783 idr_destroy(&ctx->ipp_idr);
1792 idr_destroy(&ctx->prop_idr); 1784 idr_destroy(&ctx->prop_idr);
1793 return ret; 1785 return ret;
@@ -1965,8 +1957,6 @@ static int ipp_remove(struct platform_device *pdev)
1965 exynos_drm_subdrv_unregister(&ctx->subdrv); 1957 exynos_drm_subdrv_unregister(&ctx->subdrv);
1966 1958
1967 /* remove,destroy ipp idr */ 1959 /* remove,destroy ipp idr */
1968 idr_remove_all(&ctx->ipp_idr);
1969 idr_remove_all(&ctx->prop_idr);
1970 idr_destroy(&ctx->ipp_idr); 1960 idr_destroy(&ctx->ipp_idr);
1971 idr_destroy(&ctx->prop_idr); 1961 idr_destroy(&ctx->prop_idr);
1972 1962
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 21177d9df423..94d873a6cffb 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -139,7 +139,7 @@ create_hw_context(struct drm_device *dev,
139{ 139{
140 struct drm_i915_private *dev_priv = dev->dev_private; 140 struct drm_i915_private *dev_priv = dev->dev_private;
141 struct i915_hw_context *ctx; 141 struct i915_hw_context *ctx;
142 int ret, id; 142 int ret;
143 143
144 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 144 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
145 if (ctx == NULL) 145 if (ctx == NULL)
@@ -164,22 +164,11 @@ create_hw_context(struct drm_device *dev,
164 164
165 ctx->file_priv = file_priv; 165 ctx->file_priv = file_priv;
166 166
167again: 167 ret = idr_alloc(&file_priv->context_idr, ctx, DEFAULT_CONTEXT_ID + 1, 0,
168 if (idr_pre_get(&file_priv->context_idr, GFP_KERNEL) == 0) { 168 GFP_KERNEL);
169 ret = -ENOMEM; 169 if (ret < 0)
170 DRM_DEBUG_DRIVER("idr allocation failed\n");
171 goto err_out;
172 }
173
174 ret = idr_get_new_above(&file_priv->context_idr, ctx,
175 DEFAULT_CONTEXT_ID + 1, &id);
176 if (ret == 0)
177 ctx->id = id;
178
179 if (ret == -EAGAIN)
180 goto again;
181 else if (ret)
182 goto err_out; 170 goto err_out;
171 ctx->id = ret;
183 172
184 return ctx; 173 return ctx;
185 174
diff --git a/drivers/gpu/drm/sis/sis_drv.c b/drivers/gpu/drm/sis/sis_drv.c
index 841065b998a1..5a5325e6b759 100644
--- a/drivers/gpu/drm/sis/sis_drv.c
+++ b/drivers/gpu/drm/sis/sis_drv.c
@@ -58,7 +58,6 @@ static int sis_driver_unload(struct drm_device *dev)
58{ 58{
59 drm_sis_private_t *dev_priv = dev->dev_private; 59 drm_sis_private_t *dev_priv = dev->dev_private;
60 60
61 idr_remove_all(&dev_priv->object_idr);
62 idr_destroy(&dev_priv->object_idr); 61 idr_destroy(&dev_priv->object_idr);
63 62
64 kfree(dev_priv); 63 kfree(dev_priv);
diff --git a/drivers/gpu/drm/sis/sis_mm.c b/drivers/gpu/drm/sis/sis_mm.c
index 2b2f78c428af..9a43d98e5003 100644
--- a/drivers/gpu/drm/sis/sis_mm.c
+++ b/drivers/gpu/drm/sis/sis_mm.c
@@ -128,17 +128,10 @@ static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file,
128 if (retval) 128 if (retval)
129 goto fail_alloc; 129 goto fail_alloc;
130 130
131again: 131 retval = idr_alloc(&dev_priv->object_idr, item, 1, 0, GFP_KERNEL);
132 if (idr_pre_get(&dev_priv->object_idr, GFP_KERNEL) == 0) { 132 if (retval < 0)
133 retval = -ENOMEM;
134 goto fail_idr;
135 }
136
137 retval = idr_get_new_above(&dev_priv->object_idr, item, 1, &user_key);
138 if (retval == -EAGAIN)
139 goto again;
140 if (retval)
141 goto fail_idr; 133 goto fail_idr;
134 user_key = retval;
142 135
143 list_add(&item->owner_list, &file_priv->obj_list); 136 list_add(&item->owner_list, &file_priv->obj_list);
144 mutex_unlock(&dev->struct_mutex); 137 mutex_unlock(&dev->struct_mutex);
diff --git a/drivers/gpu/drm/via/via_map.c b/drivers/gpu/drm/via/via_map.c
index c0f1cc7f5ca9..d0ab3fb32acd 100644
--- a/drivers/gpu/drm/via/via_map.c
+++ b/drivers/gpu/drm/via/via_map.c
@@ -120,7 +120,6 @@ int via_driver_unload(struct drm_device *dev)
120{ 120{
121 drm_via_private_t *dev_priv = dev->dev_private; 121 drm_via_private_t *dev_priv = dev->dev_private;
122 122
123 idr_remove_all(&dev_priv->object_idr);
124 idr_destroy(&dev_priv->object_idr); 123 idr_destroy(&dev_priv->object_idr);
125 124
126 kfree(dev_priv); 125 kfree(dev_priv);
diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c
index 0d55432e02a2..0ab93ff09873 100644
--- a/drivers/gpu/drm/via/via_mm.c
+++ b/drivers/gpu/drm/via/via_mm.c
@@ -148,17 +148,10 @@ int via_mem_alloc(struct drm_device *dev, void *data,
148 if (retval) 148 if (retval)
149 goto fail_alloc; 149 goto fail_alloc;
150 150
151again: 151 retval = idr_alloc(&dev_priv->object_idr, item, 1, 0, GFP_KERNEL);
152 if (idr_pre_get(&dev_priv->object_idr, GFP_KERNEL) == 0) { 152 if (retval < 0)
153 retval = -ENOMEM;
154 goto fail_idr;
155 }
156
157 retval = idr_get_new_above(&dev_priv->object_idr, item, 1, &user_key);
158 if (retval == -EAGAIN)
159 goto again;
160 if (retval)
161 goto fail_idr; 153 goto fail_idr;
154 user_key = retval;
162 155
163 list_add(&item->owner_list, &file_priv->obj_list); 156 list_add(&item->owner_list, &file_priv->obj_list);
164 mutex_unlock(&dev->struct_mutex); 157 mutex_unlock(&dev->struct_mutex);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 16556170fb32..bc784254e78e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -177,17 +177,16 @@ int vmw_resource_alloc_id(struct vmw_resource *res)
177 177
178 BUG_ON(res->id != -1); 178 BUG_ON(res->id != -1);
179 179
180 do { 180 idr_preload(GFP_KERNEL);
181 if (unlikely(idr_pre_get(idr, GFP_KERNEL) == 0)) 181 write_lock(&dev_priv->resource_lock);
182 return -ENOMEM;
183
184 write_lock(&dev_priv->resource_lock);
185 ret = idr_get_new_above(idr, res, 1, &res->id);
186 write_unlock(&dev_priv->resource_lock);
187 182
188 } while (ret == -EAGAIN); 183 ret = idr_alloc(idr, res, 1, 0, GFP_NOWAIT);
184 if (ret >= 0)
185 res->id = ret;
189 186
190 return ret; 187 write_unlock(&dev_priv->resource_lock);
188 idr_preload_end();
189 return ret < 0 ? ret : 0;
191} 190}
192 191
193/** 192/**