]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/i915: Propagate error from drm_gem_object_init()
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 25 Apr 2016 12:32:13 +0000 (13:32 +0100)
committerJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Thu, 28 Apr 2016 09:28:58 +0000 (12:28 +0300)
Propagate the real error from drm_gem_object_init(). Note this also
fixes some confusion in the error return from i915_gem_alloc_object...

v2:
(Matthew Auld)
  - updated new users of gem_alloc_object from latest drm-nightly
  - replaced occurrences of IS_ERR_OR_NULL() with IS_ERR()
v3:
(Joonas Lahtinen)
  - fix double "From:" in commit message
  - add goto teardown path
v4:
(Matthew Auld)
  - rebase with i915_gem_alloc_object name change

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1461587533-8841-1-git-send-email-matthew.auld@intel.com
[Joonas: Removed spurious " = NULL" from _init() function]
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_gem_batch_pool.c
drivers/gpu/drm/i915/i915_gem_context.c
drivers/gpu/drm/i915/i915_gem_render_state.c
drivers/gpu/drm/i915/i915_guc_submission.c
drivers/gpu/drm/i915/intel_display.c
drivers/gpu/drm/i915/intel_fbdev.c
drivers/gpu/drm/i915/intel_lrc.c
drivers/gpu/drm/i915/intel_overlay.c
drivers/gpu/drm/i915/intel_ringbuffer.c

index 72b7f3351ee0f8b14ea0e196d671b31f0d498548..bf5ad5ca78267f3a6a5be472190dbe33d701395d 100644 (file)
@@ -382,8 +382,8 @@ i915_gem_create(struct drm_file *file,
 
        /* Allocate the new object */
        obj = i915_gem_object_create(dev, size);
-       if (obj == NULL)
-               return -ENOMEM;
+       if (IS_ERR(obj))
+               return PTR_ERR(obj);
 
        ret = drm_gem_handle_create(file, &obj->base, &handle);
        /* drop reference from allocate - handle holds it now */
@@ -4501,15 +4501,15 @@ struct drm_i915_gem_object *i915_gem_object_create(struct drm_device *dev,
        struct drm_i915_gem_object *obj;
        struct address_space *mapping;
        gfp_t mask;
+       int ret;
 
        obj = i915_gem_object_alloc(dev);
        if (obj == NULL)
-               return NULL;
+               return ERR_PTR(-ENOMEM);
 
-       if (drm_gem_object_init(dev, &obj->base, size) != 0) {
-               i915_gem_object_free(obj);
-               return NULL;
-       }
+       ret = drm_gem_object_init(dev, &obj->base, size);
+       if (ret)
+               goto fail;
 
        mask = GFP_HIGHUSER | __GFP_RECLAIMABLE;
        if (IS_CRESTLINE(dev) || IS_BROADWATER(dev)) {
@@ -4546,6 +4546,11 @@ struct drm_i915_gem_object *i915_gem_object_create(struct drm_device *dev,
        trace_i915_gem_object_create(obj);
 
        return obj;
+
+fail:
+       i915_gem_object_free(obj);
+
+       return ERR_PTR(ret);
 }
 
 static bool discard_backing_storage(struct drm_i915_gem_object *obj)
@@ -5351,7 +5356,7 @@ i915_gem_object_create_from_data(struct drm_device *dev,
        int ret;
 
        obj = i915_gem_object_create(dev, round_up(size, PAGE_SIZE));
-       if (IS_ERR_OR_NULL(obj))
+       if (IS_ERR(obj))
                return obj;
 
        ret = i915_gem_object_set_to_cpu_domain(obj, true);
index 1bc46ba8568cb30e347d3d93cdc8da4ecb4e45f7..3752d5daa4b2171cc9f3f45f312e7985407ae381 100644 (file)
@@ -135,8 +135,8 @@ i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,
                int ret;
 
                obj = i915_gem_object_create(pool->dev, size);
-               if (obj == NULL)
-                       return ERR_PTR(-ENOMEM);
+               if (IS_ERR(obj))
+                       return obj;
 
                ret = i915_gem_object_get_pages(obj);
                if (ret)
index 4e12bae5c6590429be0872429d3c7d2bb6ce774b..e78e2f6aec511579dc27903e7e2f821d3a64c407 100644 (file)
@@ -179,8 +179,8 @@ i915_gem_alloc_context_obj(struct drm_device *dev, size_t size)
        int ret;
 
        obj = i915_gem_object_create(dev, size);
-       if (obj == NULL)
-               return ERR_PTR(-ENOMEM);
+       if (IS_ERR(obj))
+               return obj;
 
        /*
         * Try to make the context utilize L3 as well as LLC.
index 65c9dad6a4cb12a8e994113e3cf6046cc4558cc1..423cf5144bcb6cf2ab4ff475d49221bd87568614 100644 (file)
@@ -58,8 +58,8 @@ static int render_state_init(struct render_state *so, struct drm_device *dev)
                return -EINVAL;
 
        so->obj = i915_gem_object_create(dev, 4096);
-       if (so->obj == NULL)
-               return -ENOMEM;
+       if (IS_ERR(so->obj))
+               return PTR_ERR(so->obj);
 
        ret = i915_gem_obj_ggtt_pin(so->obj, 4096, 0);
        if (ret)
index 72d6665fa97ffe34746718b5bd3c6e979783b87d..a304b0ead0999715d5a77c9e31fb51bb3d9b35f9 100644 (file)
@@ -588,7 +588,7 @@ static struct drm_i915_gem_object *gem_allocate_guc_obj(struct drm_device *dev,
        struct drm_i915_gem_object *obj;
 
        obj = i915_gem_object_create(dev, size);
-       if (!obj)
+       if (IS_ERR(obj))
                return NULL;
 
        if (i915_gem_object_get_pages(obj)) {
index eb7cb94312095aeb67c4d36c29247cac2c845d8f..d30df8761aa229d41b6972c3aa7fbd71941dc7b0 100644 (file)
@@ -10321,8 +10321,8 @@ intel_framebuffer_create_for_mode(struct drm_device *dev,
 
        obj = i915_gem_object_create(dev,
                                    intel_framebuffer_size_for_mode(mode, bpp));
-       if (obj == NULL)
-               return ERR_PTR(-ENOMEM);
+       if (IS_ERR(obj))
+               return ERR_CAST(obj);
 
        mode_cmd.width = mode->hdisplay;
        mode_cmd.height = mode->vdisplay;
index af561542a5a18074f6922430d7910bc6ab1699d1..37fc68e31eaab4086d1207e59b2c5651d87eae86 100644 (file)
@@ -151,9 +151,9 @@ static int intelfb_alloc(struct drm_fb_helper *helper,
                obj = i915_gem_object_create_stolen(dev, size);
        if (obj == NULL)
                obj = i915_gem_object_create(dev, size);
-       if (!obj) {
+       if (IS_ERR(obj)) {
                DRM_ERROR("failed to allocate framebuffer\n");
-               ret = -ENOMEM;
+               ret = PTR_ERR(obj);
                goto out;
        }
 
index 2b7e6bbc017b2c5279820de48b15d1620c10d51c..1b065e72f889391866434248e173934a962007e8 100644 (file)
@@ -1474,9 +1474,11 @@ static int lrc_setup_wa_ctx_obj(struct intel_engine_cs *engine, u32 size)
 
        engine->wa_ctx.obj = i915_gem_object_create(engine->dev,
                                                   PAGE_ALIGN(size));
-       if (!engine->wa_ctx.obj) {
+       if (IS_ERR(engine->wa_ctx.obj)) {
                DRM_DEBUG_DRIVER("alloc LRC WA ctx backing obj failed.\n");
-               return -ENOMEM;
+               ret = PTR_ERR(engine->wa_ctx.obj);
+               engine->wa_ctx.obj = NULL;
+               return ret;
        }
 
        ret = i915_gem_obj_ggtt_pin(engine->wa_ctx.obj, PAGE_SIZE, 0);
@@ -2666,9 +2668,9 @@ int intel_lr_context_deferred_alloc(struct intel_context *ctx,
        context_size += PAGE_SIZE * LRC_PPHWSP_PN;
 
        ctx_obj = i915_gem_object_create(dev, context_size);
-       if (!ctx_obj) {
+       if (IS_ERR(ctx_obj)) {
                DRM_DEBUG_DRIVER("Alloc LRC backing obj failed.\n");
-               return -ENOMEM;
+               return PTR_ERR(ctx_obj);
        }
 
        ringbuf = intel_engine_create_ringbuffer(engine, 4 * PAGE_SIZE);
index 597fbcda8c5ca32ac810ff477e687f198d8ee079..6b016c9b67f1d62765200db439594f0f52fb00cb 100644 (file)
@@ -1397,7 +1397,7 @@ void intel_setup_overlay(struct drm_device *dev)
                reg_bo = i915_gem_object_create_stolen(dev, PAGE_SIZE);
        if (reg_bo == NULL)
                reg_bo = i915_gem_object_create(dev, PAGE_SIZE);
-       if (reg_bo == NULL)
+       if (IS_ERR(reg_bo))
                goto out_free;
        overlay->reg_bo = reg_bo;
 
index d6756ce6a586d8d3262c9d4d76c9c3639ff4eff2..95f8d143d0ed4bac8ab9d46d213b9df75c139ab9 100644 (file)
@@ -672,9 +672,10 @@ intel_init_pipe_control(struct intel_engine_cs *engine)
        WARN_ON(engine->scratch.obj);
 
        engine->scratch.obj = i915_gem_object_create(engine->dev, 4096);
-       if (engine->scratch.obj == NULL) {
+       if (IS_ERR(engine->scratch.obj)) {
                DRM_ERROR("Failed to allocate seqno page\n");
-               ret = -ENOMEM;
+               ret = PTR_ERR(engine->scratch.obj);
+               engine->scratch.obj = NULL;
                goto err;
        }
 
@@ -2033,9 +2034,9 @@ static int init_status_page(struct intel_engine_cs *engine)
                int ret;
 
                obj = i915_gem_object_create(engine->dev, 4096);
-               if (obj == NULL) {
+               if (IS_ERR(obj)) {
                        DRM_ERROR("Failed to allocate status page\n");
-                       return -ENOMEM;
+                       return PTR_ERR(obj);
                }
 
                ret = i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
@@ -2174,8 +2175,8 @@ static int intel_alloc_ringbuffer_obj(struct drm_device *dev,
                obj = i915_gem_object_create_stolen(dev, ringbuf->size);
        if (obj == NULL)
                obj = i915_gem_object_create(dev, ringbuf->size);
-       if (obj == NULL)
-               return -ENOMEM;
+       if (IS_ERR(obj))
+               return PTR_ERR(obj);
 
        /* mark ring buffers as read-only from GPU side by default */
        obj->gt_ro = 1;
@@ -2787,7 +2788,7 @@ int intel_init_render_ring_buffer(struct drm_device *dev)
        if (INTEL_INFO(dev)->gen >= 8) {
                if (i915_semaphore_is_enabled(dev)) {
                        obj = i915_gem_object_create(dev, 4096);
-                       if (obj == NULL) {
+                       if (IS_ERR(obj)) {
                                DRM_ERROR("Failed to allocate semaphore bo. Disabling semaphores\n");
                                i915.semaphores = 0;
                        } else {
@@ -2896,9 +2897,9 @@ int intel_init_render_ring_buffer(struct drm_device *dev)
        /* Workaround batchbuffer to combat CS tlb bug. */
        if (HAS_BROKEN_CS_TLB(dev)) {
                obj = i915_gem_object_create(dev, I830_WA_SIZE);
-               if (obj == NULL) {
+               if (IS_ERR(obj)) {
                        DRM_ERROR("Failed to allocate batch bo\n");
-                       return -ENOMEM;
+                       return PTR_ERR(obj);
                }
 
                ret = i915_gem_obj_ggtt_pin(obj, 0, 0);