Greetings,
I found a subtle problem with
http://www.embeddedarm.com/downloads/samplecode/button.c
The mmap() should be followed with an munmap(start,getpagesize()) call
before the close(fp) (third line before the end). The code as supplied
will run as written: on process termination the memory is
automatically unmapped. However if mmap() is called too many times
without a corresponding munmap(), open("/dev/mem") will return a null
file pointer. If your program exits before that you are fine (like the
sample code) but if it's in a loop there could be trouble.
Any time you use memory-mapped I/O (like a lot of the sample code),
mmap() should be followed by munmap() -- it's not enough to just close
the file pointer. It's also good practice to check the returned
values from both open() and mmap() for null pointers. Hope this helps
others avoid a subtle bug.
mmap/munmap() RTFM here: http://linux.die.net/man/2/mmap
-Jon Foote
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|