Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp945097ybg; Wed, 3 Jun 2020 18:53:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtD3juE7S3qwyW0JQ33zlAXU2MUpmGVGofA742IMFYG0DMit500yU6UTQqv9O8oryD+lG+ X-Received: by 2002:a17:906:fc06:: with SMTP id ov6mr2033234ejb.184.1591235588940; Wed, 03 Jun 2020 18:53:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591235588; cv=none; d=google.com; s=arc-20160816; b=mErBEEgxaqnE9VhGrGN9w0d7F1V7vDwOV/2Php7FOoNmRUHsE16Q/76oYGzlXplyRZ GYyqLiclbVHFsOG9KWrR+BBJ+EGlbMF6td0w65oDj0NAme08/bV5+XBMKCoJ84O03wVB ao98xUdSRZWKJ0Mj9zQiRfR0weq9mtBThWkn3Utfdjvm5M+Tz2N7gCwuKtoz4m/bgrJw bOXTxUzUXTYpocyYDAoffvIoMcRFQmYKzOuSDX36Dk/qRcKXMdo0Np9+oTKLgsSbq9WW Tk4+2V/EfKHxwh77wSjZno+nLdhgS7mSjTbn5s4SfuuWtQgP6gd2kTUn9sT/gQdcGduz 2Gzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:subject:autocrypt:from:references:cc:to:dkim-signature; bh=yl0eC8IEiuaJdjhjbYyk0oomqI78whpsi7l628GNu3w=; b=WlBuUz5xkE61V1koXA3ajre3Ax5khGeyeds5UgmmWyDw1pv4BN+/O8H2p3yLTZQ8H3 XPit33XY/veJUQOHDIMhYovZ5j3NkBoxCrzKZ4yLrPK9YNXeQaLY+dVw+fUOe15yn3PZ 3r2gRpQNjNP/1pJduS0M160qz85T4r821QZfEx6ZB+J8jWwss1FZ+ixV8bYPMtV0Ji52 z/W8fwy99GtsuX3vetPkNeGdAPk1lo3eX2Azw7y/j30Fl/dhTyElNLOXn+TrStqb8km6 NTT5uiBgMTQSTJdxPufX8FpzATU9EKWGpSYJwQ9Qp0GwfzWdQHf/CuSDKwzbo0770rLr xm1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b="Lhp/Sh90"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp6si860278ejc.472.2020.06.03.18.52.45; Wed, 03 Jun 2020 18:53:08 -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; dkim=fail header.i=@embeddedor.com header.s=default header.b="Lhp/Sh90"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729750AbgFDAxd (ORCPT + 99 others); Wed, 3 Jun 2020 20:53:33 -0400 Received: from gateway33.websitewelcome.com ([192.185.145.239]:47751 "EHLO gateway33.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729748AbgFDAxc (ORCPT ); Wed, 3 Jun 2020 20:53:32 -0400 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 0BC762F625D for ; Wed, 3 Jun 2020 19:53:29 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id ge8PjbW4RXVkQge8PjcboP; Wed, 03 Jun 2020 19:53:29 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:Subject:From:References:Cc:To:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=yl0eC8IEiuaJdjhjbYyk0oomqI78whpsi7l628GNu3w=; b=Lhp/Sh90p6Y0nYng1QU9AJee7e PyxIq9nnMP3NagNkTEhoefRUqSgO+7BTqY03o4eZwNDwz2YQLd+Eq6u6SoWZRY/22Z53vSuL66Zb0 Ma4qX4C3qDOeog/KBTfGJDMeBjezVK3+EhMd4XoZCFhm55CSi3cGTWiuDRVQqlv1KNbOa/ShPEat5 kh6IVIFK9X0Cx03YNLmbEb9lyZg2zUIlqm4g6/qRWugC/3G/uakS/bX6FjqErt29VTX+X3XH42let 0nRGTd74cq3Xr6TstbNF0uO0iRZa4Lp4pGPNzTThTWbL6uDoVEYOaAluvBOSRGq7jlGFhuuEwVZcO WGp5WTww==; Received: from [189.207.59.248] (port=56990 helo=[192.168.15.6]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1jge8O-000eWn-Nt; Wed, 03 Jun 2020 19:53:28 -0500 To: Oliver Hartkopp , "Gustavo A. R. Silva" , Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200507185118.GA14022@embeddedor> <0420f571-2d6a-c830-2029-8da60e3c2094@hartkopp.net> From: "Gustavo A. R. Silva" Autocrypt: addr=gustavo@embeddedor.com; keydata= xsFNBFssHAwBEADIy3ZoPq3z5UpsUknd2v+IQud4TMJnJLTeXgTf4biSDSrXn73JQgsISBwG 2Pm4wnOyEgYUyJd5tRWcIbsURAgei918mck3tugT7AQiTUN3/5aAzqe/4ApDUC+uWNkpNnSV tjOx1hBpla0ifywy4bvFobwSh5/I3qohxDx+c1obd8Bp/B/iaOtn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MdsZEACUjmsJx2CAY+QSUMebQRFjKavw XB/xE7fTt2ahuhHT8qQ/lWuRQedg4baInw9nhoPE+VenOzhGeGlsJ0Ys52sdXvUjUocKgUQq 6ekOHbcw919nO5L9J2ejMf/VC/quN3r3xijgRtmuuwZjmmi8ct24TpGeoBK4WrZGh/1hAYw4 ieARvKvgjXRstcEqM5thUNkOOIheud/VpY+48QcccPKbngy//zNJWKbRbeVnimua0OpqRXhC rEVm/xomeOvl1WK1BVO7z8DjSdEBGzbV76sPDJb/fw+y+VWrkEiddD/9CSfgfBNOb1p1jVnT 2mFgGneIWbU0zdDGhleI9UoQTr0e0b/7TU+Jo6TqwosP9nbk5hXw6uR5k5PF8ieyHVq3qatJ 9K1jPkBr8YWtI5uNwJJjTKIA1jHlj8McROroxMdI6qZ/wZ1ImuylpJuJwCDCORYf5kW61fcr HEDlIvGc371OOvw6ejF8ksX5+L2zwh43l/pKkSVGFpxtMV6d6J3eqwTafL86YJWH93PN+ZUh 6i6Rd2U/i8jH5WvzR57UeWxE4P8bQc0hNGrUsHQH6bpHV2lbuhDdqo+cM9ehGZEO3+gCDFmK rjspZjkJbB5Gadzvts5fcWGOXEvuT8uQSvl+vEL0g6vczsyPBtqoBLa9SNrSVtSixD1uOgyt AP7RWS474w== Subject: Re: [PATCH] can: Replace zero-length array with flexible-array Message-ID: <73903bc6-afb7-f30e-28ef-065d41c6ace6@embeddedor.com> Date: Wed, 3 Jun 2020 19:58:35 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <0420f571-2d6a-c830-2029-8da60e3c2094@hartkopp.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.207.59.248 X-Source-L: No X-Exim-ID: 1jge8O-000eWn-Nt X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.15.6]) [189.207.59.248]:56990 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Oliver, Sorry for the late reply. I totally lost track of this thread. :/ Please, see my comments below... On 5/12/20 08:30, Oliver Hartkopp wrote: > > > On 2020-05-07 20:51, Gustavo A. R. Silva wrote: >> The current codebase makes use of the zero-length array language >> extension to the C90 standard, but the preferred mechanism to declare >> variable-length types such as these ones is a flexible array member[1][2], >> introduced in C99: >> >> struct foo { >>          int stuff; >>          struct boo array[]; >> }; >> >> By making use of the mechanism above, we will get a compiler warning >> in case the flexible array does not occur last in the structure, which >> will help us prevent some kind of undefined behavior bugs from being >> inadvertently introduced[3] to the codebase from now on. >> >> Also, notice that, dynamic memory allocations won't be affected by >> this change: >> >> "Flexible array members have incomplete type, and so the sizeof operator >> may not be applied. As a quirk of the original implementation of >> zero-length arrays, sizeof evaluates to zero."[1] >> >> sizeof(flexible-array-member) triggers a warning because flexible array >> members have incomplete type[1]. There are some instances of code in >> which the sizeof operator is being incorrectly/erroneously applied to >> zero-length arrays and the result is zero. Such instances may be hiding >> some bugs. So, this work (flexible-array member conversions) will also >> help to get completely rid of those sorts of issues. >> >> This issue was found with the help of Coccinelle. >> >> [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html >> [2] https://github.com/KSPP/linux/issues/21 >> [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") >> >> Signed-off-by: Gustavo A. R. Silva >> --- >>   include/linux/can/skb.h |    2 +- >>   1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/include/linux/can/skb.h b/include/linux/can/skb.h >> index a954def26c0d..900b9f4e0605 100644 >> --- a/include/linux/can/skb.h >> +++ b/include/linux/can/skb.h >> @@ -34,7 +34,7 @@ >>   struct can_skb_priv { >>       int ifindex; >>       int skbcnt; >> -    struct can_frame cf[0]; >> +    struct can_frame cf[]; >>   }; >>     static inline struct can_skb_priv *can_skb_prv(struct sk_buff *skb) >> > > Acked-by: Oliver Hartkopp > > @Gustavo: Just to be sure: > > From the referenced URLs I got the information that the sizeof() operator causes problems when applied to e.g. cf[0]. > > We don't have this case in our code - but one question remains to me: > > We are using the above construct to ensure the padding between the two 'int' values and the struct can_frame which enforces a 64 bit alignment. > > This intention is not affected by the patch, right? > pahole shows exactly the same output either if cf is a zero-length array or a flexible-array member: $ pahole -C 'can_skb_priv' drivers/net/can/dev.o struct can_skb_priv { int ifindex; /* 0 4 */ int skbcnt; /* 4 4 */ struct can_frame cf[] __attribute__((__aligned__(8))); /* 8 0 */ /* size: 8, cachelines: 1, members: 3 */ /* forced alignments: 1 */ /* last cacheline: 8 bytes */ } __attribute__((__aligned__(8))); So, it seems everything should fine. :) Thanks -- Gustavo