resource: Simplify region_intersects() by reducing conditionals
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 3 Nov 2020 20:45:04 +0000 (22:45 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 17 Nov 2020 17:06:28 +0000 (18:06 +0100)
Now we have for 'other' and 'type' variables

other type return
  0   0 REGION_DISJOINT
  0   x REGION_INTERSECTS
  x   0 REGION_DISJOINT
  x   x REGION_MIXED

Obviously it's easier to check 'type' for 0 first instead of
currently checked 'other'.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Hanjun Guo <guohanjun@huawei.com>
Tested-by: Hanjun Guo <guohanjun@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/resource.c

index 3ae2f56..82df804 100644 (file)
@@ -557,13 +557,13 @@ int region_intersects(resource_size_t start, size_t size, unsigned long flags,
        }
        read_unlock(&resource_lock);
 
-       if (other == 0)
-               return type ? REGION_INTERSECTS : REGION_DISJOINT;
+       if (type == 0)
+               return REGION_DISJOINT;
 
-       if (type)
-               return REGION_MIXED;
+       if (other == 0)
+               return REGION_INTERSECTS;
 
-       return REGION_DISJOINT;
+       return REGION_MIXED;
 }
 EXPORT_SYMBOL_GPL(region_intersects);