Linux Kernel Pointer and error value-general Linux technology-Linux programming and kernel information. The following is a detailed description. We often see ERR_PTR, IS_ERR, and PTR_ERR inline functions in kernel code and drivers.
Many kernel functions need to return a pointer, but the function call may fail. In this case, we usually return a NULL pointer, it is like the return value of malloc or kmalloc when the specified space application is not obtained. However, sometimes we want to know the cause of function failure, but returning NULL is not enough information. Therefore, some functions return an actual error code to handle the cause of the error. Many kernel interfaces return error messages by coding error values to a pointer value. When processing such a function, it cannot be compared with NULL to determine whether the call is successful. To facilitate the use of such interfaces, the 2.6 kernel implements three inline functions in linux/err. h:
A pointer-type function can return an error value. The error here is the normal negative error code. The caller can use IS_ERR to check whether the returned pointer is an error code.
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