Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Add an ERR_CAST() function to complement ERR_PTR and co.

Add an ERR_CAST() function to complement ERR_PTR and co. for the purposes
of casting an error entyped as one pointer type to an error of another
pointer type whilst making it explicit as to what is going on.

This provides a replacement for the ERR_PTR(PTR_ERR(p)) construct.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Howells and committed by
Linus Torvalds
d1bc8e95 ae5e2979

+13
+13
include/linux/err.h
··· 34 34 return IS_ERR_VALUE((unsigned long)ptr); 35 35 } 36 36 37 + /** 38 + * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type 39 + * @ptr: The pointer to cast. 40 + * 41 + * Explicitly cast an error-valued pointer to another pointer type in such a 42 + * way as to make it clear that's what's going on. 43 + */ 44 + static inline void *ERR_CAST(const void *ptr) 45 + { 46 + /* cast away the const */ 47 + return (void *) ptr; 48 + } 49 + 37 50 #endif 38 51 39 52 #endif /* _LINUX_ERR_H */