On to, 2016-09-29 at 16:35 +0100, Tvrtko Ursulin wrote:
> +static int mmio_reg_cmp(const void *key, const void *elt)
+ {
<SNIP>
> 
> +     if (offset < i915_mmio_reg_offset(*reg))
> +             return -1;
> +     else if (offset > i915_mmio_reg_offset(*reg))
> +             return 1;
> +     else
> +             return 0;

I was about to suggest return a - b; but then realized it might
overflow. After a bit of searching, that is done in
regcache_default_cmp though. So not sure if it's a bug in there or did
I miss something. This is safe way at least.

>  static bool is_gen8_shadowed(u32 offset)
>  {
> > -   int i;
> > -   for (i = 0; i < ARRAY_SIZE(gen8_shadowed_regs); i++)
> > -           if (offset == gen8_shadowed_regs[i].reg)
> > -                   return true;
> > +   i915_reg_t *reg;
>  
> > -   return false;
> +     reg = bsearch((void *)(unsigned long)offset,

(unsigned long) is not required, as we don't have sign bits to extend.

> +                   (const void *)gen8_shadowed_regs,
> +                   ARRAY_SIZE(gen8_shadowed_regs),
> +                   sizeof(i915_reg_t),
> +                   mmio_reg_cmp);
> +
> +     return reg ? true : false;

As I previously learnt, no need to explicitly convert bool types
anymore, so this can just be return bsearch(...);

With the last two fixed,

Reviewed-by: Joonas Lahtinen <[email protected]>

Regards, Joonas
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to