tools include: Adopt ERR_CAST() from the kernel err.h header
authorArnaldo Carvalho de Melo <[email protected]>
Tue, 27 Nov 2018 12:56:55 +0000 (09:56 -0300)
committerArnaldo Carvalho de Melo <[email protected]>
Mon, 17 Dec 2018 17:54:34 +0000 (14:54 -0300)
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:

  d1bc8e954452 ("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]>
tools/include/linux/err.h

index 094649667baeea69f88df5f19d9927acc7ad583d..2f5a12b88a86c34b81913d29ffb07445d135a12f 100644 (file)
@@ -59,4 +59,17 @@ static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
        else
                return 0;
 }
+
+/**
+ * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
+ * @ptr: The pointer to cast.
+ *
+ * Explicitly cast an error-valued pointer to another pointer type in such a
+ * way as to make it clear that's what's going on.
+ */
+static inline void * __must_check ERR_CAST(__force const void *ptr)
+{
+       /* cast away the const */
+       return (void *) ptr;
+}
 #endif /* _LINUX_ERR_H */