drm: Unify and fix idr error handling
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 15 Mar 2012 17:58:31 +0000 (19:58 +0200)
committerDave Airlie <airlied@redhat.com>
Tue, 24 Apr 2012 08:50:20 +0000 (09:50 +0100)
The error handling code w.r.t. idr usage looks inconsistent.

In the case of drm_mode_object_get() and drm_ctxbitmap_next() the error
handling is also incomplete.

Unify the code to follow the same pattern always.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_context.c
drivers/gpu/drm/drm_crtc.c
drivers/gpu/drm/drm_gem.c
drivers/gpu/drm/drm_stub.c

index 325365f6d355c3c12bf2386bb354bd095d873061..affa629589ace645952535d707df72e14813b67b 100644 (file)
@@ -85,11 +85,12 @@ again:
        mutex_lock(&dev->struct_mutex);
        ret = idr_get_new_above(&dev->ctx_idr, NULL,
                                DRM_RESERVED_CONTEXTS, &new_id);
-       if (ret == -EAGAIN) {
-               mutex_unlock(&dev->struct_mutex);
-               goto again;
-       }
        mutex_unlock(&dev->struct_mutex);
+       if (ret == -EAGAIN)
+               goto again;
+       else if (ret)
+               return ret;
+
        return new_id;
 }
 
index 4d4e8b055731240417da008e670911b1c90b6332..a9ca1b80fc28aa9e330f407accc750455906b180 100644 (file)
@@ -227,7 +227,7 @@ static int drm_mode_object_get(struct drm_device *dev,
 again:
        if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) {
                DRM_ERROR("Ran out memory getting a mode number\n");
-               return -EINVAL;
+               return -ENOMEM;
        }
 
        mutex_lock(&dev->mode_config.idr_mutex);
@@ -235,6 +235,8 @@ again:
        mutex_unlock(&dev->mode_config.idr_mutex);
        if (ret == -EAGAIN)
                goto again;
+       else if (ret)
+               return ret;
 
        obj->id = new_id;
        obj->type = obj_type;
index 83114b5e3cee236fe6a2f5b2cb261d6ba1abb3f8..fc6ded8f318b6d6242ce3ebe2a30dec71dc6e627 100644 (file)
@@ -272,8 +272,7 @@ again:
        spin_unlock(&file_priv->table_lock);
        if (ret == -EAGAIN)
                goto again;
-
-       if (ret != 0)
+       else if (ret)
                return ret;
 
        drm_gem_object_handle_reference(obj);
@@ -456,8 +455,7 @@ again:
 
                if (ret == -EAGAIN)
                        goto again;
-
-               if (ret != 0)
+               else if (ret)
                        goto err;
 
                /* Allocate a reference for the name table.  */
index aa454f80e1098c641fa82834bc9034df001c578f..ae1ccf1d5d96c68cc27427aaee469b15519e6e06 100644 (file)
@@ -122,11 +122,10 @@ again:
        ret = idr_get_new_above(&drm_minors_idr, NULL,
                                base, &new_id);
        mutex_unlock(&dev->struct_mutex);
-       if (ret == -EAGAIN) {
+       if (ret == -EAGAIN)
                goto again;
-       } else if (ret) {
+       else if (ret)
                return ret;
-       }
 
        if (new_id >= limit) {
                idr_remove(&drm_minors_idr, new_id);