title: linux device driver file operations: it is possible to have race conditions?
body: <p>Consider a linux device driver that implements the open(), read(), write(), close(), unlocked_ioctl() and, maybe, mmap().</p>
  
  <p>Now, imagine that multiple (or the same) processes open the same device (/dev/device) concurrently.</p>
  
  <p>Are those file operations guaranteed in any way to be atomic w.r.t. to each other or should each of the open(), read(), write(), close() take a mutex so that one of their pairs doesn't preempt them while in the middle of changing, for example, a buffer data (through the same inode)?</p>
  
  <p>It should not be necessary if the kernel guarantee their atomicity with respect to each other and if each operation finds and leave the buffer/hardware in a consistent state.</p>
  
  <p>Please, redirect me towards some reference (if you know).</p>
  
  <p>Thank you.</p>
  
  <p>edit: it is in one of the comments, but the best reference that I found is here:</p>
  
  <p><a href="http://www.makelinux.net/ldd3/chp-6-sect-6" rel="nofollow">http://www.makelinux.net/ldd3/chp-6-sect-6</a></p>
  
  <p>It also show strategies to alleviate the problem, either by restricting to a single user, either by creating copies, either by forcing the user to wait etc.</p>