1

I'm running unregister_chrdev(major, "mod_name"); but I can still the the device in ls -l /dev/.

What am I doing wrong?

Tomer Amir
  • 1,370
  • 1
  • 22
  • 50
  • How do you create a device? I think you need `device_create()/device_destroy()` pair for that. It seems that `unregister_chrdev` unregisters major number related to all devices, while device is represented by the pair of minor and major numbers – myaut Apr 11 '15 at 17:09
  • `register_chrdev(0, "mod_name", &fops);` – Tomer Amir Apr 11 '15 at 17:18
  • And this creates node in devtmpfs? Any way, please take a look to that answer http://stackoverflow.com/a/5973426/2709018 . It shows the correct way of creating character device. – myaut Apr 11 '15 at 17:24

1 Answers1

1

register_chrdev(9) and unregister_chrdev(9) do not actually create or remove files in /dev directory. You should create them beforehand by a load script. Deletion is the same, you should delete them manually.

See scull example, scull_load creates a char file (with the same major number as your module) after loading the module with insmod. scull_unload is similar, removes files under /dev after unloading with rmmod.

As @myaut suggested, this can also be done with device_create, but this is a GPL-only function and if your module is not licensed under GPL, you will have to create the files manually.

Community
  • 1
  • 1
holgac
  • 1,499
  • 1
  • 13
  • 25