Summary of related function comments in Linux driver (with new)

Source: Internet
Author: User


1, array_size macro, is to find the device structure in the number of devices defined in the Linux/kernel.h #define ARRAY_SIZE (arr) (sizeof (arr)/sizeof (arr) [0]) + __must_be_ The array (arr)/sizeof (arr) [0]) is the number of devices to be found, __must_be_array (arr) is prevented from being used by Wu, for example with pointers instead of arrays.


2, int_work before the kernel in the definition of this function is #define init_work (_work, _func, _data), it can be understood that init_work will be in your definition of _work task Force to add a work task, the task is _ Func _func This task will require some data as a parameter, and this parameter is passed through _data.        do{                                                           /                 (_work)->data = (atomic_long_t) work_data_init ();      /                    Init_list_head (& (_work)->entry);                       /                    Prepare_work ((_work), (_func));                        /          } while (0)          #define Init_delayed_work (_work,_func)                        /            do{                                                   /                    init_work (& (_work)- >work, (_func));            /                  Init_timer (& (_work)->timer);                   /             

3, container_of () #define CONTAINER_OF (PTR, type, member) ({                     const typeof (((type *) 0)->member) *__mptr = (PTR); 
    (Type *) ((char*) __mptr-offsetof (Type,member));}) (char *) __mptr converted to a byte-type pointer. (char *) __mptr-offsetof (Type,member)) is used to find the struct start address (char * pointer), then (type*) ((char *) __mptr-offsetof (Type,member)) in ( Type *) to convert a byte-type struct start pointer to a type-type struct start pointer. It is obvious that a pointer to an entire struct variable is obtained based on a pointer to a domain member variable in a struct variable.


Summary of related function comments in Linux driver (with new)

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.