From patchwork Tue Jul 21 13:50:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6836221 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E0AD49F380 for ; Tue, 21 Jul 2015 13:54:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0EAC42069A for ; Tue, 21 Jul 2015 13:54:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 46D5A20670 for ; Tue, 21 Jul 2015 13:54:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHXy3-0004mC-NX; Tue, 21 Jul 2015 13:52:23 +0000 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHXxr-0004gj-A5 for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2015 13:52:11 +0000 Received: by wicgb10 with SMTP id gb10so56388354wic.1 for ; Tue, 21 Jul 2015 06:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=sdMx7yTu1R/sHiWb5UnjUxzkyvrfB424V+WFaV0i5+Q=; b=z5CdHsq1DejZ0FOpZkjo1ri2aSyj68ZEO9UHG1TzysFA9h3V3c82mtazTA8hGhKM5Y 9BCMmqLkxyEvsiVq+q60gdxUHQ0QHjwlsMOFAtfr6rVOoFEvDTISuEazdKEFmHPv4TjM RYfvQuEIUD0bA7n7t4LrA0LrurpQ+H7zyclkM/YL64ObLhEH2qwXOkC5djHiqgleuGaA HpOrFFLvcx2F35cGpeTgfR3oNdXJqlFJ18ZzFu/uEpAQuM4tOD1+UOXZjXNpsC/ssElf rJ5V8yEr8fUQqzpIA7SGmBjHz5sF3PheswnQphUtb8FalJGG48BYZ8bRPU/B+UCOACrP dgKQ== X-Received: by 10.180.76.232 with SMTP id n8mr32657151wiw.72.1437486709612; Tue, 21 Jul 2015 06:51:49 -0700 (PDT) Received: from cizrna.lan ([109.72.12.178]) by smtp.gmail.com with ESMTPSA id pf4sm37172056wjb.23.2015.07.21.06.51.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jul 2015 06:51:48 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 01/16] typecheck_member and offsetof_t Date: Tue, 21 Jul 2015 15:50:43 +0200 Message-Id: <1437486658-28365-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1437486658-28365-1-git-send-email-tomeu.vizoso@collabora.com> References: <1437486658-28365-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150721_065211_492724_84216657 X-CRM114-Status: UNSURE ( 9.12 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.4 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Tomeu Vizoso , Stephen Warren , "Rafael J. Wysocki" , Mark Brown , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 Signed-off-by: Tomeu Vizoso --- include/linux/stddef.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/stddef.h b/include/linux/stddef.h index 9c61c7cda936..e60bd164c03a 100644 --- a/include/linux/stddef.h +++ b/include/linux/stddef.h @@ -27,4 +27,11 @@ enum { #define offsetofend(TYPE, MEMBER) \ (offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER)) +#define typecheck_member(TYPE, MEMBER, MEMBERTYPE) \ + ((size_t)(&((TYPE *)0)->MEMBER - (MEMBERTYPE*)0) ? 0 : 0) + +/* like offsetof(), but ensures that MEMBER is of type MEMBERTYPE */ +#define offsetof_t(TYPE, MEMBER, MEMBERTYPE) \ + (typecheck_member(TYPE, MEMBER, MEMBERTYPE) + offsetof(TYPE, MEMBER)) + #endif