From patchwork Tue Sep 23 07:04:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Henningsson X-Patchwork-Id: 4953781 X-Patchwork-Delegate: tiwai@suse.de Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6F48EBEEA5 for ; Tue, 23 Sep 2014 07:05:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 443F4201C0 for ; Tue, 23 Sep 2014 07:05:22 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 48458201D3 for ; Tue, 23 Sep 2014 07:05:20 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id C5C62264FDF; Tue, 23 Sep 2014 09:05:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 8562F261B1A; Tue, 23 Sep 2014 09:05:03 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 87D49261B20; Tue, 23 Sep 2014 09:05:01 +0200 (CEST) Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by alsa0.perex.cz (Postfix) with ESMTP id AC0AF261B19 for ; Tue, 23 Sep 2014 09:04:54 +0200 (CEST) Received: from hd9483857.selulk5.dyn.perspektivbredband.net ([217.72.56.87] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1XWK9e-0001OH-8F; Tue, 23 Sep 2014 07:04:54 +0000 From: David Henningsson To: tiwai@suse.de, alsa-devel@alsa-project.org Date: Tue, 23 Sep 2014 09:04:50 +0200 Message-Id: <1411455890-8324-2-git-send-email-david.henningsson@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411455890-8324-1-git-send-email-david.henningsson@canonical.com> References: <1411455890-8324-1-git-send-email-david.henningsson@canonical.com> Cc: David Henningsson Subject: [alsa-devel] [PATCH] hda-emu: add include/linux/err.h X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP We recently started using it on the kernel side. Signed-off-by: David Henningsson --- include/linux/err.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/linux/err.h diff --git a/include/linux/err.h b/include/linux/err.h new file mode 100644 index 0000000..627729d --- /dev/null +++ b/include/linux/err.h @@ -0,0 +1,64 @@ +#ifndef _LINUX_ERR_H +#define _LINUX_ERR_H + +/* + * Kernel pointers have redundant information, so we can use a + * scheme where we can return either an error code or a normal + * pointer with the same return value. + * + * This should be a per-architecture thing, to allow different + * error and pointer decisions. + */ +#define MAX_ERRNO 4095 + +#define __must_check +#define __force +#define unlikely(x) x + +#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) + +static inline void * __must_check ERR_PTR(long error) +{ + return (void *) error; +} + +static inline long __must_check PTR_ERR(__force const void *ptr) +{ + return (long) ptr; +} + +static inline bool __must_check IS_ERR(__force const void *ptr) +{ + return IS_ERR_VALUE((unsigned long)ptr); +} + +static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr) +{ + return !ptr || IS_ERR_VALUE((unsigned long)ptr); +} + +/** + * 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; +} + +static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr) +{ + if (IS_ERR(ptr)) + return PTR_ERR(ptr); + else + return 0; +} + +/* Deprecated */ +#define PTR_RET(p) PTR_ERR_OR_ZERO(p) + +#endif /* _LINUX_ERR_H */