diff mbox

[ethtool,2/2] Use htobe64, htobe16 from libc instead of local byteswap code

Message ID 1396494376-6521-2-git-send-email-crrodriguez@opensuse.org
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Cristian Rodríguez April 3, 2014, 3:06 a.m. UTC
They are implemented in <endian.h> which is already included
in internal.h, no need to reinvent them with different names.

Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
---
 ethtool.c  |  2 +-
 internal.h | 31 -------------------------------
 rxclass.c  |  4 ++--
 3 files changed, 3 insertions(+), 34 deletions(-)

Comments

Ben Hutchings April 21, 2014, 9:18 p.m. UTC | #1
On Thu, 2014-04-03 at 00:06 -0300, Cristian Rodríguez wrote:
> They are implemented in <endian.h> which is already included
> in internal.h, no need to reinvent them with different names.
> 
> Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
[...]

According to the manual page, "These functions were added to glibc in
version 2.9."

Which is quite old now, but newer than several supported distributions
(e.g. RHEL 5).  So we would need an autoconf test and fallback
definition, at which point there doesn't seem to be any benefit.

Ben.
Ben Hutchings April 21, 2014, 9:18 p.m. UTC | #2
On Thu, 2014-04-03 at 00:06 -0300, Cristian Rodríguez wrote:
> They are implemented in <endian.h> which is already included
> in internal.h, no need to reinvent them with different names.
> 
> Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
[...]

According to the manual page, "These functions were added to glibc in
version 2.9."

Which is quite old now, but newer than several supported distributions
(e.g. RHEL 5).  So we would need an autoconf test and fallback
definition, at which point there doesn't seem to be any benefit.

Ben.
diff mbox

Patch

diff --git a/ethtool.c b/ethtool.c
index acb4397..e47ce0b 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -368,7 +368,7 @@  static void parse_generic_cmdline(struct cmd_context *ctx,
 				}
 				case CMDL_BE16: {
 					u16 *p = info[idx].wanted_val;
-					*p = cpu_to_be16(
+					*p = htobe16(
 						get_uint_range(argp[i], 0,
 							       0xffff));
 					break;
diff --git a/internal.h b/internal.h
index 86a64f2..7e7266b 100644
--- a/internal.h
+++ b/internal.h
@@ -31,37 +31,6 @@  typedef __int32_t s32;
 #include "ethtool-copy.h"
 #include "net_tstamp-copy.h"
 
-#if __BYTE_ORDER == __BIG_ENDIAN
-static inline u16 cpu_to_be16(u16 value)
-{
-	return value;
-}
-static inline u32 cpu_to_be32(u32 value)
-{
-	return value;
-}
-static inline u64 cpu_to_be64(u64 value)
-{
-	return value;
-}
-#else
-static inline u16 cpu_to_be16(u16 value)
-{
-	return (value >> 8) | (value << 8);
-}
-static inline u32 cpu_to_be32(u32 value)
-{
-	return cpu_to_be16(value >> 16) | (cpu_to_be16(value) << 16);
-}
-static inline u64 cpu_to_be64(u64 value)
-{
-	return cpu_to_be32(value >> 32) | ((u64)cpu_to_be32(value) << 32);
-}
-#endif
-
-#define ntohll cpu_to_be64
-#define htonll cpu_to_be64
-
 #define BITS_PER_BYTE		8
 #define BITS_PER_LONG		(BITS_PER_BYTE * sizeof(long))
 #define DIV_ROUND_UP(n, d)	(((n) + (d) - 1) / (d))
diff --git a/rxclass.c b/rxclass.c
index cd686a3..a013e06 100644
--- a/rxclass.c
+++ b/rxclass.c
@@ -836,7 +836,7 @@  static int rxclass_get_val(char *str, unsigned char *p, u32 *flags,
 		err = rxclass_get_ulong(str, &val, 64);
 		if (err)
 			return -1;
-		*(__be64 *)&p[opt->offset] = htonll((u64)val);
+		*(__be64 *)&p[opt->offset] = htobe64((u64)val);
 		if (opt->moffset >= 0)
 			*(__be64 *)&p[opt->moffset] = (__be64)mask;
 		break;
@@ -939,7 +939,7 @@  static int rxclass_get_mask(char *str, unsigned char *p,
 		err = rxclass_get_ulong(str, &val, 64);
 		if (err)
 			return -1;
-		*(__be64 *)&p[opt->moffset] = ~htonll((u64)val);
+		*(__be64 *)&p[opt->moffset] = ~htobe64((u64)val);
 		break;
 	}
 	case OPT_IP4: {