Skip to contentSkip to conversation

libmlx4: Fix a compiler warning

PATCH In review Bart Van Assche 2 participants 4 messages Oct 10, 2011 – Apr 2, 2012 3 messages not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libmlx4: Fix a compiler warning

Avoid that link_local_gid() triggers the following compiler warning:
dereferencing type-punned pointer will break strict-aliasing rules

---
 src/verbs.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
src/verbs.c +3 -5
index 199d107..28d8585 100644
@@ -616,12 +616,10 @@ int mlx4_destroy_qp(struct ibv_qp *ibqp)
 
 static int link_local_gid(const union ibv_gid *gid)
 {
-	uint32_t hi = *(uint32_t *)(gid->raw);
-	uint32_t lo = *(uint32_t *)(gid->raw + 4);
-	if (hi == htonl(0xfe800000) && lo == 0)
-		return 1;
+	uint32_t hi = gid->u32[0];
+	uint32_t lo = gid->u32[1];
 
-	return 0;
+	return hi == htonl(0xfe800000) && lo == 0;
 }
 
 static uint16_t get_vlan_id(union ibv_gid *gid)
Signature · 6 lines
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to a message not in the archive
Quoted 6 lines · Bart Van Assche

-       uint32_t hi = *(uint32_t *)(gid->raw);
-       uint32_t lo = *(uint32_t *)(gid->raw + 4);
-       if (hi == htonl(0xfe800000) && lo == 0)
-               return 1;
+       uint32_t hi = gid->u32[0];
+       uint32_t lo = gid->u32[1];

Thanks, however I like to keep libmlx4 backwards compatible if possible. So we can't do this unconditionally.

- R.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to a message not in the archive
Quoted 10 lines · Roland Dreier

Review

Quoted 6 lines · Bart Van Assche
(quoted diff) +2 -4
-       uint32_t hi = *(uint32_t *)(gid->raw);
-       uint32_t lo = *(uint32_t *)(gid->raw + 4);
-       if (hi == htonl(0xfe800000) && lo == 0)
-               return 1;
+       uint32_t hi = gid->u32[0];
+       uint32_t lo = gid->u32[1];

Thanks, however I like to keep libmlx4 backwards compatible if possible. So we can't do this unconditionally.

How about the patch below ?

[PATCH] libmlx4: Fix a compiler warning

Avoid that link_local_gid() triggers the following compiler warning:
dereferencing type-punned pointer will break strict-aliasing rules

---
 configure.in |   10 ++++++++++
 src/verbs.c  |    5 +++++
 2 files changed, 15 insertions(+), 0 deletions(-)
configure.in +10 -0
index 8aad5ff..eb03820 100644
@@ -63,6 +63,16 @@ AM_CONDITIONAL(HAVE_IBV_DEVICE_LIBRARY_EXTENSION,
     test $IBV_DEVICE_LIBRARY_EXTENSION != IBV_DEVICE_LIBRARY_EXTENSION)
 AC_SUBST(IBV_DEVICE_LIBRARY_EXTENSION)
 
+# Check whether ibv_gid has a member called u32.
+
+AC_CHECK_MEMBER([ibv_gid.u32],
+	        [AC_DEFINE([HAVE_IBV_GID_U32],
+		           1,                                   
+			   [Define to 1 if ibv_gid has a member called u32.])
+                ],
+		[],
+		[#include <infiniband/verbs.h>])
+
 AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script,
     [if test -n "`$LD --help < /dev/null 2>/dev/null | grep version-script`"; then
         ac_cv_version_script=yes
src/verbs.c +5 -0
index 408fc6d..c7a08a5 100644
@@ -624,8 +624,13 @@ int mlx4_destroy_qp(struct ibv_qp *ibqp)
 
 static int link_local_gid(const union ibv_gid *gid)
 {
+#ifdef HAVE_IBV_GID_M32
+	uint32_t hi = gid->u32[0];
+	uint32_t lo = gid->u32[1];
+#else
 	uint32_t hi = *(uint32_t *)(gid->raw);
 	uint32_t lo = *(uint32_t *)(gid->raw + 4);
+#endif
 	if (hi == htonl(0xfe800000) && lo == 0)
 		return 1;
 
Signature · 7 lines
1.7.7


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
In reply to a message not in the archive
Quoted 9 lines · Bart Van Assche
Quoted 8 lines · Roland Dreier
Quoted 6 lines · Bart Van Assche
(quoted diff) +2 -4
-       uint32_t hi = *(uint32_t *)(gid->raw);
-       uint32_t lo = *(uint32_t *)(gid->raw + 4);
-       if (hi == htonl(0xfe800000) && lo == 0)
-               return 1;
+       uint32_t hi = gid->u32[0];
+       uint32_t lo = gid->u32[1];
Quoted 4 lines
Quoted 2 lines

Thanks, however I like to keep libmlx4 backwards compatible if possible. So we can't do this unconditionally.

How about the patch below ?

Sorry, but the patch I sent yesterday was wrong. Please replace by the patch below:

[PATCH] libmlx4: Fix a compiler warning

Avoid that link_local_gid() triggers the following compiler warning:
dereferencing type-punned pointer will break strict-aliasing rules

---
 configure.in |    9 +++++++++
 src/verbs.c  |    5 +++++
 2 files changed, 14 insertions(+), 0 deletions(-)
configure.in +9 -0
index 8aad5ff..eeb4430 100644
@@ -63,6 +63,15 @@ AM_CONDITIONAL(HAVE_IBV_DEVICE_LIBRARY_EXTENSION,
     test $IBV_DEVICE_LIBRARY_EXTENSION != IBV_DEVICE_LIBRARY_EXTENSION)
 AC_SUBST(IBV_DEVICE_LIBRARY_EXTENSION)
 
+# Check whether ibv_gid has a member called u32.
+
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <infiniband/verbs.h>]],
+                                   [[union ibv_gid g; return sizeof(g.u32);]])],
+                  [AC_DEFINE([HAVE_IBV_GID_U32],
+                             [1],
+                             [Define to 1 if ibv_gid has a member called u32.])
+                  ])
+
 AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script,
     [if test -n "`$LD --help < /dev/null 2>/dev/null | grep version-script`"; then
         ac_cv_version_script=yes
src/verbs.c +5 -0
index 408fc6d..b52f799 100644
@@ -624,8 +624,13 @@ int mlx4_destroy_qp(struct ibv_qp *ibqp)
 
 static int link_local_gid(const union ibv_gid *gid)
 {
+#ifdef HAVE_IBV_GID_U32
+	uint32_t hi = gid->u32[0];
+	uint32_t lo = gid->u32[1];
+#else
 	uint32_t hi = *(uint32_t *)(gid->raw);
 	uint32_t lo = *(uint32_t *)(gid->raw + 4);
+#endif
 	if (hi == htonl(0xfe800000) && lo == 0)
 		return 1;
 

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html