From patchwork Wed Jun 15 17:45:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 883022 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5FHiS4Z008243 for ; Wed, 15 Jun 2011 17:45:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752088Ab1FORpy (ORCPT ); Wed, 15 Jun 2011 13:45:54 -0400 Received: from mga11.intel.com ([192.55.52.93]:48499 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751647Ab1FORpx convert rfc822-to-8bit (ORCPT ); Wed, 15 Jun 2011 13:45:53 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 15 Jun 2011 10:45:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.65,370,1304319600"; d="scan'208";a="16639774" Received: from orsmsx602.amr.corp.intel.com ([10.22.226.211]) by fmsmga002.fm.intel.com with ESMTP; 15 Jun 2011 10:45:52 -0700 Received: from orsmsx102.amr.corp.intel.com (10.22.225.129) by orsmsx602.amr.corp.intel.com (10.22.226.211) with Microsoft SMTP Server (TLS) id 8.2.255.0; Wed, 15 Jun 2011 10:45:52 -0700 Received: from orsmsx101.amr.corp.intel.com ([169.254.8.26]) by ORSMSX102.amr.corp.intel.com ([169.254.1.6]) with mapi id 14.01.0289.001; Wed, 15 Jun 2011 10:45:51 -0700 From: "Hefty, Sean" To: "linux-rdma (linux-rdma@vger.kernel.org)" Subject: [PATCH 6/8] librdmacm: Use union with sockaddr structures Thread-Topic: [PATCH 6/8] librdmacm: Use union with sockaddr structures Thread-Index: AcwrhA9g+uZ5vnZzRCeSP59NsfjwAw== Date: Wed, 15 Jun 2011 17:45:50 +0000 Message-ID: <1828884A29C6694DAF28B7E6B8A82373021311@ORSMSX101.amr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.9.131.214] MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 15 Jun 2011 17:45:54 +0000 (UTC) To avoid strict aliasing compiler warnings, use an unamed union to store the src and dst addresses. This eliminates the need for padding and sockaddr casts. Signed-off-by: Sean Hefty --- This isn't related to XRC support; I just got tired of seeing a bunch of warnings when compiling. This removed most of the warnings. examples/cmatose.c | 12 ++++++------ include/rdma/rdma_cma.h | 26 ++++++++++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/examples/cmatose.c b/examples/cmatose.c index 84831ec..82e0d7c 100644 --- a/examples/cmatose.c +++ b/examples/cmatose.c @@ -541,13 +541,13 @@ static int run_server(void) if (ret) goto out; if (test.addr.src_addr.sa_family == AF_INET) - ((struct sockaddr_in *) &test.addr.src_addr)->sin_port = port; + test.addr.src_sin.sin_port = port; else - ((struct sockaddr_in6 *) &test.addr.src_addr)->sin6_port = port; + test.addr.src_sin6.sin6_port = port; } else { - test.addr.src_addr.sa_family = PF_INET; - ((struct sockaddr_in *) &test.addr.src_addr)->sin_port = port; + test.addr.src_addr.sa_family = AF_INET; + test.addr.src_sin.sin_port = port; } ret = rdma_bind_addr(listen_id, &test.addr.src_addr); @@ -628,9 +628,9 @@ static int run_client(void) return ret; if (test.addr.dst_addr.sa_family == AF_INET) - ((struct sockaddr_in *) &test.addr.dst_addr)->sin_port = port; + test.addr.dst_sin.sin_port = port; else - ((struct sockaddr_in6 *) &test.addr.dst_addr)->sin6_port = port; + test.addr.dst_sin6.sin6_port = port; printf("cmatose: connecting\n"); for (i = 0; i < connections; i++) { diff --git a/include/rdma/rdma_cma.h b/include/rdma/rdma_cma.h index 3b40060..c0f83b1 100755 --- a/include/rdma/rdma_cma.h +++ b/include/rdma/rdma_cma.h @@ -91,12 +91,18 @@ struct rdma_ib_addr { }; struct rdma_addr { - struct sockaddr src_addr; - uint8_t src_pad[sizeof(struct sockaddr_storage) - - sizeof(struct sockaddr)]; - struct sockaddr dst_addr; - uint8_t dst_pad[sizeof(struct sockaddr_storage) - - sizeof(struct sockaddr)]; + union { + struct sockaddr src_addr; + struct sockaddr_in src_sin; + struct sockaddr_in6 src_sin6; + struct sockaddr_storage src_storage; + }; + union { + struct sockaddr dst_addr; + struct sockaddr_in dst_sin; + struct sockaddr_in6 dst_sin6; + struct sockaddr_storage dst_storage; + }; union { struct rdma_ib_addr ibaddr; } addr; @@ -578,15 +584,15 @@ int rdma_ack_cm_event(struct rdma_cm_event *event); static inline uint16_t rdma_get_src_port(struct rdma_cm_id *id) { return id->route.addr.src_addr.sa_family == PF_INET6 ? - ((struct sockaddr_in6 *) &id->route.addr.src_addr)->sin6_port : - ((struct sockaddr_in *) &id->route.addr.src_addr)->sin_port; + id->route.addr.src_sin6.sin6_port : + id->route.addr.src_sin.sin_port; } static inline uint16_t rdma_get_dst_port(struct rdma_cm_id *id) { return id->route.addr.dst_addr.sa_family == PF_INET6 ? - ((struct sockaddr_in6 *) &id->route.addr.dst_addr)->sin6_port : - ((struct sockaddr_in *) &id->route.addr.dst_addr)->sin_port; + id->route.addr.dst_sin6.sin6_port : + id->route.addr.dst_sin.sin_port; } static inline struct sockaddr *rdma_get_local_addr(struct rdma_cm_id *id)