Skip to contentSkip to conversation

kmod: be32toh for older boxen

PATCH New Randy MacLeod 2 participants 4 messages Sep 6, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kmod: be32toh for older boxen

The attached patch fixes kmod when built on RHEL-5.9. I need to do this for a yocto cross-compile. I've also built on Ubuntu-12.04.

No run-time testing as the change seems simple enough.

Let me now if any changes are needed since this is my first patch to kmod.

Thanks,

// Randy

Randy MacLeod (1):
kmod-native: Add back-up implementation of be32toh().

 configure.ac                |  1 +
 libkmod/libkmod-signature.c | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH 1/1 kmod-native: Add back-up implementation of be32toh().

Older hosts may not have the be32toh function defined. Check for this and fall back to checking the endianness and calling bswap_32 directly if needed. This works on both old and new hosts.

---
 configure.ac                |  1 +
 libkmod/libkmod-signature.c | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)
configure.ac +1 -0
index 40e54cf..de2ee49 100644
@@ -45,6 +45,7 @@ PKG_PROG_PKG_CONFIG
 AC_CHECK_FUNCS_ONCE(__xstat)
 AC_CHECK_FUNCS_ONCE([__secure_getenv secure_getenv])
 AC_CHECK_FUNCS_ONCE([finit_module])
+AC_CHECK_FUNCS_ONCE([be32toh])
 
 # dietlibc doesn't have st.st_mtim struct member
 AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
libkmod/libkmod-signature.c +13 -1
index 6237ab7..791d092 100644
@@ -18,7 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <endian.h>
+#include <byteswap.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -26,6 +26,18 @@
 
 #include "libkmod-internal.h"
 
+/* be32toh is usually a macro definend in <endian.h>, but it might be
+ * a function in some system so check both, and if neither is defined
+ * then define be32toh (for RHEL 5).
+ */
+#if !defined(HAVE_BE32TOH) && !defined(be32toh)
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define be32toh(x) __bswap_32 (x)
+#else
+#define be32toh(x) (x)
+#endif
+#endif
+
 /* These types and tables were copied from the 3.7 kernel sources.
  * As this is just description of the signature format, it should not be
  * considered derived work (so libkmod can use the LGPL license).
Signature · 1 line
1.8.2.1
#2 lore raw

Re: [PATCH] kmod-native: Add back-up implementation of be32toh().

Hi Randy,

Quoted 4 lines · Randy MacLeod

Older hosts may not have the be32toh function defined. Check for this and fall back to checking the endianness and calling bswap_32 directly if needed. This works on both old and new hosts.

I'm fine with adding fallback code, even if I'm surprised with it. However see comments below.

Quoted 2 lines

We don't use s-o-b.

Quoted 10 lines
---
 configure.ac                |  1 +
 libkmod/libkmod-signature.c | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)
configure.ac +0 -0
index 40e54cf..de2ee49 100644

configure.ac PKG_PROG_PKG_CONFIG · line 48

Quoted 4 lines
configure.ac +1 -0
@@ -45,6 +45,7 @@ PKG_PROG_PKG_CONFIG
 AC_CHECK_FUNCS_ONCE(__xstat)
 AC_CHECK_FUNCS_ONCE([__secure_getenv secure_getenv])
 AC_CHECK_FUNCS_ONCE([finit_module])
+AC_CHECK_FUNCS_ONCE([be32toh])

I guess you could use AC_CHECK_DECLS_ONCE so the check below is simpler, since you don't need to care if it's a macro or a function.

Quoted 17 lines
configure.ac +0 -0
 # dietlibc doesn't have st.st_mtim struct member
 AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
libkmod/libkmod-signature.c +1 -1
index 6237ab7..791d092 100644
@@ -18,7 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <endian.h>
+#include <byteswap.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>

libkmod/libkmod-signature.c line 32

Quoted 7 lines
libkmod/libkmod-signature.c +4 -0
@@ -26,6 +26,18 @@
 
 #include "libkmod-internal.h"
 
+/* be32toh is usually a macro definend in <endian.h>, but it might be
+ * a function in some system so check both, and if neither is defined
+ * then define be32toh (for RHEL 5).
+ */

by using AC_CHECK_DECLS_ONCE this comment would be gone

libkmod/libkmod-signature.c line 33

Quoted 1 line
libkmod/libkmod-signature.c +1 -0
+#if !defined(HAVE_BE32TOH) && !defined(be32toh)

as well as the double test.

libkmod/libkmod-signature.c line 35

Quoted 2 lines
libkmod/libkmod-signature.c +2 -0
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define be32toh(x) __bswap_32 (x)

Is there any reason to include byteswap.h and then end up using the __bswap* variant?

libkmod/libkmod-signature.c line 40

Quoted 5 lines
libkmod/libkmod-signature.c +5 -0
+#else
+#define be32toh(x) (x)
+#endif
+#endif
+

Please add this check to the missing.h header. We may want to use this function in more places. Then in this file you just need to include this file.

Thanks,
Lucas De Marchi

#3 lore raw

Re: [PATCH] kmod-native: Add back-up implementation of be32toh().

Quoted 10 lines · Lucas De Marchi

Hi Randy,

Quoted 4 lines · Randy MacLeod

Older hosts may not have the be32toh function defined. Check for this and fall back to checking the endianness and calling bswap_32 directly if needed. This works on both old and new hosts.

Quoted 8 lines

I'm fine with adding fallback code, even if I'm surprised with it. However see comments below.

Quoted 2 lines

We don't use s-o-b.

ok.

Quoted 48 lines
Quoted 12 lines

---
  configure.ac                |  1 +
  libkmod/libkmod-signature.c | 14 +++++++++++++-
  2 files changed, 14 insertions(+), 1 deletion(-)
configure.ac +0 -0
index 40e54cf..de2ee49 100644

configure.ac PKG_PROG_PKG_CONFIG · line 48

Quoted 4 lines
configure.ac +1 -0
@@ -45,6 +45,7 @@ PKG_PROG_PKG_CONFIG
  AC_CHECK_FUNCS_ONCE(__xstat)
  AC_CHECK_FUNCS_ONCE([__secure_getenv secure_getenv])
  AC_CHECK_FUNCS_ONCE([finit_module])
+AC_CHECK_FUNCS_ONCE([be32toh])

I guess you could use AC_CHECK_DECLS_ONCE so the check below is simpler, since you don't need to care if it's a macro or a function.

Quoted 17 lines
configure.ac +0 -0
  # dietlibc doesn't have st.st_mtim struct member
  AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
libkmod/libkmod-signature.c +1 -1
index 6237ab7..791d092 100644
@@ -18,7 +18,7 @@
   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   */
 
-#include <endian.h>
+#include <byteswap.h>
  #include <stdint.h>
  #include <stdlib.h>
  #include <string.h>

libkmod/libkmod-signature.c line 32

Quoted 7 lines
libkmod/libkmod-signature.c +4 -0
@@ -26,6 +26,18 @@
 
  #include "libkmod-internal.h"
 
+/* be32toh is usually a macro definend in <endian.h>, but it might be
+ * a function in some system so check both, and if neither is defined
+ * then define be32toh (for RHEL 5).
+ */

by using AC_CHECK_DECLS_ONCE this comment would be gone

Quoted 3 lines

libkmod/libkmod-signature.c line 33

Quoted 1 line
libkmod/libkmod-signature.c +1 -0
+#if !defined(HAVE_BE32TOH) && !defined(be32toh)

as well as the double test.

Will do, simpler is better.

Quoted 7 lines

libkmod/libkmod-signature.c line 35

Quoted 4 lines
libkmod/libkmod-signature.c +2 -0
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define be32toh(x) __bswap_32 (x)

Is there any reason to include byteswap.h and then end up using the __bswap* variant?

No, it was late and I wanted to know if you guys would take a patch to make kmod build on old hosts so I sent this a little early.

Quoted 10 lines

libkmod/libkmod-signature.c line 40

Quoted 6 lines
libkmod/libkmod-signature.c +5 -0
+#else
+#define be32toh(x) (x)
+#endif
+#endif
+

Please add this check to the missing.h header. We may want to use this function in more places. Then in this file you just need to include this file.

Ok.
Thanks for the review.
v2 coming later today.

// Randy

Quoted 4 lines

Thanks,
Lucas De Marchi

Signature · 2 lines
# Randy MacLeod. SMTS, Linux, Wind River
Direct: 613.963.1350