Re: [PATCH v1 1/7] resource: Simplify region_intersects() by reducing conditionals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 13, 2020 at 7:57 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
>
> 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@xxxxxxxxxxxxxxx>
> ---
>  kernel/resource.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/resource.c b/kernel/resource.c
> index 841737bbda9e..70575a61bf20 100644
> --- a/kernel/resource.c
> +++ b/kernel/resource.c
> @@ -554,13 +554,10 @@ 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;
> -
> -       return REGION_DISJOINT;
> +       return (other == 0) ? REGION_INTERSECTS : REGION_MIXED;

The parens are not needed here.

Also I would do

if (other == 0)
       REGION_INTERSECTS;

return REGION_MIXED;

>  }
>  EXPORT_SYMBOL_GPL(region_intersects);
>
> --
> 2.28.0
>



[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux