ts-7000
[Top] [All Lists]

[ts-7000] potential bug + fix in samplecode/button.c

To:
Subject: [ts-7000] potential bug + fix in samplecode/button.c
From: "Jonathan" <>
Date: Fri, 28 Sep 2007 03:47:34 -0000

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/
 

<Prev in Thread] Current Thread [Next in Thread>
  • [ts-7000] potential bug + fix in samplecode/button.c, Jonathan <=
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU