From 9f0f5970db54ce9c42f2d66e54e9cb3c35333c13 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Tigeot?= Date: Sat, 7 Feb 2015 11:11:17 +0100 Subject: [PATCH] drm: Start using idr_alloc() --- sys/dev/drm/drm_crtc.c | 27 +++++++++------------------ sys/dev/drm/i915/i915_gem_context.c | 21 +++++---------------- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/sys/dev/drm/drm_crtc.c b/sys/dev/drm/drm_crtc.c index 700da0f749..9e77a72081 100644 --- a/sys/dev/drm/drm_crtc.c +++ b/sys/dev/drm/drm_crtc.c @@ -271,30 +271,21 @@ EXPORT_SYMBOL(drm_get_connector_status_name); static int drm_mode_object_get(struct drm_device *dev, struct drm_mode_object *obj, uint32_t obj_type) { - int new_id = 0; 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; - } - - lockmgr(&dev->mode_config.idr_mutex, LK_EXCLUSIVE); - ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id); - lockmgr(&dev->mode_config.idr_mutex, LK_RELEASE); - if (ret == -EAGAIN) - goto again; - else if (ret) - return ret; - + mutex_lock(&dev->mode_config.idr_mutex); + ret = idr_alloc(&dev->mode_config.crtc_idr, obj, 1, 0, GFP_KERNEL); + if (ret >= 0) { /* * Set up the object linking under the protection of the idr * lock so that other users can't see inconsistent state. */ - obj->id = new_id; - obj->type = obj_type; - return 0; + obj->id = ret; + obj->type = obj_type; + } + mutex_unlock(&dev->mode_config.idr_mutex); + + return ret < 0 ? ret : 0; } /** diff --git a/sys/dev/drm/i915/i915_gem_context.c b/sys/dev/drm/i915/i915_gem_context.c index 46fdf64763..3dd6d56310 100644 --- a/sys/dev/drm/i915/i915_gem_context.c +++ b/sys/dev/drm/i915/i915_gem_context.c @@ -140,7 +140,7 @@ create_hw_context(struct drm_device *dev, { struct drm_i915_private *dev_priv = dev->dev_private; struct i915_hw_context *ctx; - int ret, id; + int ret; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (ctx == NULL) @@ -172,22 +172,11 @@ create_hw_context(struct drm_device *dev, ctx->file_priv = file_priv; -again: - if (idr_pre_get(&file_priv->context_idr, GFP_KERNEL) == 0) { - ret = -ENOMEM; - DRM_DEBUG_DRIVER("idr allocation failed\n"); - goto err_out; - } - - ret = idr_get_new_above(&file_priv->context_idr, ctx, - DEFAULT_CONTEXT_ID + 1, &id); - if (ret == 0) - ctx->id = id; - - if (ret == -EAGAIN) - goto again; - else if (ret) + ret = idr_alloc(&file_priv->context_idr, ctx, DEFAULT_CONTEXT_ID + 1, 0, + GFP_KERNEL); + if (ret < 0) goto err_out; + ctx->id = ret; return ctx; -- 2.11.4.GIT