All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN
@ 2019-02-02 16:06 Masahiro Yamada
  2019-02-02 16:06 ` [PATCH 2/2] linux/kernel.h: split *_MAX and *_MIN macros into <linux/limits.h> Masahiro Yamada
  2019-02-02 16:31 ` [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN Alexey Dobriyan
  0 siblings, 2 replies; 5+ messages in thread
From: Masahiro Yamada @ 2019-02-02 16:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Masahiro Yamada, Alexey Dobriyan, Zhang Yanmin, linux-kernel

The log of commit 44f564a4bf6a ("ipc: add definitions of USHORT_MAX
and others") did not explain why it used (s16) and (u16) instead of
(short) and (unsigned short).

Let's use (short) and (unsigned short), which is more sensible, and
more consistent with the other MAX/MIN defines.

As you see in include/uapi/asm-generic/int-ll64.h, s16/u16 are
typedef'ed as signed/unsigned short. So, this commit does not have
a functional change.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Zhang Yanmin <yanmin.zhang@intel.com>
---

 include/linux/kernel.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 8f0e68e..110bac1 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -16,9 +16,9 @@
 #include <asm/byteorder.h>
 #include <uapi/linux/kernel.h>
 
-#define USHRT_MAX	((u16)(~0U))
-#define SHRT_MAX	((s16)(USHRT_MAX>>1))
-#define SHRT_MIN	((s16)(-SHRT_MAX - 1))
+#define USHRT_MAX	((unsigned short)(~0U))
+#define SHRT_MAX	((short)(USHRT_MAX>>1))
+#define SHRT_MIN	((short)(-SHRT_MAX - 1))
 #define INT_MAX		((int)(~0U>>1))
 #define INT_MIN		(-INT_MAX - 1)
 #define UINT_MAX	(~0U)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] linux/kernel.h: split *_MAX and *_MIN macros into <linux/limits.h>
  2019-02-02 16:06 [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN Masahiro Yamada
@ 2019-02-02 16:06 ` Masahiro Yamada
  2019-02-02 16:31 ` [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN Alexey Dobriyan
  1 sibling, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2019-02-02 16:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Masahiro Yamada, Alex Elder, Alexey Dobriyan, Zhang Yanmin, linux-kernel

<linux/kernel.h> tends to be cluttered because we often put various
sort of unrelated stuff in it. So, we have split out a sensible chunk
of code into a separate header from time to time.

This commit splits out the *_MAX and *_MIN defines.

The standard header <limits.h> contains various MAX, MIN constants
including numerial limits. [1]

So, I think it makes sense to move in-kernel MAX, MIN constants into
include/linux/limits.h.

We already have include/uapi/linux/limits.h to contain some user-space
constants. I changed its include guard to _UAPI_LINUX_LIMITS_H. This
change has no impact to the user-space because scripts/headers_install.sh
rips off the '_UAPI' prefix from the include guards of exported headers.

[1] http://pubs.opengroup.org/onlinepubs/009604499/basedefs/limits.h.html

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Alex Elder <elder@linaro.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Zhang Yanmin <yanmin.zhang@intel.com>
---

 include/linux/kernel.h      | 29 +----------------------------
 include/linux/limits.h      | 36 ++++++++++++++++++++++++++++++++++++
 include/uapi/linux/limits.h |  4 ++--
 3 files changed, 39 insertions(+), 30 deletions(-)
 create mode 100644 include/linux/limits.h

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 110bac1..b80b965 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -4,6 +4,7 @@
 
 
 #include <stdarg.h>
+#include <linux/limits.h>
 #include <linux/linkage.h>
 #include <linux/stddef.h>
 #include <linux/types.h>
@@ -16,34 +17,6 @@
 #include <asm/byteorder.h>
 #include <uapi/linux/kernel.h>
 
-#define USHRT_MAX	((unsigned short)(~0U))
-#define SHRT_MAX	((short)(USHRT_MAX>>1))
-#define SHRT_MIN	((short)(-SHRT_MAX - 1))
-#define INT_MAX		((int)(~0U>>1))
-#define INT_MIN		(-INT_MAX - 1)
-#define UINT_MAX	(~0U)
-#define LONG_MAX	((long)(~0UL>>1))
-#define LONG_MIN	(-LONG_MAX - 1)
-#define ULONG_MAX	(~0UL)
-#define LLONG_MAX	((long long)(~0ULL>>1))
-#define LLONG_MIN	(-LLONG_MAX - 1)
-#define ULLONG_MAX	(~0ULL)
-#define SIZE_MAX	(~(size_t)0)
-#define PHYS_ADDR_MAX	(~(phys_addr_t)0)
-
-#define U8_MAX		((u8)~0U)
-#define S8_MAX		((s8)(U8_MAX>>1))
-#define S8_MIN		((s8)(-S8_MAX - 1))
-#define U16_MAX		((u16)~0U)
-#define S16_MAX		((s16)(U16_MAX>>1))
-#define S16_MIN		((s16)(-S16_MAX - 1))
-#define U32_MAX		((u32)~0U)
-#define S32_MAX		((s32)(U32_MAX>>1))
-#define S32_MIN		((s32)(-S32_MAX - 1))
-#define U64_MAX		((u64)~0ULL)
-#define S64_MAX		((s64)(U64_MAX>>1))
-#define S64_MIN		((s64)(-S64_MAX - 1))
-
 #define STACK_MAGIC	0xdeadbeef
 
 /**
diff --git a/include/linux/limits.h b/include/linux/limits.h
new file mode 100644
index 0000000..01aeb53
--- /dev/null
+++ b/include/linux/limits.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_LIMITS_H
+#define _LINUX_LIMITS_H
+
+#include <uapi/linux/limits.h>
+#include <linux/types.h>
+
+#define USHRT_MAX	((unsigned short)(~0U))
+#define SHRT_MAX	((short)(USHRT_MAX >> 1))
+#define SHRT_MIN	((short)(-SHRT_MAX - 1))
+#define INT_MAX		((int)(~0U >> 1))
+#define INT_MIN		(-INT_MAX - 1)
+#define UINT_MAX	(~0U)
+#define LONG_MAX	((long)(~0UL >> 1))
+#define LONG_MIN	(-LONG_MAX - 1)
+#define ULONG_MAX	(~0UL)
+#define LLONG_MAX	((long long)(~0ULL >> 1))
+#define LLONG_MIN	(-LLONG_MAX - 1)
+#define ULLONG_MAX	(~0ULL)
+#define SIZE_MAX	(~(size_t)0)
+#define PHYS_ADDR_MAX	(~(phys_addr_t)0)
+
+#define U8_MAX		((u8)~0U)
+#define S8_MAX		((s8)(U8_MAX >> 1))
+#define S8_MIN		((s8)(-S8_MAX - 1))
+#define U16_MAX		((u16)~0U)
+#define S16_MAX		((s16)(U16_MAX >> 1))
+#define S16_MIN		((s16)(-S16_MAX - 1))
+#define U32_MAX		((u32)~0U)
+#define S32_MAX		((s32)(U32_MAX >> 1))
+#define S32_MIN		((s32)(-S32_MAX - 1))
+#define U64_MAX		((u64)~0ULL)
+#define S64_MAX		((s64)(U64_MAX >> 1))
+#define S64_MIN		((s64)(-S64_MAX - 1))
+
+#endif /* _LINUX_LIMITS_H */
diff --git a/include/uapi/linux/limits.h b/include/uapi/linux/limits.h
index c3547f0..6bcbe30 100644
--- a/include/uapi/linux/limits.h
+++ b/include/uapi/linux/limits.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_LIMITS_H
-#define _LINUX_LIMITS_H
+#ifndef _UAPI_LINUX_LIMITS_H
+#define _UAPI_LINUX_LIMITS_H
 
 #define NR_OPEN	        1024
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN
  2019-02-02 16:06 [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN Masahiro Yamada
  2019-02-02 16:06 ` [PATCH 2/2] linux/kernel.h: split *_MAX and *_MIN macros into <linux/limits.h> Masahiro Yamada
@ 2019-02-02 16:31 ` Alexey Dobriyan
  2019-02-02 16:36   ` Alexey Dobriyan
  2019-02-03  1:09   ` Masahiro Yamada
  1 sibling, 2 replies; 5+ messages in thread
From: Alexey Dobriyan @ 2019-02-02 16:31 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Andrew Morton, Zhang Yanmin, linux-kernel

On Sun, Feb 03, 2019 at 01:06:24AM +0900, Masahiro Yamada wrote:
> The log of commit 44f564a4bf6a ("ipc: add definitions of USHORT_MAX
> and others") did not explain why it used (s16) and (u16) instead of
> (short) and (unsigned short).
> 
> Let's use (short) and (unsigned short), which is more sensible, and
> more consistent with the other MAX/MIN defines.
> 
> As you see in include/uapi/asm-generic/int-ll64.h, s16/u16 are
> typedef'ed as signed/unsigned short. So, this commit does not have
> a functional change.

> -#define USHRT_MAX	((u16)(~0U))
> -#define SHRT_MAX	((s16)(USHRT_MAX>>1))
> -#define SHRT_MIN	((s16)(-SHRT_MAX - 1))
> +#define USHRT_MAX	((unsigned short)(~0U))
					 ^   ^
					 +---+
					   unnecessary ()
> +#define SHRT_MAX	((short)(USHRT_MAX>>1))
> +#define SHRT_MIN	((short)(-SHRT_MAX - 1))

"short" and "unsigned short" are probably the most useless C types.
I doubt their usage should be promoted.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN
  2019-02-02 16:31 ` [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN Alexey Dobriyan
@ 2019-02-02 16:36   ` Alexey Dobriyan
  2019-02-03  1:09   ` Masahiro Yamada
  1 sibling, 0 replies; 5+ messages in thread
From: Alexey Dobriyan @ 2019-02-02 16:36 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Andrew Morton, Zhang Yanmin, linux-kernel

On Sat, Feb 02, 2019 at 07:31:05PM +0300, Alexey Dobriyan wrote:
> On Sun, Feb 03, 2019 at 01:06:24AM +0900, Masahiro Yamada wrote:
> > The log of commit 44f564a4bf6a ("ipc: add definitions of USHORT_MAX
> > and others") did not explain why it used (s16) and (u16) instead of
> > (short) and (unsigned short).
> > 
> > Let's use (short) and (unsigned short), which is more sensible, and
> > more consistent with the other MAX/MIN defines.
> > 
> > As you see in include/uapi/asm-generic/int-ll64.h, s16/u16 are
> > typedef'ed as signed/unsigned short. So, this commit does not have
> > a functional change.
> 
> > -#define USHRT_MAX	((u16)(~0U))
> > -#define SHRT_MAX	((s16)(USHRT_MAX>>1))
> > -#define SHRT_MIN	((s16)(-SHRT_MAX - 1))
> > +#define USHRT_MAX	((unsigned short)(~0U))
> 					 ^   ^
> 					 +---+
> 					   unnecessary ()
> > +#define SHRT_MAX	((short)(USHRT_MAX>>1))
> > +#define SHRT_MIN	((short)(-SHRT_MAX - 1))
> 
> "short" and "unsigned short" are probably the most useless C types.
> I doubt their usage should be promoted.

OTOH, U16_MAX etc exist and cast to u16, so using "short" would be
the right thing to do.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN
  2019-02-02 16:31 ` [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN Alexey Dobriyan
  2019-02-02 16:36   ` Alexey Dobriyan
@ 2019-02-03  1:09   ` Masahiro Yamada
  1 sibling, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2019-02-03  1:09 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: Andrew Morton, Zhang Yanmin, Linux Kernel Mailing List

On Sun, Feb 3, 2019 at 1:33 AM Alexey Dobriyan <adobriyan@gmail.com> wrote:
>
> On Sun, Feb 03, 2019 at 01:06:24AM +0900, Masahiro Yamada wrote:
> > The log of commit 44f564a4bf6a ("ipc: add definitions of USHORT_MAX
> > and others") did not explain why it used (s16) and (u16) instead of
> > (short) and (unsigned short).
> >
> > Let's use (short) and (unsigned short), which is more sensible, and
> > more consistent with the other MAX/MIN defines.
> >
> > As you see in include/uapi/asm-generic/int-ll64.h, s16/u16 are
> > typedef'ed as signed/unsigned short. So, this commit does not have
> > a functional change.
>
> > -#define USHRT_MAX    ((u16)(~0U))
> > -#define SHRT_MAX     ((s16)(USHRT_MAX>>1))
> > -#define SHRT_MIN     ((s16)(-SHRT_MAX - 1))
> > +#define USHRT_MAX    ((unsigned short)(~0U))
>                                          ^   ^
>                                          +---+
>                                            unnecessary ()


Thanks, I will remove it in v2.




> > +#define SHRT_MAX     ((short)(USHRT_MAX>>1))
> > +#define SHRT_MIN     ((short)(-SHRT_MAX - 1))
>
> "short" and "unsigned short" are probably the most useless C types.
> I doubt their usage should be promoted.



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-03  1:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-02 16:06 [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN Masahiro Yamada
2019-02-02 16:06 ` [PATCH 2/2] linux/kernel.h: split *_MAX and *_MIN macros into <linux/limits.h> Masahiro Yamada
2019-02-02 16:31 ` [PATCH 1/2] linux/kernel.h: use 'short' to define USHRT_MAX, SHRT_MAX, SHRT_MIN Alexey Dobriyan
2019-02-02 16:36   ` Alexey Dobriyan
2019-02-03  1:09   ` Masahiro Yamada

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.