title: device_create with existing device name
body: <p>I'm learning how to write character device drivers as dynamically-loadable modules for the Linux. Typically I use the following sequence of function calls to register the device and create a device file which appears under <code>/dev/</code>:</p>
  
  <pre><code>alloc_chrdev_region(&amp;first, 0, 1, "myclass");
  myclass = class_create(THIS_MODULE, "myclass");
  device_create(myclass, NULL, first, NULL, "mydevicefile");
  cdev_init(&amp;c_dev, &amp;fops);
  cdev_add(&amp;c_dev, first, 1);
  </code></pre>
  
  <p>The device file then appears at <code>/dev/mydevicefile</code> and I'm able to interact with it.</p>
  
  <p>This made me wonder what would happen if passed an existing device file name instead of <em>"mydevicefile"</em>:</p>
  
  <pre><code>device_create(myclass, NULL, first, NULL, "null");
  </code></pre>
  
  <p>This resulted in <code>/dev/null</code> being replaced by my character device file -- and more concerning: an onslaught of error messages in my console from daemons expecting the original <code>/dev/null</code>. Not even removing my faux <code>null</code> module fixed this.</p>
  
  <p>While in practice there should not be an existing device file with the same name as the one my module uses, the fact that it is theoretically possible to overwrite another device file still bothers me.</p>
  
  <p>How do I protect against the case that a device file already exists with the same name as the one I intend to use?</p>
  
  <p><strong>UPDATE</strong>: I suppose what I'm really tying to find out is why udev is permitting the replacement.</p>