Re: Bug in __ioremap() + Patch

Michal Jaegermann (michal@ellpspace.math.ualberta.ca)
Wed, 21 Jan 1998 13:41:48 -0700 (MST)


>>
>> +++ linux-2.1.78c/arch/i386/mm/ioremap.c Tue Jan 20 20:41:53 1998
>> --- orig/linux-2.1.78/arch/i386/mm/ioremap.c Fri Apr 4 16:52:17 1997
>> @@ -95,7 +95,7 @@
>> if (phys_addr & ~PAGE_MASK)
>> return NULL;
>> size = PAGE_ALIGN(size);
>> - if (!size || size > phys_addr + size)
>> + if (!size || (size != ~phys_addr+1 && size > phys_addr + size))
>> return NULL;
>> area = get_vm_area(size);
>> if (!area)
>>
>> I'm sure there's better ways of writing the extra bit in the condition, but it
>> works.
>
>Really many places in Linux mm do the same, especially the generic mm/ code.
>

How about testing like this:
if (!size || -phys_addr < size)
return NULL;
This assumes that both 'phys_addr' and 'size' are unsigned quantities.
Will "~phys_addr + 1" be compiler-safer than "-phys_addr" above?
Does one has to check for a case when phys_addr is zero? If yes, then
if (!size || (!phys_addr && -phys_addr < size))
should do, I think.

--mj