Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3856177ybv; Tue, 25 Feb 2020 08:29:56 -0800 (PST) X-Google-Smtp-Source: APXvYqyOrtGSaAS6Zwj1Y2J2rRyewFsc3wvj87jWI7+LudA6AEKrPGKrJ5qWBpiO2Q4HwSY6UCZV X-Received: by 2002:a05:6830:2154:: with SMTP id r20mr48411000otd.131.1582648196545; Tue, 25 Feb 2020 08:29:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582648196; cv=none; d=google.com; s=arc-20160816; b=cb/GAzz6J8luF7NknUCH1m153S+zh+9SKu1E80G9UUTtADzMDDshJeQCnXiKyry5Et Jgyt/pIMlxOmig+pznvDSpP4RjvskyeXI5WH50cL2OGH04z7cced/GXRLU0qhsAZv7ii BXe33UATH9EyRqmn9iB9dKocHux9LQklP1OKw5j+YY+Q3lhfcVUFropsZoojjVZSJ7Vf XJObCFeDMTLiOFc7qafAn9TOr3eXVPNg8CukwX0XOlJoLiuM6YeuVFV+G3IoTjFSoaPG qkR+J1zyldYT/ktVFpRm56XbDOLAHsb0MC+3AtdvYCr7+ZaMelr1s4YZm67EK7BJYdma +oKQ== 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:from:references:cc:to:subject; bh=me4vt5LNjR8ZGWLbc/puUCo8d4Y6NLxH3/S2RLsU4h0=; b=XSkCFSg4Rp4z1P8CT4k+zVM1ZHzz+FgS94Yw790uH4XFSeeYoITPCyDuUO8hMk1hQM 7XgNvBb6Yb9Y/8gKA55pQVYuBGlkcUXYVAggejJL6nLFNoRasf1oqIPJfKAFGkHSbi9u TMnpwB5/7Y5gnpoIWLGD1b6tlASzMFOz1wio8jPPzR47Qo+ePlxH8i2nxzt+Ymmr54es Y4I8bfJ4fpeONAHkmiXvO4RER90ZAgdCpic+D04Ff6B5MH36pxizlGh8sSlj5Aa5+ZrW R3xK3AO/wVX6bOdsiKyva6yUy8+cZEwcAkPwf1YtTxrNulcVABkWYVrLzD59huUSsp1V IF3g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m24si8290709otk.239.2020.02.25.08.29.43; Tue, 25 Feb 2020 08:29:56 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730624AbgBYQ3h (ORCPT + 99 others); Tue, 25 Feb 2020 11:29:37 -0500 Received: from sender11-of-f72.zoho.eu ([31.186.226.244]:17816 "EHLO sender11-of-f72.zoho.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728065AbgBYQ3h (ORCPT ); Tue, 25 Feb 2020 11:29:37 -0500 X-Greylist: delayed 904 seconds by postgrey-1.27 at vger.kernel.org; Tue, 25 Feb 2020 11:29:36 EST Received: from [172.30.220.169] (163.114.130.128 [163.114.130.128]) by mx.zoho.eu with SMTPS id 158264725127230.28543562251855; Tue, 25 Feb 2020 17:14:11 +0100 (CET) Subject: Re: [PATCH][next] wireless: realtek: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" , Kalle Valo , "David S. Miller" , Ping-Ke Shih , Yan-Hsuan Chuang Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200225002746.GA26789@embeddedor> From: Jes Sorensen Message-ID: <04cba503-9de8-0b61-8d97-77bf47392ef5@trained-monkey.org> Date: Tue, 25 Feb 2020 11:14:09 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200225002746.GA26789@embeddedor> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ZohoMailClient: External Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/24/20 7:27 PM, 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] > > This issue was found with the help of Coccinelle. Hi Gustavo, I really don't think this improves the code in any way for the drivers you are modifying. If we really want to address this corner case, it seems like fixing the compiler to address [0] arrays the same as [] arrays is the right solution. Cheers, Jes