drm/i915: Prefer list_first_entry_or_null
authorChris Wilson <chris@chris-wilson.co.uk>
Tue, 26 Jul 2016 11:01:51 +0000 (12:01 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Tue, 26 Jul 2016 12:00:58 +0000 (13:00 +0100)
list_first_entry_or_null() can generate better code than using
if (!list_empty()) {ptr = list_first_entry()) ..., so put it to use.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: http://patchwork.freedesktop.org/patch/msgid/1469432687-22756-3-git-send-email-chris@chris-wilson.co.uk
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1469530913-17180-2-git-send-email-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_gem_gtt.c
drivers/gpu/drm/i915/i915_gem_request.c
drivers/gpu/drm/i915/i915_gem_shrinker.c

index 30da543e1bdfd85b390d3d6869a3058b91bc73d0..38e7d992a20d7ecf5e1fb9264a4e4985368d51c2 100644 (file)
@@ -2736,13 +2736,11 @@ static void i915_gtt_color_adjust(struct drm_mm_node *node,
        if (node->color != color)
                *start += 4096;
 
-       if (!list_empty(&node->node_list)) {
-               node = list_entry(node->node_list.next,
-                                 struct drm_mm_node,
-                                 node_list);
-               if (node->allocated && node->color != color)
-                       *end -= 4096;
-       }
+       node = list_first_entry_or_null(&node->node_list,
+                                       struct drm_mm_node,
+                                       node_list);
+       if (node && node->allocated && node->color != color)
+               *end -= 4096;
 }
 
 static int i915_gem_setup_global_gtt(struct drm_device *dev,
index 60a3a343b3a89af1e4267f911f89b8dd6fbe94c0..49396b895a363986310ac32c9bebdf82375f1606 100644 (file)
@@ -317,12 +317,10 @@ __i915_gem_request_alloc(struct intel_engine_cs *engine,
                return ret;
 
        /* Move the oldest request to the slab-cache (if not in use!) */
-       if (!list_empty(&engine->request_list)) {
-               req = list_first_entry(&engine->request_list,
+       req = list_first_entry_or_null(&engine->request_list,
                                       typeof(*req), list);
-               if (i915_gem_request_completed(req))
-                       i915_gem_request_retire(req);
-       }
+       if (req && i915_gem_request_completed(req))
+               i915_gem_request_retire(req);
 
        req = kmem_cache_zalloc(dev_priv->requests, GFP_KERNEL);
        if (!req)
index afaa2597e35e17cfd4ad1a705050b9fafae32a3b..5d4772c146b1f35b47213459b58a74486c89b70a 100644 (file)
@@ -163,17 +163,18 @@ i915_gem_shrink(struct drm_i915_private *dev_priv,
         */
        for (phase = phases; phase->list; phase++) {
                struct list_head still_in_list;
+               struct drm_i915_gem_object *obj;
 
                if ((flags & phase->bit) == 0)
                        continue;
 
                INIT_LIST_HEAD(&still_in_list);
-               while (count < target && !list_empty(phase->list)) {
-                       struct drm_i915_gem_object *obj;
+               while (count < target &&
+                      (obj = list_first_entry_or_null(phase->list,
+                                                      typeof(*obj),
+                                                      global_list))) {
                        struct i915_vma *vma, *v;
 
-                       obj = list_first_entry(phase->list,
-                                              typeof(*obj), global_list);
                        list_move_tail(&obj->global_list, &still_in_list);
 
                        if (flags & I915_SHRINK_PURGEABLE &&