From: Russell King - ARM Linux <linux@arm.linux.org.uk> To: Nicolas Pitre <nicolas.pitre@linaro.org> Cc: Arnd Bergmann <arnd@arndb.de>, linux-arch@vger.kernel.org, Linus Walleij <linus.walleij@linaro.org>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, Grant Likely <grant.likely@secretlab.ca>, Alexandre Courbot <acourbot@nvidia.com>, Guenter Roeck <linux@roeck-us.net>, "devicetree-discuss@lists.ozlabs.org" <devicetree-discuss@lists.ozlabs.org>, "linux-arm-kernel@lists.infradead.org" <linux-arm-kernel@lists.infradead.org> Subject: [PATCH] Proposed removal of IS_ERR_OR_NULL() (was: Re: [PATCH 1/4] gpiolib: introduce descriptor-based GPIO interface) Date: Wed, 9 Jan 2013 15:04:28 +0000 [thread overview] Message-ID: <20130109150427.GL3931@n2100.arm.linux.org.uk> (raw) In-Reply-To: <alpine.LFD.2.02.1301090932400.6300@xanadu.home> 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 <rmk+kernel@arm.linux.org.uk> 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 <dhowells@redhat.com> Tape-measuring-service-offered-by: Will Deacon <will.deacon@arm.com> Victim-for-firing-sqad: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> --- 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); }
WARNING: multiple messages have this Message-ID (diff)
From: linux@arm.linux.org.uk (Russell King - ARM Linux) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] Proposed removal of IS_ERR_OR_NULL() (was: Re: [PATCH 1/4] gpiolib: introduce descriptor-based GPIO interface) Date: Wed, 9 Jan 2013 15:04:28 +0000 [thread overview] Message-ID: <20130109150427.GL3931@n2100.arm.linux.org.uk> (raw) In-Reply-To: <alpine.LFD.2.02.1301090932400.6300@xanadu.home> 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 <rmk+kernel@arm.linux.org.uk> 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 <dhowells@redhat.com> Tape-measuring-service-offered-by: Will Deacon <will.deacon@arm.com> Victim-for-firing-sqad: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> --- 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); }
next prev parent reply other threads:[~2013-01-09 15:04 UTC|newest] Thread overview: 121+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-01-08 7:18 [PATCH 0/4] gpio: introduce descriptor-based interface Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 7:18 ` [PATCH 1/4] gpiolib: introduce descriptor-based GPIO interface Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 12:59 ` Arnd Bergmann 2013-01-08 12:59 ` Arnd Bergmann 2013-01-09 1:06 ` Alexandre Courbot 2013-01-09 1:06 ` Alexandre Courbot 2013-01-09 1:06 ` Alexandre Courbot 2013-01-09 10:25 ` Russell King - ARM Linux 2013-01-09 10:25 ` Russell King - ARM Linux 2013-01-09 10:25 ` Russell King - ARM Linux 2013-01-09 10:35 ` Arnd Bergmann 2013-01-09 10:35 ` Arnd Bergmann 2013-01-09 10:35 ` Arnd Bergmann 2013-01-09 10:44 ` Russell King - ARM Linux 2013-01-09 10:44 ` Russell King - ARM Linux 2013-01-09 10:44 ` Russell King - ARM Linux 2013-01-09 11:10 ` Russell King - ARM Linux 2013-01-09 11:10 ` Russell King - ARM Linux 2013-01-09 11:10 ` Russell King - ARM Linux 2013-01-09 11:52 ` Arnd Bergmann 2013-01-09 11:52 ` Arnd Bergmann 2013-01-09 11:52 ` Arnd Bergmann 2013-01-09 11:52 ` Arnd Bergmann 2013-01-09 14:44 ` Nicolas Pitre 2013-01-09 14:44 ` Nicolas Pitre 2013-01-09 14:44 ` Nicolas Pitre 2013-01-09 15:04 ` Russell King - ARM Linux [this message] 2013-01-09 15:04 ` [PATCH] Proposed removal of IS_ERR_OR_NULL() (was: Re: [PATCH 1/4] gpiolib: introduce descriptor-based GPIO interface) Russell King - ARM Linux 2013-01-09 15:04 ` Russell King - ARM Linux 2013-01-09 15:21 ` Grant Likely 2013-01-09 15:21 ` Grant Likely 2013-01-09 15:21 ` Grant Likely 2013-01-09 15:21 ` Grant Likely 2013-01-09 15:26 ` Arnd Bergmann 2013-01-09 15:26 ` Arnd Bergmann 2013-01-09 15:26 ` Arnd Bergmann 2013-01-09 15:27 ` Nicolas Pitre 2013-01-09 15:27 ` Nicolas Pitre 2013-01-09 15:27 ` Nicolas Pitre 2013-01-09 15:51 ` Russell King - ARM Linux 2013-01-09 15:51 ` Russell King - ARM Linux 2013-01-09 15:51 ` Russell King - ARM Linux 2013-01-09 16:09 ` Nicolas Pitre 2013-01-09 16:09 ` Nicolas Pitre 2013-01-09 16:09 ` Nicolas Pitre 2013-01-09 16:21 ` Russell King - ARM Linux 2013-01-09 16:21 ` Russell King - ARM Linux 2013-01-09 16:21 ` Russell King - ARM Linux 2013-01-09 17:12 ` Russell King - ARM Linux 2013-01-09 17:12 ` Russell King - ARM Linux 2013-01-09 17:12 ` Russell King - ARM Linux 2013-01-09 17:52 ` Tony Lindgren 2013-01-09 17:52 ` Tony Lindgren 2013-01-09 17:52 ` Tony Lindgren 2013-01-17 10:28 ` Linus Walleij 2013-01-17 10:28 ` Linus Walleij 2013-01-17 10:28 ` Linus Walleij 2013-01-10 8:36 ` [PATCH 1/4] gpiolib: introduce descriptor-based GPIO interface Thierry Reding 2013-01-10 8:36 ` Thierry Reding 2013-01-10 8:36 ` Thierry Reding 2013-01-08 7:18 ` [PATCH 2/4] gpiolib: add gpiod_get and gpiod_put functions Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 13:07 ` Arnd Bergmann 2013-01-08 13:07 ` Arnd Bergmann 2013-01-09 1:49 ` Alexandre Courbot 2013-01-09 1:49 ` Alexandre Courbot 2013-01-09 1:49 ` Alexandre Courbot 2013-01-08 7:18 ` [PATCH 3/4] gpiolib: of: convert OF helpers to descriptor API Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 7:18 ` [PATCH 4/4] gpiolib: add documentation for new gpiod_ API Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 7:18 ` Alexandre Courbot 2013-01-08 13:06 ` [PATCH 0/4] gpio: introduce descriptor-based interface Arnd Bergmann 2013-01-08 13:06 ` Arnd Bergmann 2013-01-09 1:48 ` Alexandre Courbot 2013-01-09 1:48 ` Alexandre Courbot 2013-01-09 1:48 ` Alexandre Courbot 2013-01-09 10:46 ` Arnd Bergmann 2013-01-09 10:46 ` Arnd Bergmann 2013-01-09 10:46 ` Arnd Bergmann 2013-01-10 4:07 ` Alex Courbot 2013-01-10 4:07 ` Alex Courbot 2013-01-10 4:07 ` Alex Courbot 2013-01-10 10:08 ` Arnd Bergmann 2013-01-10 10:08 ` Arnd Bergmann 2013-01-10 10:08 ` Arnd Bergmann 2013-01-14 10:21 ` Alex Courbot 2013-01-14 10:21 ` Alex Courbot 2013-01-14 10:21 ` Alex Courbot 2013-01-14 10:46 ` Arnd Bergmann 2013-01-14 10:46 ` Arnd Bergmann 2013-01-14 10:46 ` Arnd Bergmann 2013-01-14 10:21 ` Alex Courbot 2013-01-17 11:15 ` Linus Walleij 2013-01-17 11:15 ` Linus Walleij 2013-01-17 11:15 ` Linus Walleij 2013-01-17 12:02 ` Greg Ungerer 2013-01-17 12:02 ` Greg Ungerer 2013-01-17 12:02 ` Greg Ungerer 2013-01-17 16:50 ` Steven King 2013-01-17 16:50 ` Steven King 2013-01-17 16:50 ` Steven King 2013-01-17 16:50 ` Steven King 2013-01-17 19:22 ` Arnd Bergmann 2013-01-17 19:22 ` Arnd Bergmann 2013-01-17 19:22 ` Arnd Bergmann 2013-01-20 6:07 ` Alex Courbot 2013-01-20 6:07 ` Alex Courbot 2013-01-20 6:07 ` Alex Courbot 2013-01-22 8:55 ` Linus Walleij 2013-01-22 8:55 ` Linus Walleij 2013-01-22 8:55 ` Linus Walleij 2013-01-17 11:25 ` Linus Walleij 2013-01-17 11:25 ` Linus Walleij 2013-01-17 11:25 ` Linus Walleij
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20130109150427.GL3931@n2100.arm.linux.org.uk \ --to=linux@arm.linux.org.uk \ --cc=acourbot@nvidia.com \ --cc=arnd@arndb.de \ --cc=devicetree-discuss@lists.ozlabs.org \ --cc=grant.likely@secretlab.ca \ --cc=linus.walleij@linaro.org \ --cc=linux-arch@vger.kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux@roeck-us.net \ --cc=nicolas.pitre@linaro.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.