Int _ register_chrdev (unsigned int major, unsigned int baseminor, unsigned int count,

Source: Internet
Author: User

FS/char_dev.c

/**

* _ Register_chrdev ()-create and register a cdev occupying a range of minors
* @ Major: Major device number or 0 for Dynamic Allocation
* @ Baseminor: First of the requested range of minor numbers
* @ Count: the number of minor numbers required
* @ Name: name of this range of devices
* @ Fops: file operations associated with this Devices
*
* If @ major = 0 this functions will dynamically allocate a major and return
* Its number.
*
* If @ major> 0 this function will attempt to reserve a device with the given
* Major number and will return zero on success.
*
* Returns a-ve errno on failure.
*
* The name of this device has nothing to do with the name of the device in
*/Dev. It only helps to keep track of the different owners of devices. If
* Your module name has only one type of devices it's OK to use e.g. The name
* Of the module here.
*/
Int _ register_chrdev (unsigned int major, unsigned int baseminor,
Unsigned int count, const char * Name,
Const struct file_operations * FoPs)
{
Struct char_device_struct * CD;
Struct cdev * cdev;
Int err =-enomem;

Cd = _ register_chrdev_region (Major, baseminor, Count, name );
If (is_err (CD ))
Return ptr_err (CD );

Cdev = cdev_alloc ();
If (! Cdev)
Goto out2;

Cdev-> owner = fops-> owner;
Cdev-> Ops = fops;
Kobject_set_name (& cdev-> kobj, "% s", name );

Err = cdev_add (cdev, mkdev (CD-> major, baseminor), count );
If (ERR)
Goto out;

CD-> cdev = cdev;

Return major? 0: CD-> Major;
Out:
Kobject_put (& cdev-> kobj );
Out2:
Kfree (_ unregister_chrdev_region (CD-> major, baseminor, count ));
Return err;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.