From patchwork Fri Mar 20 23:39:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 11450573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7424314B4 for ; Fri, 20 Mar 2020 23:40:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 519DB20752 for ; Fri, 20 Mar 2020 23:40:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726935AbgCTXkO (ORCPT ); Fri, 20 Mar 2020 19:40:14 -0400 Received: from mout-p-102.mailbox.org ([80.241.56.152]:45568 "EHLO mout-p-102.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726880AbgCTXkN (ORCPT ); Fri, 20 Mar 2020 19:40:13 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 48kgHc4RhKzKmNY; Sat, 21 Mar 2020 00:40:12 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id H9vkHJPTzdq8; Sat, 21 Mar 2020 00:40:10 +0100 (CET) From: Hauke Mehrtens To: backports@vger.kernel.org Cc: johannes@sipsolutions.net, Hauke Mehrtens Subject: [PATCH 3/8] backports: stddef.h: Add sizeof_field() Date: Sat, 21 Mar 2020 00:39:45 +0100 Message-Id: <20200320233950.32257-4-hauke@hauke-m.de> In-Reply-To: <20200320233950.32257-1-hauke@hauke-m.de> References: <20200320233950.32257-1-hauke@hauke-m.de> MIME-Version: 1.0 Sender: backports-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: backports@vger.kernel.org This backports sizeof_field() from upstream Linux commit 4229a470175b ("stddef.h: Introduce sizeof_field()"). This is now used by multiple drivers. Signed-off-by: Hauke Mehrtens --- backport/backport-include/linux/stddef.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backport/backport-include/linux/stddef.h b/backport/backport-include/linux/stddef.h index 2c836b00..a6cdc67d 100644 --- a/backport/backport-include/linux/stddef.h +++ b/backport/backport-include/linux/stddef.h @@ -2,6 +2,16 @@ #define __BACKPORT_LINUX_STDDEF_H #include_next +#ifndef sizeof_field +/** + * sizeof_field(TYPE, MEMBER) + * + * @TYPE: The structure containing the field of interest + * @MEMBER: The field to return the size of + */ +#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) +#endif + #ifndef offsetofend /** * offsetofend(TYPE, MEMBER) @@ -10,7 +20,7 @@ * @MEMBER: The member within the structure to get the end offset of */ #define offsetofend(TYPE, MEMBER) \ - (offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER)) + (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER)) #endif #endif /* __BACKPORT_LINUX_STDDEF_H */