From: Uwe Kleine-König Date: Tue, 22 Mar 2011 23:34:05 +0000 (-0700) Subject: include/linux/err.h: add a function to cast error-pointers to a return value X-Git-Tag: Ubuntu-5.13.0-19.19~28191 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=fa9ee9c4b9885dfdf8eccac19b8b4fc8a7c53288;p=mirror_ubuntu-jammy-kernel.git include/linux/err.h: add a function to cast error-pointers to a return value PTR_RET() can be used if you have an error-pointer and are only interested in the eventual error value, but not the pointer. Yields the usual 0 for no error, -ESOMETHING otherwise. Signed-off-by: Uwe Kleine-König Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/include/linux/err.h b/include/linux/err.h index 448afc12c78a..f2edce25a76b 100644 --- a/include/linux/err.h +++ b/include/linux/err.h @@ -52,6 +52,14 @@ static inline void * __must_check ERR_CAST(const void *ptr) return (void *) ptr; } +static inline int __must_check PTR_RET(const void *ptr) +{ + if (IS_ERR(ptr)) + return PTR_ERR(ptr); + else + return 0; +} + #endif #endif /* _LINUX_ERR_H */