Register_chrdev, apiregister_chrdev

Source: Internet
Author: User

Register_chrdev, apiregister_chrdev

Register_chrdev for kernel device driver APIs

Register_chrdev is used to register a character device. The source code is analyzed as follows: static inline int register_chrdev (unsigned int major, const char * name, const struct file_operations * fops) {# After setting the smallest character device number and the largest device number, call the following function to register return _ register_chrdev (major, 0,256, name, fops);} 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; # apply for a structure cd = _ register_chrdev_region (major, baseminor, count, name); if (IS_ERR (cd) return PTR_ERR (cd ); # apply for a character device cdev = cdev_alloc (); if (! Cdev) goto out2; # assign a value to the character device: cdev-> owner = fops-> owner; cdev-> ops = fops; # Set the namekobject_set_name (& cdev-> kobj, "% s", name); # Add the character device err = cdev_add (cdev, MKDEV (cd-> major, baseminor), count); if (err) goto out; # point to the newly applied character device cd-> cdev = cdev; # normally, major is not zero, so the whole function returns zero as the success result 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.