Skip to content

Commit 4d744ce

Browse files
kangtasticJonathan Corbet
authored andcommitted
err.h: Add missing kerneldocs for error pointer functions
Add kerneldocs for ERR_PTR(), PTR_ERR(), PTR_ERR_OR_ZERO(), IS_ERR(), and IS_ERR_OR_NULL(). Doing so will help convert hundreds of mentions of them in existing documentation into automatic cross-references. Also add kerneldocs for IS_ERR_VALUE(). Doing so adds no automatic cross-references, but this macro has a slightly different use case than the functionally similar IS_ERR(), and documenting it may be helpful to readers who encounter it in existing code. ERR_CAST() already has kerneldocs and has not been touched. Signed-off-by: James Seo <james@equiv.tech> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/20230509175543.2065835-3-james@equiv.tech
1 parent 34d9f62 commit 4d744ce

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

include/linux/err.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,54 @@
1919

2020
#ifndef __ASSEMBLY__
2121

22+
/**
23+
* IS_ERR_VALUE - Detect an error pointer.
24+
* @x: The pointer to check.
25+
*
26+
* Like IS_ERR(), but does not generate a compiler warning if result is unused.
27+
*/
2228
#define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
2329

30+
/**
31+
* ERR_PTR - Create an error pointer.
32+
* @error: A negative error code.
33+
*
34+
* Encodes @error into a pointer value. Users should consider the result
35+
* opaque and not assume anything about how the error is encoded.
36+
*
37+
* Return: A pointer with @error encoded within its value.
38+
*/
2439
static inline void * __must_check ERR_PTR(long error)
2540
{
2641
return (void *) error;
2742
}
2843

44+
/**
45+
* PTR_ERR - Extract the error code from an error pointer.
46+
* @ptr: An error pointer.
47+
* Return: The error code within @ptr.
48+
*/
2949
static inline long __must_check PTR_ERR(__force const void *ptr)
3050
{
3151
return (long) ptr;
3252
}
3353

54+
/**
55+
* IS_ERR - Detect an error pointer.
56+
* @ptr: The pointer to check.
57+
* Return: true if @ptr is an error pointer, false otherwise.
58+
*/
3459
static inline bool __must_check IS_ERR(__force const void *ptr)
3560
{
3661
return IS_ERR_VALUE((unsigned long)ptr);
3762
}
3863

64+
/**
65+
* IS_ERR_OR_NULL - Detect an error pointer or a null pointer.
66+
* @ptr: The pointer to check.
67+
*
68+
* Like IS_ERR(), but also returns true for a null pointer.
69+
*/
3970
static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
4071
{
4172
return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
@@ -54,6 +85,23 @@ static inline void * __must_check ERR_CAST(__force const void *ptr)
5485
return (void *) ptr;
5586
}
5687

88+
/**
89+
* PTR_ERR_OR_ZERO - Extract the error code from a pointer if it has one.
90+
* @ptr: A potential error pointer.
91+
*
92+
* Convenience function that can be used inside a function that returns
93+
* an error code to propagate errors received as error pointers.
94+
* For example, ``return PTR_ERR_OR_ZERO(ptr);`` replaces:
95+
*
96+
* .. code-block:: c
97+
*
98+
* if (IS_ERR(ptr))
99+
* return PTR_ERR(ptr);
100+
* else
101+
* return 0;
102+
*
103+
* Return: The error code within @ptr if it is an error pointer; 0 otherwise.
104+
*/
57105
static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
58106
{
59107
if (IS_ERR(ptr))

0 commit comments

Comments
 (0)