Skip to content

Commit 92151b0

Browse files
committed
tools include: Adopt ERR_CAST() from the kernel err.h header
Add ERR_CAST(), so that tools can use it, just like the kernel. This addresses coccinelle checks that are being performed to tools/ in addition to kernel sources, so lets add this to cover that and to get tools code closer to kernel coding standards. This originally was introduced in the kernel headers in this cset: d1bc8e9 ("Add an ERR_CAST() function to complement ERR_PTR and co.") Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: David Ahern <[email protected]> Cc: David Howells <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Julia Lawall <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Wang Nan <[email protected]> Cc: Wen Yang <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 741dad8 commit 92151b0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/include/linux/err.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,17 @@ static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
5959
else
6060
return 0;
6161
}
62+
63+
/**
64+
* ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
65+
* @ptr: The pointer to cast.
66+
*
67+
* Explicitly cast an error-valued pointer to another pointer type in such a
68+
* way as to make it clear that's what's going on.
69+
*/
70+
static inline void * __must_check ERR_CAST(__force const void *ptr)
71+
{
72+
/* cast away the const */
73+
return (void *) ptr;
74+
}
6275
#endif /* _LINUX_ERR_H */

0 commit comments

Comments
 (0)