Subject: do_mmap_pgoff issue...

From: Gerhard Jaeger <[email-masked]>
Date: Thu, 27 Apr 2006 15:59:19 +0200

Hi list,

while trying to mmap some flash area on my mpc8541 CDS board, 
I noticed that the overflow case is probably not correctly handled 
within function do_mmap_pgoff in linux/mm/mmap.c

The facts:
- mmap the last page @ 0xFFFFF000, len 4K
- result: mmap says EOVERFLOW...
- the function that failed was do_mmap_pgoff()

Here's the pice of code

/* offset overflow? */
if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
    return -EOVERFLOW;

It's quite clear why it fails in my case:
pgoff + (len >> PAGE_SHIFT) will be 0

I fixed that by inserting the following, to handle that special case:

if ((pgoff + (len >> PAGE_SHIFT)) < pgoff) {
    if ((pgoff + (len >> PAGE_SHIFT)) != 0 )
        return -EOVERFLOW;
}

My question is - is that behaviour a bug or a feature? In fact it's
an off-by-one issue, but I could not believe, that nobody else ever
had problems with that.

TIA for enlighten me
Gerhard

-- 
Gerhard Jaeger <[email-masked]>            
SYSGO AG                      Embedded and Real-Time Software
www.sysgo.com | www.elinos.com | www.pikeos.com | www.osek.de