Skip to content

Commit d1bc8e9

Browse files
dhowellsLinus Torvalds
authored andcommitted
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>
1 parent ae5e297 commit d1bc8e9

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎include/linux/err.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ static inline long IS_ERR(const void *ptr)
3434
return IS_ERR_VALUE((unsigned long)ptr);
3535
}
3636

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+
3750
#endif
3851

3952
#endif /* _LINUX_ERR_H */

0 commit comments

Comments
 (0)