Commit 2e928815 authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

drm: convert to idr_alloc()

Convert to the much saner new idr interface.

* drm_ctxbitmap_next() error handling in drm_addctx() seems broken.
  drm_ctxbitmap_next() return -errno on failure not -1.

[artem.savkov@gmail.com: missing idr_preload_end in drm_gem_flink_ioctl]
[jslaby@suse.cz: fix drm_gem_flink_ioctl() return value]
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarDavid Airlie <airlied@linux.ie>
Signed-off-by: default avatarArtem Savkov <artem.savkov@gmail.com>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 62f516b8
...@@ -74,24 +74,13 @@ void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle) ...@@ -74,24 +74,13 @@ void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
*/ */
static int drm_ctxbitmap_next(struct drm_device * dev) static int drm_ctxbitmap_next(struct drm_device * dev)
{ {
int new_id;
int ret; int ret;
again:
if (idr_pre_get(&dev->ctx_idr, GFP_KERNEL) == 0) {
DRM_ERROR("Out of memory expanding drawable idr\n");
return -ENOMEM;
}
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
ret = idr_get_new_above(&dev->ctx_idr, NULL, ret = idr_alloc(&dev->ctx_idr, NULL, DRM_RESERVED_CONTEXTS, 0,
DRM_RESERVED_CONTEXTS, &new_id); GFP_KERNEL);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
if (ret == -EAGAIN) return ret;
goto again;
else if (ret)
return ret;
return new_id;
} }
/** /**
......
...@@ -266,32 +266,21 @@ char *drm_get_connector_status_name(enum drm_connector_status status) ...@@ -266,32 +266,21 @@ char *drm_get_connector_status_name(enum drm_connector_status status)
static int drm_mode_object_get(struct drm_device *dev, static int drm_mode_object_get(struct drm_device *dev,
struct drm_mode_object *obj, uint32_t obj_type) struct drm_mode_object *obj, uint32_t obj_type)
{ {
int new_id = 0;
int ret; int ret;
again:
if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) {
DRM_ERROR("Ran out memory getting a mode number\n");
return -ENOMEM;
}
mutex_lock(&dev->mode_config.idr_mutex); mutex_lock(&dev->mode_config.idr_mutex);
ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id); ret = idr_alloc(&dev->mode_config.crtc_idr, obj, 1, 0, GFP_KERNEL);
if (ret >= 0) {
if (!ret) {
/* /*
* Set up the object linking under the protection of the idr * Set up the object linking under the protection of the idr
* lock so that other users can't see inconsistent state. * lock so that other users can't see inconsistent state.
*/ */
obj->id = new_id; obj->id = ret;
obj->type = obj_type; obj->type = obj_type;
} }
mutex_unlock(&dev->mode_config.idr_mutex); mutex_unlock(&dev->mode_config.idr_mutex);
if (ret == -EAGAIN) return ret < 0 ? ret : 0;
goto again;
return ret;
} }
/** /**
......
...@@ -270,21 +270,19 @@ drm_gem_handle_create(struct drm_file *file_priv, ...@@ -270,21 +270,19 @@ drm_gem_handle_create(struct drm_file *file_priv,
int ret; int ret;
/* /*
* Get the user-visible handle using idr. * Get the user-visible handle using idr. Preload and perform
* allocation under our spinlock.
*/ */
again: idr_preload(GFP_KERNEL);
/* ensure there is space available to allocate a handle */
if (idr_pre_get(&file_priv->object_idr, GFP_KERNEL) == 0)
return -ENOMEM;
/* do the allocation under our spinlock */
spin_lock(&file_priv->table_lock); spin_lock(&file_priv->table_lock);
ret = idr_get_new_above(&file_priv->object_idr, obj, 1, (int *)handlep);
ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_NOWAIT);
spin_unlock(&file_priv->table_lock); spin_unlock(&file_priv->table_lock);
if (ret == -EAGAIN) idr_preload_end();
goto again; if (ret < 0)
else if (ret)
return ret; return ret;
*handlep = ret;
drm_gem_object_handle_reference(obj); drm_gem_object_handle_reference(obj);
...@@ -451,29 +449,25 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data, ...@@ -451,29 +449,25 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
if (obj == NULL) if (obj == NULL)
return -ENOENT; return -ENOENT;
again: idr_preload(GFP_KERNEL);
if (idr_pre_get(&dev->object_name_idr, GFP_KERNEL) == 0) {
ret = -ENOMEM;
goto err;
}
spin_lock(&dev->object_name_lock); spin_lock(&dev->object_name_lock);
if (!obj->name) { if (!obj->name) {
ret = idr_get_new_above(&dev->object_name_idr, obj, 1, ret = idr_alloc(&dev->object_name_idr, obj, 1, 0, GFP_NOWAIT);
&obj->name); obj->name = ret;
args->name = (uint64_t) obj->name; args->name = (uint64_t) obj->name;
spin_unlock(&dev->object_name_lock); spin_unlock(&dev->object_name_lock);
idr_preload_end();
if (ret == -EAGAIN) if (ret < 0)
goto again;
else if (ret)
goto err; goto err;
ret = 0;
/* Allocate a reference for the name table. */ /* Allocate a reference for the name table. */
drm_gem_object_reference(obj); drm_gem_object_reference(obj);
} else { } else {
args->name = (uint64_t) obj->name; args->name = (uint64_t) obj->name;
spin_unlock(&dev->object_name_lock); spin_unlock(&dev->object_name_lock);
idr_preload_end();
ret = 0; ret = 0;
} }
......
...@@ -109,7 +109,6 @@ EXPORT_SYMBOL(drm_ut_debug_printk); ...@@ -109,7 +109,6 @@ EXPORT_SYMBOL(drm_ut_debug_printk);
static int drm_minor_get_id(struct drm_device *dev, int type) static int drm_minor_get_id(struct drm_device *dev, int type)
{ {
int new_id;
int ret; int ret;
int base = 0, limit = 63; int base = 0, limit = 63;
...@@ -121,25 +120,11 @@ static int drm_minor_get_id(struct drm_device *dev, int type) ...@@ -121,25 +120,11 @@ static int drm_minor_get_id(struct drm_device *dev, int type)
limit = base + 255; limit = base + 255;
} }
again:
if (idr_pre_get(&drm_minors_idr, GFP_KERNEL) == 0) {
DRM_ERROR("Out of memory expanding drawable idr\n");
return -ENOMEM;
}
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
ret = idr_get_new_above(&drm_minors_idr, NULL, ret = idr_alloc(&drm_minors_idr, NULL, base, limit, GFP_KERNEL);
base, &new_id);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
if (ret == -EAGAIN)
goto again;
else if (ret)
return ret;
if (new_id >= limit) { return ret == -ENOSPC ? -EINVAL : ret;
idr_remove(&drm_minors_idr, new_id);
return -EINVAL;
}
return new_id;
} }
struct drm_master *drm_master_create(struct drm_minor *minor) struct drm_master *drm_master_create(struct drm_minor *minor)
......
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