Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4393808ybf; Wed, 4 Mar 2020 03:06:36 -0800 (PST) X-Google-Smtp-Source: ADFU+vt3qkz7kzXrNrmKdb8kj7llJYElkCn7DZ7uc7baEgWXlr0NbxElgTAf1d3XPHkQaRNlJGtV X-Received: by 2002:a05:6830:4b9:: with SMTP id l25mr1925894otd.266.1583319996640; Wed, 04 Mar 2020 03:06:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583319996; cv=none; d=google.com; s=arc-20160816; b=Pxvq7yi27sCER2FoUSd/Brzf+svVzar7JdT8tR2sjM61GZCBTlLbhTbMU9ve4h3Zur VtEObQz870EEzpS/D/b0nehrZU/rRw3LBuGI+a31ZvF0QlC3mCCx7BPTycwtIvgOCF3m wsUxPdkfp2KIIY3/Xa8fNZDmeMjxVM0isdNL4+Ke5kjf6D0kOhLU7hgzG7vRL3I2EY15 MhNkWuIFh8ak59xnIdXeCVl0NiRTHfZfenz8Ng6a3eE95I1ih3mAqQQbBEfuwjSHVAen G6/ifPHXuhaeeLVbzNSveScOsVQ+E34vG/CVfTqEBSI9kZSdTcycKkZsKORNyHh1qTbo HEEw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+UrriobMwgm/eHoLh3SJPb2F94MDnXPoWKh3xoG6SWk=; b=kVARuo+ZLNND4ad/Fdg4Tbu5kePrXmdRp/OaYHGprYyTM3xL12GFdsbRdGTZ6BFHlt P19FJA3ylnkvhYY42QJcyajkBxjt9vgNrrmszfAQlrv3/bEhgzgHrmhzptsPG0bhNKEe pt/d/s4JGeVuJlxGP9CLHaJbf/GKLH8A6DnIEXqwBiJcDDo0OSbvQhFIQMFJGb8v+B8L P+zQ3ecBrf95PkGrdt3avbvRkxa1ZK8JVTrpwcXO3xY4xamSTEJ6/C3t0hmduW5g/loX yugbGVCS9nwPH86WQY0wZFoIrlnGw8cPog8DqmHdRrrbJ5xeDuvFMYfo/2T6hqRwR0rS 5swQ== 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 n11si951986otf.36.2020.03.04.03.06.24; Wed, 04 Mar 2020 03:06:36 -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 S2387772AbgCDLGJ (ORCPT + 99 others); Wed, 4 Mar 2020 06:06:09 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:51309 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729232AbgCDLGJ (ORCPT ); Wed, 4 Mar 2020 06:06:09 -0500 Received: from 79.184.237.41.ipv4.supernova.orange.pl (79.184.237.41) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.341) id 23ba990a84e430d4; Wed, 4 Mar 2020 12:06:06 +0100 From: "Rafael J. Wysocki" To: "Gustavo A. R. Silva" Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] powercap: idle_inject: Replace zero-length array with flexible-array member Date: Wed, 04 Mar 2020 12:06:06 +0100 Message-ID: <2823796.V19jU70VZq@kreacher> In-Reply-To: <20200227190721.GA19083@embeddedor> References: <20200227190721.GA19083@embeddedor> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thursday, February 27, 2020 8:07:21 PM CET 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] > > Lastly, fix the following checkpatch warning: > WARNING: Prefer 'unsigned long' over 'unsigned long int' as the int is unnecessary > + unsigned long int cpumask[]; > > 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 > --- > drivers/powercap/idle_inject.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c > index cd1270614cc6..e9bbd3c42eef 100644 > --- a/drivers/powercap/idle_inject.c > +++ b/drivers/powercap/idle_inject.c > @@ -67,7 +67,7 @@ struct idle_inject_device { > struct hrtimer timer; > unsigned int idle_duration_us; > unsigned int run_duration_us; > - unsigned long int cpumask[0]; > + unsigned long cpumask[]; > }; > > static DEFINE_PER_CPU(struct idle_inject_thread, idle_inject_thread); > Applied as 5.7 material, thanks!