Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3752899ybb; Mon, 23 Mar 2020 07:05:58 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtqhqmPH1tmdyTHl+9zyDJponlPQDA5zHNZ2GidQXkJP9hOlshWtG2Gp7F+GkYElxRbzjWx X-Received: by 2002:aca:f541:: with SMTP id t62mr17463401oih.172.1584972358351; Mon, 23 Mar 2020 07:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584972358; cv=none; d=google.com; s=arc-20160816; b=iYn1p1unfAE+AzcUtE53KCCbuRnRF2i1DEzQvVJ57KQIYvCmLelpAYV/31IVGyr70p g95Djax4Iol9FgO8mKNyvgazMwDEW/JENNm9ZDM+fYY1jC8YNpMM8viSf+vLZbxwYT6o 5EoJUe6I8onMlrtNdaeWNOCQdl0jIzWDsDp9H0lAonClVi431wCWyGeIX8FvB5/Dhk/u c6PcKhO8OjjLH/8XAj9LrPZSV7hXiAdFoZ9oYYAHlrWDCTJEa2TrGesJBZuyCH2ElYcS Q6+NCm3gZMIpSi6Gh7kTlQXrwHHV8PGt4uECvrxePJrsQXdhxXgANfeJp4xrRsiuXZD1 Xz6Q== 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=eHJqqvbvkO4Qx/LJKz+nliHPB1J5YpCKLrYmxIiWT/Q=; b=L+af27i5taDxGFE31SXbIp9NNg4tWvTYZTe2lEP/0dnXKRv55+qi2at2ojVFjeqCPk wTEywM9cPaksi6fL8pr1eZNi9Dm5egBpjmBB7BgmTRCv/5cB/8D7egTLwitUHep2j6/5 DB0zL9B/VkIN7WgbmkKJ6aofuFUOnB3w7GeoW1sIVgPbuo3wuDepTh/gNLnrKP8ZHrwI hoZ3WRTg3Jkm5C7jZrDW+0fuT+pgkawE0rZSb0Q0wt/TDHRebHiued3Mh+vj5Z2/54Ar 7mvuDzYGJQqL3mn4VPLCQYr85WtZsNLZVWGOXp2b7hLfTLuvq+rvlzHAFUtbEEeRT7aR 1QwA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si1126123otr.321.2020.03.23.07.05.32; Mon, 23 Mar 2020 07:05:58 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728596AbgCWOBt (ORCPT + 99 others); Mon, 23 Mar 2020 10:01:49 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:36372 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728446AbgCWOBs (ORCPT ); Mon, 23 Mar 2020 10:01:48 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 3CE882963E0 Subject: Re: [PATCH][next] chrome: wilco_ec: event: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" , Benson Leung Cc: linux-kernel@vger.kernel.org References: <20200320231634.GA20040@embeddedor.com> From: Enric Balletbo i Serra Message-ID: <18308ba0-c789-2b41-f4cd-418b3ae7122a@collabora.com> Date: Mon, 23 Mar 2020 15:01:44 +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: <20200320231634.GA20040@embeddedor.com> Content-Type: text/plain; charset=utf-8 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 Hi Gustavo On 21/3/20 0:16, 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 Queued for 5.7. Thanks! ~ Enric > --- > drivers/platform/chrome/wilco_ec/event.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/platform/chrome/wilco_ec/event.c b/drivers/platform/chrome/wilco_ec/event.c > index dba3d445623f..814518509739 100644 > --- a/drivers/platform/chrome/wilco_ec/event.c > +++ b/drivers/platform/chrome/wilco_ec/event.c > @@ -79,7 +79,7 @@ static DEFINE_IDA(event_ida); > struct ec_event { > u16 size; > u16 type; > - u16 event[0]; > + u16 event[]; > } __packed; > > #define ec_event_num_words(ev) (ev->size - 1) > @@ -96,7 +96,7 @@ struct ec_event_queue { > int capacity; > int head; > int tail; > - struct ec_event *entries[0]; > + struct ec_event *entries[]; > }; > > /* Maximum number of events to store in ec_event_queue */ >