From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23D41C07E95 for ; Tue, 13 Jul 2021 12:22:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D416061279 for ; Tue, 13 Jul 2021 12:22:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D416061279 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=ACULAB.COM Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kuc4gHtKvQ6XlbXixYKm599BlFeZlgutORdxdZXJKiI=; b=ZnDJG3wpWF7IWj z9OALqR3AcfOV8uR+AkArNV97TxJOEeRObK8Ez5s5KG6lsPspjsL6B6r9q8r3mIYaDpxq/I7x07OK O7I5uFT1D0sksY6gMV2oTVzwo0oq56JP+Og8emeAY6yQb3uRjJGRRIVAGUOxLpkYDxpL7/WRfVORL 1pkY3IUp6kv+B7X4GwJ8Oj8W+oUBGL/PTSPC558pJKEUL8U46bichlN9C3pBERe9OQbpiYHfiAcOY vADKOQHdG+EKjfl8jAYc5Jg8Q+otvdfoemy3ZOn5+OCJCjmXCinUOsb1ATctk3eUumTxfQRYPQylc eFmmWaAP5Gf7fSb0G0Og==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3HPW-00AMjV-5H; Tue, 13 Jul 2021 12:21:14 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3HPS-00AMie-Bv for linux-arm-kernel@bombadil.infradead.org; Tue, 13 Jul 2021 12:21:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:In-Reply-To:References:Message-ID:Date:Subject:CC:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=i9pbxIDIz34PkSxZ7+DXYN88GZfJbQfLu5azrNa9YV4=; b=XbsdZpejNvzHHsNhiMO+VWsrWy OWZUitBUW8QlEQno0oqdWM5heve+sea+u4fLr0ukmI34g3euUionozkCa1EHoBKKMst65lD0gxFyT c0OoOTufav9qn8u1/z6gEnZ1WXZK2dGU+bFU3UChiL09zLiSYpJxoV0Qpjy63o7JBkWB9ewRjWYh1 lr8ZMRzq+ddefYb8LDky9uOJY81twuFMSmU1/60T3x+uIYOrxkjs7CRoPQKyTinjst9risixp0Qes 8P4qFj0Li90JJ2Te8aCjkKtaEF8sW8Htw9ecSv3f8UWK0XZjOqwjkyBzQxX1ykdvVnJZ/fU7M9fme UqbnGsuQ==; Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]) by casper.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3HOx-0015bm-Bw for linux-arm-kernel@lists.infradead.org; Tue, 13 Jul 2021 12:20:59 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210713_132043_148450_6C5DB073 X-CRM114-Status: GOOD ( 21.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel