Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3849526pxv; Tue, 13 Jul 2021 05:22:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRLwPqnOcFZ9d1Yw+nljq8+vSr3YSs9de3nDhmUqAMtvEok+XHwqLrJ4nt1H5ayczZ9Pqy X-Received: by 2002:a17:907:7d94:: with SMTP id oz20mr5322458ejc.333.1626178944268; Tue, 13 Jul 2021 05:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626178944; cv=none; d=google.com; s=arc-20160816; b=o7cGCh/Y1GG9Q1RpQWFFJ1Bd//7Zn0B95/mYM6iSVPBA2NhFVzF+Wb0qaspTuvoaj9 idJ5CEHhyRLwNgseB4W3Vd0zL5RdJaLz5XJpgB61REZQx+kEnCcNycs8yq00qlGr6cNA c4Z/7ljyoL+jS7KXGjViWntpErG3R/QNcNInMJr4F3lfJMQ7g9UppQq4KilfKek4vbPg /tAIe6ovsqok2jpmuiWxJduF1B1cCF+qpgolrfduX2CuD1ngrPvK+5nujc7nTk6RTBtl dXvj4ZGjcXrDjq+ry0jXRrEoSnu3q18SqcAXihWNnHnXuuSf9+3hi6U5fK2tzlzPFbHl 5rxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=WOk/RFFtMAR29gonl4yYmhO6odxFEquUOlv5grHwSy4=; b=bgVuExHGxCpb96uWB0sAtp1eUij0wdGIb8M28kcUQlXens4k322xzEiylfhYRUFqer uGZhB1wkqXVUWCNNLYFVsRVRsYK6OyqftH5G7bRSOWMrGnNIumWbXzyrc2oAeYxDtMkJ XD2DAFIHUwhDiheBHDgniWhcWD4ZBZFa0QUazJ2TDTAUe0xdvfuobcMoUUGxmeU6mJkY v5LqvWnB7VdXrnMSPHslAxvrnRCBhrcs/4ZmJAMcHLii3VMRUj2EBxDqxc+j5QhVrk85 2t8zTz7lquA889sEnW5rWXuEfSki5REes6fQFYFoC7TntO/OXyb5cxPpDSSowU2dSZJw QGlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qa38si2241534ejc.571.2021.07.13.05.22.00; Tue, 13 Jul 2021 05:22:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236104AbhGMMXW convert rfc822-to-8bit (ORCPT + 99 others); Tue, 13 Jul 2021 08:23:22 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]:49588 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236085AbhGMMXV (ORCPT ); Tue, 13 Jul 2021 08:23:21 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-231-Dk-aoIJGObaCzW5wvCtF0g-1; Tue, 13 Jul 2021 13:20:28 +0100 X-MC-Unique: Dk-aoIJGObaCzW5wvCtF0g-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 13 Jul 2021 13:20:26 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.018; Tue, 13 Jul 2021 13:20:26 +0100 From: David Laight To: 'Russell King' CC: =?iso-8859-1?Q?Uwe_Kleine-K=F6nig?= , Salah Triki , "fabrice.gasnier@foss.st.com" , "thierry.reding@gmail.com" , "lee.jones@linaro.org" , "mcoquelin.stm32@gmail.com" , "alexandre.torgue@foss.st.com" , "linux-pwm@vger.kernel.org" , "linux-stm32@st-md-mailman.stormreply.com" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] divide by 3*sizeof(u32) when computing array_size Thread-Topic: [PATCH] divide by 3*sizeof(u32) when computing array_size Thread-Index: AQHXd8hGdzQpdmgYHUiEx+VC3p1WwKtAvfwg///0h4CAAB31IA== Date: Tue, 13 Jul 2021 12:20:26 +0000 Message-ID: <2f725f0be09349308bf7d9a24399d516@AcuMS.aculab.com> References: <20210712231910.GA1831270@pc> <20210713063053.qqttzxlopvpnadj3@pengutronix.de> <20210713091954.GG22278@shell.armlinux.org.uk> <012ccfea2a564274bd9d2e1cfc130873@AcuMS.aculab.com> <20210713112253.GH22278@shell.armlinux.org.uk> In-Reply-To: <20210713112253.GH22278@shell.armlinux.org.uk> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Russell King > Sent: 13 July 2021 12:23 > > On Tue, Jul 13, 2021 at 11:07:00AM +0000, David Laight wrote: > > From: Russell King > > > Sent: 13 July 2021 10:20 > > .... > > > I would also note that the code relies on there being no padding in > > > struct stm32_breakinput - it should be noted that a strict > > > interpretation of the C standard allows padding to be added anywhere > > > to a structure - at the start, end or between members. > > > > I'm pretty certain I remember that padding before the first member > > isn't allowed. > > You may be right there. > > > In any case the kernel generally assumes there is no extra padding. > > (eg for structures that map hardware registers.) > > That's incorrect. Places where we care either generally end up with > __packed or are carefully layed out to ensure members are naturally > aligned to reduce the likelyhood of it. 32-bit OABI ARM has been > particularly "fun" in this respect. I did say 'extra padding'. Ensuring everything is naturally aligned is best - shame the standards bodies don't do that - just look at the SCTP socket options. Adding __packed is right sometimes, but it isn't without cost and is probably wrong for anything hardware related. Definitely useful on structure members to remove the padding before that specific member (eg for 64bit in x86 compat code). But marking a structure __packed is usually wrong (or bad). > > For big structures it is worth adding a compile-time check of > > the structure size - but not really for three u32. > > Sorry, structure size has absolutely nothing to do with whether it's > a good idea to have a compile-time check. The deciding factor is > whether the code relies on some property such as it being a certain > size. Such as in this exact case. If you grep for "BUILD_BUG_ON.*sizeof" > in fs/ for example, this illustrates the point rather well. I'd not bother if the size is obviously going to be correct. I did get some odd bugs a few years ago from a compiler that aligned all structures on 4-byte boundaries. I had to change a structure of two u16 into an array :-) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)