Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp896867ybf; Thu, 27 Feb 2020 01:32:24 -0800 (PST) X-Google-Smtp-Source: APXvYqxqq4y03h21x/onYb/WwgTSZe75vVolLG6WJgfr4IdOX6ah5G0Tp7rwD5ldNOWgpFwZMPoS X-Received: by 2002:a05:6830:c7:: with SMTP id x7mr2445865oto.272.1582795944655; Thu, 27 Feb 2020 01:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582795944; cv=none; d=google.com; s=arc-20160816; b=SBcuqyBsuPdgss1l7V44+oCI3i0k6nnEI606fb7Jjma5zHFszYzk41bLfroMzx+0vP VNTRSRqj6B7mog56DNuR1NmrwGmUXi+bbvgIZ/IVkeUCfQVJlmVDtVtyJD3ADfUQExEt lgYNkvhI5cKqPwpZNPyHgEvOCkYA+h6Yo6tgusndspaPuW5QWax4/ZQCHJux2X6+ttdl MN9/eihCoyyNhhRRtXrprKRTfJZYFycKe25HnndSEmEF2S5r7z5xfJknS9OxumUCTa4u J+3PFP8zvqT3Q9qnc0UNRezeh4y3R4mXahPnrj1+pXdG6q0/FXKxQCpwf7ssBP5+qeqB FrFg== 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=/ITiOVVS/LfOGBRPLH6HyVs/gJJIy1Zi/4624WeqeaI=; b=VcxfZKIGK7dKOb3wabZMKN/MoQfJejZAXj399YqRv6yTPcHoffPqqEKLoAbjmV6A9V bEDoxKwiMEnkFPC0plH59d/uOkQD69R9ETqgzeheWrV5KgcKzdFaM14RgGMPyQYc7e/7 7ENXHTKQlcedIUno2oOK54DBCC9UDyMi12UJZZq2iqd6c+AEjE2wI0zAW0VWOEHkLA2h EZQ/AzmNXfI58OvNNLB6CYkl9RGiwnLxXR2Qm7qrGw1dly8XXQMRMO8qyuooG+IL15ed 6PlCrqfcLYPm/XcyVkzB2ksn4pNm+kveKTDDRPDztS3JkXI1Ktdp0IGZNWDdQZXEIAMS IC3A== 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 m85si1125696oig.158.2020.02.27.01.32.11; Thu, 27 Feb 2020 01:32:24 -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 S1728678AbgB0JcC (ORCPT + 99 others); Thu, 27 Feb 2020 04:32:02 -0500 Received: from mx2.suse.de ([195.135.220.15]:34174 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728624AbgB0JcC (ORCPT ); Thu, 27 Feb 2020 04:32:02 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1BF34ACD7; Thu, 27 Feb 2020 09:31:59 +0000 (UTC) Subject: Re: [PATCH] xen: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" , Boris Ostrovsky , Stefano Stabellini Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org References: <20200226212612.GA4663@embeddedor> From: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= Message-ID: <77d23b72-e16b-e63a-7700-3afe6c77d327@suse.com> Date: Thu, 27 Feb 2020 10:31:58 +0100 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: <20200226212612.GA4663@embeddedor> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26.02.20 22:26, 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. > > [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 Reviewed-by: Juergen Gross Juergen