Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2017349yba; Mon, 15 Apr 2019 03:15:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxP9I/P0MWeUV9OgBUmvY0FSS6lT/8h7kxAP8oxRHBIlByFERy3aLpWtN2dSHNt02GVrVr1 X-Received: by 2002:aa7:8609:: with SMTP id p9mr74176117pfn.166.1555323317486; Mon, 15 Apr 2019 03:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555323317; cv=none; d=google.com; s=arc-20160816; b=zcd1tvl0tItnWgVLNTFtSmVSyJ4B74H0zWgHz+XfVaRRzSs5Q/hMi9eajMkFQWJQc4 ow23D1x6kftNC7SowiD0rXu/6O5tcMOTtAFAbhk18/TixoiNvj3zKqZf6dq8dnZNIWXI TF9EjVQ62Vk+d8fEbxuPj5rd5+IDUOEheIb7/35kKPwnL07r3X0bE3weICZA6SeCRGmK MhwHcbC9jD+eA3PjNJDjIY0pJuHbr5Y7iMTi4/xs836N2GzCC6r8uGvLFxDH4foPUQYS N60ndGXhnk3RihSDj/ulzz2Bquxtapn+HGrKj/V9KSy/SxeroKoP3C2Qf4Z3M2e5Yb0D a9Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=YoMWmUaIuhPWO6FEtWwrQktpmL4pDG/BBVlcee6yDfE=; b=A1xXim828Lbu/uUm0zBElsCsXp6SB4aoeDZw20wwzHzE7yeYhVGTHWvkveOgWu3SdB qYkMrPtYQYMlc377sTaNWcu221Y0fYVs/VDHVwEKXhESNxnOAOR7CDQvMwjgV4y5q18I 3uU5ooJTjiGdL31UBOvDhwj8voVmQZr/hoOBY4Ocq9srW6RAzjGBrYMmRuUc6dRKI/dS Tuv11U+NpX1/C7P1j/OD8NtZ4djeDxn9VTJxG/7De2qp7loSUOvEOTWcbU/HV37rYlHr bJxpZjv0CtGHyhf5Bhj6kxIXeT7mYGoYQYDfKWX6zdQBV0SQabeh4GCpeCla57eP/rKb ciyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=dkiPsFxF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t21si44332467plr.366.2019.04.15.03.15.01; Mon, 15 Apr 2019 03:15:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=dkiPsFxF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727212AbfDOKOA (ORCPT + 99 others); Mon, 15 Apr 2019 06:14:00 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:54394 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726094AbfDOKN7 (ORCPT ); Mon, 15 Apr 2019 06:13:59 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3FA8Ule131521; Mon, 15 Apr 2019 10:12:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=content-type : mime-version : subject : from : in-reply-to : date : cc : content-transfer-encoding : message-id : references : to; s=corp-2018-07-02; bh=YoMWmUaIuhPWO6FEtWwrQktpmL4pDG/BBVlcee6yDfE=; b=dkiPsFxFARZHO8s5GhtIc9W+Ua/BB8ArL9gL0S4apvcmpbFv4Qq5c9ctchFDiwT/M6b2 mqa3kgf4ykq/sRcF4xmGL1mtLKZTeAoUdFCUhVS+EB3aswa7IuJEbp0Gq16PyICqTibx SjTX8OHfHCQJRNM63Ib74hA9hCVxFm/XT3R13vz7MFgxkq2F3kRNaCfQ3xcf9PMl1eyf Kn3HzmOKUYJ/K3MUs+TXxxRUQXuUNBGqBbJzNdFHHf6+8pIsCOCSnbltssuRk7Rw/+SW y5ZDZZ00HbckDtY+Fap94sV/ze7rlw5VPKZznkO/NwtWS1VHZ53D9m+bArDCVnECy2+W cw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 2ru59cwvfj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 15 Apr 2019 10:12:27 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3FACObS176437; Mon, 15 Apr 2019 10:12:27 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2rv2tu3b2u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 15 Apr 2019 10:12:26 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x3FACIeb009910; Mon, 15 Apr 2019 10:12:22 GMT Received: from [192.168.0.110] (/73.243.10.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Apr 2019 03:12:18 -0700 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Subject: Re: [PATCH 1/2] include: linux: Regularise the use of FIELD_SIZEOF macro From: William Kucharski In-Reply-To: <20190414091452.22275-1-shyam.saini@amarulasolutions.com> Date: Mon, 15 Apr 2019 04:12:16 -0600 Cc: Kernel Hardening , LKML , Andrew Morton , keescook@chromium.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, linux-ext4@vger.kernel.org, devel@lists.orangefs.org, linux-mm@kvack.org, linux-sctp@vger.kernel.org, bpf@vger.kernel.org, kvm@vger.kernel.org, mayhs11saini@gmail.com Content-Transfer-Encoding: quoted-printable Message-Id: References: <20190414091452.22275-1-shyam.saini@amarulasolutions.com> To: Shyam Saini X-Mailer: Apple Mail (2.3445.104.8) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9227 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904150072 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9227 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904150072 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Apr 14, 2019, at 3:14 AM, Shyam Saini = wrote: >=20 > Currently, there are 3 different macros, namely sizeof_field, = SIZEOF_FIELD > and FIELD_SIZEOF which are used to calculate the size of a member of > structure, so to bring uniformity in entire kernel source tree lets = use > FIELD_SIZEOF and replace all occurrences of other two macros with = this. >=20 > For this purpose, redefine FIELD_SIZEOF in include/linux/stddef.h and > tools/testing/selftests/bpf/bpf_util.h and remove its defination from > include/linux/kernel.h > --- a/include/linux/stddef.h > +++ b/include/linux/stddef.h > @@ -20,6 +20,15 @@ enum { > #endif >=20 > /** > + * FIELD_SIZEOF - get the size of a struct's field > + * @t: the target struct > + * @f: the target struct's field > + * Return: the size of @f in the struct definition without having a > + * declared instance of @t. > + */ > +#define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f)) > + > +/** > * sizeof_field(TYPE, MEMBER) > * > * @TYPE: The structure containing the field of interest > @@ -34,6 +43,6 @@ enum { > * @MEMBER: The member within the structure to get the end offset of > */ > #define offsetofend(TYPE, MEMBER) \ > - (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER)) > + (offsetof(TYPE, MEMBER) + FIELD_SIZEOF(TYPE, MEMBER)) If you're doing this, why are you leaving the definition of = sizeof_field() in stddef.h untouched? Given the way this has worked historically, if you are leaving it in = place for source compatibility reasons, shouldn't it be redefined in terms of FIELD_SIZEOF(), e.g.: #define sizeof_field(TYPE, MEMBER) FIELD_SIZEOF(TYPE, MEMBER)