From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754823AbdBEThY (ORCPT + 2 others); Sun, 5 Feb 2017 14:37:24 -0500 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:28516 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754696AbdBET2b (ORCPT ); Sun, 5 Feb 2017 14:28:31 -0500 From: Willy Tarreau To: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux@roeck-us.net Cc: Gavin Shan , Alex Williamson , Willy Tarreau Subject: [PATCH 3.10 216/319] drivers/vfio: Rework offsetofend() Date: Sun, 5 Feb 2017 20:20:38 +0100 Message-Id: <1486322541-8206-117-git-send-email-w@1wt.eu> X-Mailer: git-send-email 2.8.0.rc2.1.gbe9624a In-Reply-To: <1486322541-8206-1-git-send-email-w@1wt.eu> References: <1486322541-8206-1-git-send-email-w@1wt.eu> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: From: Gavin Shan commit b13460b92093b29347e99d6c3242e350052b62cd upstream. The macro offsetofend() introduces unnecessary temporary variable "tmp". The patch avoids that and saves a bit memory in stack. Signed-off-by: Gavin Shan Signed-off-by: Alex Williamson [wt: backported only for ipv6 out-of-bounds fix] Signed-off-by: Willy Tarreau --- include/linux/vfio.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/linux/vfio.h b/include/linux/vfio.h index ac8d488..1a7f0ac 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -86,8 +86,7 @@ extern void vfio_unregister_iommu_driver( * from user space. This allows us to easily determine if the provided * structure is sized to include various fields. */ -#define offsetofend(TYPE, MEMBER) ({ \ - TYPE tmp; \ - offsetof(TYPE, MEMBER) + sizeof(tmp.MEMBER); }) \ +#define offsetofend(TYPE, MEMBER) \ + (offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER)) #endif /* VFIO_H */ -- 2.8.0.rc2.1.gbe9624a