From patchwork Tue Sep 18 05:01:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 970936 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42DrSL2CGMz9sBv for ; Tue, 18 Sep 2018 15:01:38 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D5DF6CE7; Tue, 18 Sep 2018 05:01:36 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 6326CC8D for ; Tue, 18 Sep 2018 05:01:35 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id ABFC0F8 for ; Tue, 18 Sep 2018 05:01:34 +0000 (UTC) X-Originating-IP: 103.19.215.2 Received: from sigabrt.benpfaff.org (unknown [103.19.215.2]) (Authenticated sender: blp@ovn.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id A06DE1BF205; Tue, 18 Sep 2018 05:01:30 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Mon, 17 Sep 2018 22:01:23 -0700 Message-Id: <20180918050123.27641-1-blp@ovn.org> X-Mailer: git-send-email 2.16.1 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH] util: Better document ALIGNED_CAST. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org CC: Han Zhou Signed-off-by: Ben Pfaff Acked-by: Han Zhou --- include/openvswitch/util.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h index b4d49ee21804..9189e6480b1c 100644 --- a/include/openvswitch/util.h +++ b/include/openvswitch/util.h @@ -273,8 +273,14 @@ is_pow2(uintmax_t x) #define BITMAP_ULONG_BITS (sizeof(unsigned long) * CHAR_BIT) #define BITMAP_N_LONGS(N_BITS) DIV_ROUND_UP(N_BITS, BITMAP_ULONG_BITS) -/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to - * (void *). This is to suppress the alignment warning issued by clang. */ +/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to (void + * *). This suppresses the alignment warning issued by Clang and newer + * versions of GCC when a pointer is cast to a type with a stricter alignment. + * + * Add ALIGNED_CAST only if you are sure that the cast is actually correct, + * that is, that the pointer is actually properly aligned for the stricter + * type. On RISC architectures, dereferencing a misaligned pointer can cause a + * segfault, so it is important to be aware of correct alignment. */ #define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR)) #ifdef __cplusplus