Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1323822
| From | Andrew Morton <akpm@linux-foundation.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v2] err.h: allow IS_ERR_VALUE to handle properly more types |
| Date | 2016-02-02 07:30 +0100 |
| Message-ID | <qXCDp-6Jl-23@gated-at.bofh.it> (permalink) |
| References | <qOl8K-1I5-19@gated-at.bofh.it> <qVQ7O-FX-53@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu, 28 Jan 2016 09:27:28 +0100 Andrzej Hajda <a.hajda@samsung.com> wrote: > Current implementation of IS_ERR_VALUE works correctly only with > following types: > - unsigned long, > - short, int, long. > Other types are handled incorrectly either on 32-bit either on 64-bit > either on both architectures. > The patch fixes it by comparing argument with MAX_ERRNO casted > to argument's type for unsigned types and comparing with zero for signed > types. As a result all integer types bigger than char are handled properly. > > I have analyzed usage of IS_ERR_VALUE using coccinelle and in about 35 > cases it is used incorrectly, ie it can hide errors depending of 32/64 bit > architecture. Instead of fixing usage I propose to enhance the macro > to cover more types. > And just for the record: the macro is used 101 times with signed variables, > I am not sure if it should be preferred over simple comparison "ret < 0", > but the new version can do it as well. > > And below list of detected potential errors: > > ... > > --- a/include/linux/err.h > +++ b/include/linux/err.h > @@ -18,7 +18,9 @@ > > #ifndef __ASSEMBLY__ > > -#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) > +#define IS_ERR_VALUE(x) ((typeof(x))(-1) <= 0 \ > + ? unlikely((x) < 0) \ > + : unlikely((x) >= (typeof(x))-MAX_ERRNO)) > hm, seems complicated. Can we simply cast the value to long? #define IS_ERR_VALUE(x) ((long)x < 0) && (long)x >= (long)-MAX_ERRNO) and simplify that to #define IS_ERR_VALUE(x) ((unsigned long)(long)x >= (unsigned long)-MAX_ERRNO) or something like that.
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2] err.h: allow IS_ERR_VALUE to handle properly more types Andrzej Hajda <a.hajda@samsung.com> - 2016-01-28 09:30 +0100
Re: [PATCH v2] err.h: allow IS_ERR_VALUE to handle properly more types Andrew Morton <akpm@linux-foundation.org> - 2016-02-02 07:30 +0100
Re: [PATCH v2] err.h: allow IS_ERR_VALUE to handle properly more types Andrzej Hajda <a.hajda@samsung.com> - 2016-02-02 09:30 +0100
Re: [PATCH v2] err.h: allow IS_ERR_VALUE to handle properly more types Andrew Morton <akpm@linux-foundation.org> - 2016-02-03 01:40 +0100
Re: [PATCH v2] err.h: allow IS_ERR_VALUE to handle properly more types Andrzej Hajda <a.hajda@samsung.com> - 2016-02-03 12:00 +0100
[PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Andrzej Hajda <a.hajda@samsung.com> - 2016-02-03 14:20 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Arnd Bergmann <arnd@arndb.de> - 2016-02-04 13:50 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Andrzej Hajda <a.hajda@samsung.com> - 2016-02-04 15:50 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Arnd Bergmann <arnd@arndb.de> - 2016-02-04 16:10 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Arnd Bergmann <arnd@arndb.de> - 2016-02-04 16:20 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Andrew Morton <akpm@linux-foundation.org> - 2016-02-04 20:00 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Arnd Bergmann <arnd@arndb.de> - 2016-02-05 12:00 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Andrzej Hajda <a.hajda@samsung.com> - 2016-02-08 09:50 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Arnd Bergmann <arnd@arndb.de> - 2016-02-08 13:10 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Al Viro <viro@ZenIV.linux.org.uk> - 2016-02-09 02:50 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Andrzej Hajda <a.hajda@samsung.com> - 2016-02-09 09:50 +0100
Re: [PATCH v3] err.h: allow IS_ERR_VALUE to handle properly more types Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-02-05 00:40 +0100
csiph-web