From patchwork Sun Mar 23 20:18:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 3880631 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 636219F334 for ; Sun, 23 Mar 2014 20:18:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D44420220 for ; Sun, 23 Mar 2014 20:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 962CB20259 for ; Sun, 23 Mar 2014 20:18:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750979AbaCWUSn (ORCPT ); Sun, 23 Mar 2014 16:18:43 -0400 Received: from mga11.intel.com ([192.55.52.93]:10324 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751107AbaCWUSc (ORCPT ); Sun, 23 Mar 2014 16:18:32 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 23 Mar 2014 13:18:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,715,1389772800"; d="scan'208";a="505038281" Received: from cst-linux.jf.intel.com ([10.23.221.72]) by fmsmga002.fm.intel.com with ESMTP; 23 Mar 2014 13:18:31 -0700 From: sean.hefty@intel.com To: sean.hefty@intel.com, ira.weiny@intel.com, kaike.wan@intel.com, john.fleck@intel.com, linux-rdma@vger.kernel.org Subject: [PATCH 3/9] ibacm: Eliminate strict aliasing compiler warnings Date: Sun, 23 Mar 2014 13:18:15 -0700 Message-Id: <1395605901-9080-4-git-send-email-sean.hefty@intel.com> X-Mailer: git-send-email 1.7.3 In-Reply-To: <1395605901-9080-1-git-send-email-sean.hefty@intel.com> References: <1395605901-9080-1-git-send-email-sean.hefty@intel.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Hefty Use local variables and memcpy to defeat the compiler warning: dereferencing type-punned pointer will break strict-aliasing rules Signed-off-by: Sean Hefty --- src/acm.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/acm.c b/src/acm.c index 57d34dc..c9e1b3c 100644 --- a/src/acm.c +++ b/src/acm.c @@ -1598,13 +1598,15 @@ static void acm_process_timeouts(void) DLIST_ENTRY *entry; struct acm_send_msg *msg; struct acm_resolve_rec *rec; + struct acm_mad *mad; while (!DListEmpty(&timeout_list)) { entry = timeout_list.Next; DListRemove(entry); msg = container_of(entry, struct acm_send_msg, entry); - rec = (struct acm_resolve_rec *) ((struct acm_mad *) msg->data)->data; + mad = (struct acm_mad *) &msg->data[0]; + rec = (struct acm_resolve_rec *) mad->data; acm_format_name(0, log_data, sizeof log_data, rec->dest_type, rec->dest, sizeof rec->dest); @@ -2647,7 +2649,7 @@ static int acm_parse_osm_fullv1_paths(FILE *f, uint64_t *lid2guid, struct acm_ep char s[128]; char *p, *ptr, *p_guid, *p_lid; uint64_t guid; - uint16_t lid, dlid; + uint16_t lid, dlid, net_dlid; int sl, mtu, rate; int ret = 1, i; uint8_t addr[ACM_MAX_ADDRESS]; @@ -2710,6 +2712,7 @@ static int acm_parse_osm_fullv1_paths(FILE *f, uint64_t *lid2guid, struct acm_ep break; dlid = strtoul(p, NULL, 0); + net_dlid = htons(dlid); p = strtok_r(NULL, ":", &ptr); if (!p) @@ -2740,7 +2743,7 @@ static int acm_parse_osm_fullv1_paths(FILE *f, uint64_t *lid2guid, struct acm_ep memset(addr, 0, ACM_MAX_ADDRESS); if (i == 0) { addr_type = ACM_ADDRESS_LID; - *((uint16_t *) addr) = htons(dlid); + memcpy(addr, &net_dlid, sizeof net_dlid); } else { addr_type = ACM_ADDRESS_GID; memcpy(addr, &dgid, sizeof(dgid)); @@ -2754,7 +2757,7 @@ static int acm_parse_osm_fullv1_paths(FILE *f, uint64_t *lid2guid, struct acm_ep dest->path.sgid = sgid; dest->path.slid = htons(ep->port->lid); dest->path.dgid = dgid; - dest->path.dlid = htons(dlid); + dest->path.dlid = net_dlid; dest->path.reversible_numpath = IBV_PATH_RECORD_REVERSIBLE; dest->path.pkey = htons(ep->pkey); dest->path.mtu = (uint8_t) mtu;