From patchwork Wed Jan 9 15:04:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King - ARM Linux X-Patchwork-Id: 1953271 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 5AB953FC5A for ; Wed, 9 Jan 2013 15:09:15 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TsxDK-0003wm-1b; Wed, 09 Jan 2013 15:05:10 +0000 Received: from [2002:4e20:1eda::1] (helo=caramon.arm.linux.org.uk) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TsxDC-0003t3-AZ for linux-arm-kernel@lists.infradead.org; Wed, 09 Jan 2013 15:05:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=caramon; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=XIrAdW2OpCm3TDWDWd8ghoFrsFt299KsSujikABbHWM=; b=oYcfcW6Vg4ZY0AUodkZ+hJYhI/Xo5mnztBtP0GjnjPGqO82Aue05EhNqzdyaDs0Cd0DeFeKWOTdOg0PTSEUhzkCOeDhU8EXWnZ3UixLLJW7+TWyM/UQ5/NGTYi4z7+CSh1nhbXngleYQfluejN/8dfxMTG7NbM8GvTLrfVwlwEQ=; Received: from n2100.arm.linux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]:41868) by caramon.arm.linux.org.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1TsxCf-00010Y-KO; Wed, 09 Jan 2013 15:04:30 +0000 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1TsxCe-0006md-Dv; Wed, 09 Jan 2013 15:04:28 +0000 Date: Wed, 9 Jan 2013 15:04:28 +0000 From: Russell King - ARM Linux To: Nicolas Pitre Subject: [PATCH] Proposed removal of IS_ERR_OR_NULL() (was: Re: [PATCH 1/4] gpiolib: introduce descriptor-based GPIO interface) Message-ID: <20130109150427.GL3931@n2100.arm.linux.org.uk> References: <1357629535-26033-1-git-send-email-acourbot@nvidia.com> <201301081259.29839.arnd@arndb.de> <201301091035.23206.arnd@arndb.de> <20130109104414.GF3931@n2100.arm.linux.org.uk> <20130109111055.GG3931@n2100.arm.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130109_100503_677667_76B9BF15 X-CRM114-Status: GOOD ( 21.78 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS Cc: linux-arch@vger.kernel.org, Arnd Bergmann , Linus Walleij , Linux Kernel Mailing List , Grant Likely , Alexandre Courbot , "linux-arm-kernel@lists.infradead.org" , "devicetree-discuss@lists.ozlabs.org" , Guenter Roeck X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org So, it seems there's some concensus building here, and it seems that I've become the chosen victi^wvolunteer for this. So, here's a patch. It's missing a Guns-supplied-by: tag though. From: Russell King Subject: Mark IS_ERR_OR_NULL() deprecated IS_ERR_OR_NULL() attracts a lot of abuse: people use it without much thought about it's effects. Common errors include: 1. checking the returned pointer for functions defined as only returning errno-pointer values, rather than using IS_ERR(). This leads to: ptr = foo(); if (IS_ERR_OR_NULL(ptr)) return PTR_ERR(ptr); 2. using it to check functions which only ever return NULL on error, thereby leading to another zero-error value return. In the case of debugfs functions, these return errno-pointer values when debugfs is configured out, which means code which blindly checks using IS_ERR_OR_NULL() ends up returning errors, which is rather perverse for something that's not implemented. Therefore, let's schedule it for removal in a few releases. Nicolas Pitre comments: > I do agree with Russell here. Despite the original intentions behind > IS_ERR_OR_NULL() which were certainly legitimate, the end result in > practice is less reliable code with increased maintenance costs. > Unlike other convenience macros in the kernel, this one is giving a > false sense of correctness with too many people falling in the trap > of using it just because it is available. > > I strongly think this macro should simply be removed from the source > tree entirely and the code reverted to explicit tests against NULL > when appropriate. Suggested-by: David Howells Tape-measuring-service-offered-by: Will Deacon Victim-for-firing-sqad: Russell King Signed-off-by: Russell King Acked-by: Grant Likely Acked-by: Arnd Bergmann Acked-by: Nicolas Pitre Acked-by: Linus Walleij --- Ok, so I'm in the firing line for suggesting this, but it appears several people wish this to happen. I'm not intending to push this patch forwards _just_ yet: we need to sort out the existing users _first_ to prevent the kernel turning into one hell of a mess of warnings. include/linux/err.h | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/include/linux/err.h b/include/linux/err.h index f2edce2..d5a85df 100644 --- a/include/linux/err.h +++ b/include/linux/err.h @@ -34,7 +34,22 @@ static inline long __must_check IS_ERR(const void *ptr) return IS_ERR_VALUE((unsigned long)ptr); } -static inline long __must_check IS_ERR_OR_NULL(const void *ptr) +/* + * IS_ERR_OR_NULL() attracts a lot of abuse: people use it without much + * thought about it's effects. Common errors include: + * 1. checking the returned pointer for functions defined as only returning + * errno-pointer values, rather than using IS_ERR(). + * This leads to: ptr = foo(); if (IS_ERR_OR_NULL(ptr)) return PTR_ERR(ptr); + * 2. using it to check functions which only ever return NULL on error, + * thereby leading to another zero-error value return. + * In the case of debugfs functions, these return errno-pointer values when + * debugfs is configured out, which means code which blindly checks using + * IS_ERR_OR_NULL() ends up returning errors, which is rather perverse for + * something that's not implemented. + * + * Therefore, let's schedule it for removal in a few releases. + */ +static inline long __must_check __deprecated IS_ERR_OR_NULL(const void *ptr) { return !ptr || IS_ERR_VALUE((unsigned long)ptr); }