RE: How to create node in /dev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 
> static int __init my_init(void) {
>     int err = 0;
>     if (alloc_chrdev_region(&dev, 0, 1, "my_device") != 0) {
>         printk("<1>error: alloc_chrdev_region failed!");
>         return -1;
>     }

Just calling register_chrdev should be enough for you case. See drivers\char\mem.c for an example.

>     cdev_init(&amp;my_cdev, &amp;fops);
>     err = cdev_add(&amp;my_cdev, &amp;dev, 1);

You don't need all this code.

> then I add this line to the /etc/udev/udev.rules:
> KERNEL=="my_device"        NAME="my_device"
> 

No need to modify udev.rules unless you want to change the name of the created device file.

-
Sekhar Nori

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux