Find the answer to your Linux question:
Results 1 to 2 of 2
I am failing to create two device nodes with minor number 0 and 1 under /proc. device_create creates the first device with minor number 0, but how do I create ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2011
    Posts
    1

    Failing to create two device nodes with 0 and 1 minor number


    I am failing to create two device nodes with minor number 0 and 1 under /proc. device_create creates the first device with minor number 0, but how do I create the second device with minor number 1?
    HTML Code:
    static int __init my_driver_init (void) {
            int result;
            int major;
            printk("In init module"winking smiley;
    
            result = alloc_chrdev_region(&dev, 0, 2, mydev_name);
            if (result<0)
             return result;
    
            major = MAJOR(dev);
    
            printk("The device is registered by Major no: %d\n", major);
            my_driver_cdev = cdev_alloc();
           cdev_init (my_driver_cdev, &my_driver_fops);
            my_driver_cdev->owner = THIS_MODULE;
            result = cdev_add(my_driver_cdev, 0, 2);
            if (result<0){
              printk("Error in registering the module\n"winking smiley;
              unregister_chrdev_region(dev, 2);
              return result;
            }
    
            printk(KERN_INFO "my_driver: %d\n",__LINE__);
    
            my_driver_class = class_create(THIS_MODULE,mydev_name);
            if (IS_ERR(my_driver_class)) {
                    printk(KERN_ERR "Error creating my_driver class.\n"winking smiley;
                    result = PTR_ERR(my_driver_class);
                    cdev_del(my_driver_cdev);
                    unregister_chrdev_region(dev, 2);
                    return -1;
            }
          device_create(my_driver_class,NULL,dev,NULL,"my_driver%d",0);
    
          printk(KERN_INFO "my_driver: %d\n",__LINE__);
     
    }
    Adding the below line does not create the second device with minor number 1.

    HTML Code:
    device_create(my_driver_class,NULL,dev,NULL,"my_driver%d",1);
    Thanks in advance!!
    Azp

  2. #2
    Just Joined! charlie_arya's Avatar
    Join Date
    Sep 2009
    Posts
    39
    Where are you defining major number? Can you send the log? Are you trying to use existing device where Major number is already defined? In that case check the base minor number.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •