[openib-general] [PATCH] use union in ibv_get_device_guid()

Sean Hefty sean.hefty at intel.com
Tue Sep 6 16:32:46 PDT 2005


This patch replaces the uint16_t array with a union to avoid a compiler
related optimization issue with SuSE gcc 3.3.3.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>

Index: libibverbs/src/device.c
===================================================================
--- libibverbs/src/device.c	(revision 3295)
+++ libibverbs/src/device.c	(working copy)
@@ -63,7 +63,10 @@
 uint64_t ibv_get_device_guid(struct ibv_device *device)
 {
 	struct sysfs_attribute *attr;
-	uint16_t guid[4];
+	union {
+		uint16_t parts[4];
+		uint64_t whole;
+	} guid;
 	int i;
 
 	attr = sysfs_get_classdev_attr(device->ibdev, "node_guid");
@@ -71,13 +74,13 @@
 		return 0;
 
 	if (sscanf(attr->value, "%hx:%hx:%hx:%hx",
-		   guid, guid + 1, guid + 2, guid + 3) != 4)
+		   guid.parts, guid.parts + 1, guid.parts + 2, guid.parts + 3) != 4)
 		return 0;
 
 	for (i = 0; i < 4; ++i)
-		guid[i] = htons(guid[i]);
+		guid.parts[i] = htons(guid.parts[i]);
 
-	return *(uint64_t *) guid;
+	return guid.whole;
 }
 
 struct ibv_context *ibv_open_device(struct ibv_device *device)






More information about the general mailing list