[PATCH] dma-debug: Fix the overlap() function to be correct andreadable

From: Ingo Molnar
Date: Fri Jul 10 2009 - 15:52:24 EST



* Ingo Molnar <mingo@xxxxxxx> wrote:

> > IOW, I think this whole function is just total crap, apparently
> > put together by randomly assembling characters until it
> > compiles. Somebody should put more effort into looking at it,
> > but I think it should be something like
> >
> > static inline int overlap(void *addr, unsigned long len, void *start, void *end)
> > {
> > unsigned long a1 = (unsigned long) addr;
> > unsigned long b1 = a1 + len;
> > unsigned long a2 = (unsigned long) start;
> > unsigned long b2 = (unsigned long) end;
>
> At least some arguments have unsigned long natural types (they come
> out of page_address() for example) so the function parameters could
> perhaps be changed to unsigned long too as well.
>
> > #ifdef WE_CARE_DEEPLY
> > /* Overflow? */
> > if (b1 < a1)
> > return 1;
> > #ifdef AND_ARE_ANAL
> > if (b2 < a2)
> > return 1;
> > #endif
> > #endif
> > return !(b1 <= a2 || a1 >= b2);
> > }
> >
> > but I really migth have done soemthing wrong there. It's a
> > simple function, but somebody needs to double-check that I
> > haven't made it worse.
>
> Looks correct to me.

How about the patch below? Lightly tested.

Ingo

------------>