diff options
Diffstat (limited to 'drivers/gpu/drm/drm_hashtab.c')
-rw-r--r-- | drivers/gpu/drm/drm_hashtab.c | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/drivers/gpu/drm/drm_hashtab.c b/drivers/gpu/drm/drm_hashtab.c index a93d7b4ddaa6..e3a75688f3cd 100644 --- a/drivers/gpu/drm/drm_hashtab.c +++ b/drivers/gpu/drm/drm_hashtab.c | |||
@@ -39,27 +39,18 @@ | |||
39 | 39 | ||
40 | int drm_ht_create(struct drm_open_hash *ht, unsigned int order) | 40 | int drm_ht_create(struct drm_open_hash *ht, unsigned int order) |
41 | { | 41 | { |
42 | unsigned int i; | 42 | unsigned int size = 1 << order; |
43 | 43 | ||
44 | ht->size = 1 << order; | ||
45 | ht->order = order; | 44 | ht->order = order; |
46 | ht->fill = 0; | ||
47 | ht->table = NULL; | 45 | ht->table = NULL; |
48 | ht->use_vmalloc = ((ht->size * sizeof(*ht->table)) > PAGE_SIZE); | 46 | if (size <= PAGE_SIZE / sizeof(*ht->table)) |
49 | if (!ht->use_vmalloc) { | 47 | ht->table = kcalloc(size, sizeof(*ht->table), GFP_KERNEL); |
50 | ht->table = kcalloc(ht->size, sizeof(*ht->table), GFP_KERNEL); | 48 | else |
51 | } | 49 | ht->table = vzalloc(size*sizeof(*ht->table)); |
52 | if (!ht->table) { | ||
53 | ht->use_vmalloc = 1; | ||
54 | ht->table = vmalloc(ht->size*sizeof(*ht->table)); | ||
55 | } | ||
56 | if (!ht->table) { | 50 | if (!ht->table) { |
57 | DRM_ERROR("Out of memory for hash table\n"); | 51 | DRM_ERROR("Out of memory for hash table\n"); |
58 | return -ENOMEM; | 52 | return -ENOMEM; |
59 | } | 53 | } |
60 | for (i=0; i< ht->size; ++i) { | ||
61 | INIT_HLIST_HEAD(&ht->table[i]); | ||
62 | } | ||
63 | return 0; | 54 | return 0; |
64 | } | 55 | } |
65 | EXPORT_SYMBOL(drm_ht_create); | 56 | EXPORT_SYMBOL(drm_ht_create); |
@@ -180,7 +171,6 @@ int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key) | |||
180 | list = drm_ht_find_key(ht, key); | 171 | list = drm_ht_find_key(ht, key); |
181 | if (list) { | 172 | if (list) { |
182 | hlist_del_init(list); | 173 | hlist_del_init(list); |
183 | ht->fill--; | ||
184 | return 0; | 174 | return 0; |
185 | } | 175 | } |
186 | return -EINVAL; | 176 | return -EINVAL; |
@@ -189,7 +179,6 @@ int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key) | |||
189 | int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item) | 179 | int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item) |
190 | { | 180 | { |
191 | hlist_del_init(&item->head); | 181 | hlist_del_init(&item->head); |
192 | ht->fill--; | ||
193 | return 0; | 182 | return 0; |
194 | } | 183 | } |
195 | EXPORT_SYMBOL(drm_ht_remove_item); | 184 | EXPORT_SYMBOL(drm_ht_remove_item); |
@@ -197,10 +186,10 @@ EXPORT_SYMBOL(drm_ht_remove_item); | |||
197 | void drm_ht_remove(struct drm_open_hash *ht) | 186 | void drm_ht_remove(struct drm_open_hash *ht) |
198 | { | 187 | { |
199 | if (ht->table) { | 188 | if (ht->table) { |
200 | if (ht->use_vmalloc) | 189 | if ((PAGE_SIZE / sizeof(*ht->table)) >> ht->order) |
201 | vfree(ht->table); | ||
202 | else | ||
203 | kfree(ht->table); | 190 | kfree(ht->table); |
191 | else | ||
192 | vfree(ht->table); | ||
204 | ht->table = NULL; | 193 | ht->table = NULL; |
205 | } | 194 | } |
206 | } | 195 | } |