From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75E21C43331 for ; Wed, 25 Mar 2020 10:05:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BA222078D for ; Wed, 25 Mar 2020 10:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585130750; bh=IqlfnFelAWvPe2y4xDnwYRiMUJhKhX78uzhM/X4uE3k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=zWWfhiYrZeCe8LGczvc0+Et/ulBzEtPZ2BiaYrddcrBk6pIEDoqJhM19yBVH1fK4a nTo7VIH1KHtp+x+w8iZ7oYFmux0Vz0yb5RHX2N+HZ77xOD5tbwTZGPpfukvOIkMWob /rCJTUyvkCjWlcI/9f4vlWJFRd2ZZWhJGZZ4lbhI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726262AbgCYKFt (ORCPT ); Wed, 25 Mar 2020 06:05:49 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:33690 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbgCYKFt (ORCPT ); Wed, 25 Mar 2020 06:05:49 -0400 Received: by mail-oi1-f193.google.com with SMTP id m14so1585797oic.0; Wed, 25 Mar 2020 03:05:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Kx6zWzWlFb2q6tLbIGNUJ4/Vt+PrSLq5ud8xhYBRhgA=; b=EuHEDyB57eZf3L3yGmVihgmC3bhHNHnRnNVZvLjoQWe+u8StLC1YQIfPwyJrM4tWK0 yFlceBXYHUKEa/KBzJ/eR+vW5M+lc1Q+Wm5EqcvNCz1o8USb85MrN14AJyHXwR9EF0O3 qPV0FPAKsI2yT+YzwQdvsJC5ha9Xl2MRRZamrCD1Zew7nf2HPfjAhoKVh1n1oMpvbx6Q 2ojqVAi1H2qEk16yKT1UjI8h5FOrY6SEmY//sXONb4uGsbAjFMs56kVeJr0oPuUtLLjm rDEbds3LcqdM0mC2VS6uAs5P/42aniJOahc6Pz7YUa34TyYjJW8mqWzZOr9T5RdwYIRS 0Fbw== X-Gm-Message-State: ANhLgQ1bdoWfe8PqPeFJ7/DaVz34mpkj0q6cyMtV5m+nlEoTfqcQTP8j JtJ93tKFt99v/VFHFzoRg4JfBYodIRgBStumKfk= X-Google-Smtp-Source: ADFU+vtOyDIGXvu5ZBYH6gJK0sVQRrbQ385r2m1A6DOdRsKzFm55S1la0Vnjw3U5JFdGNrLljxf66cKaHUbGIpXYluQ= X-Received: by 2002:aca:f07:: with SMTP id 7mr215666oip.68.1585130747875; Wed, 25 Mar 2020 03:05:47 -0700 (PDT) MIME-Version: 1.0 References: <20200319195046.GA452@embeddedor.com> In-Reply-To: <20200319195046.GA452@embeddedor.com> From: "Rafael J. Wysocki" Date: Wed, 25 Mar 2020 11:05:36 +0100 Message-ID: Subject: Re: [PATCH][next] acpi: nfit.h: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" , Dan Williams Cc: Vishal Verma , Dave Jiang , Ira Weiny , "Rafael J. Wysocki" , Len Brown , "linux-nvdimm@lists.01.org" , ACPI Devel Maling List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On Thu, Mar 19, 2020 at 9:15 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. > > [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 Dan, I'm assuming that you will take care of this one or please let me know otherwise. Cheers! > --- > drivers/acpi/nfit/nfit.h | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/drivers/acpi/nfit/nfit.h b/drivers/acpi/nfit/nfit.h > index 24241941181c..af09143ce403 100644 > --- a/drivers/acpi/nfit/nfit.h > +++ b/drivers/acpi/nfit/nfit.h > @@ -144,32 +144,32 @@ struct nfit_spa { > unsigned long ars_state; > u32 clear_err_unit; > u32 max_ars; > - struct acpi_nfit_system_address spa[0]; > + struct acpi_nfit_system_address spa[]; > }; > > struct nfit_dcr { > struct list_head list; > - struct acpi_nfit_control_region dcr[0]; > + struct acpi_nfit_control_region dcr[]; > }; > > struct nfit_bdw { > struct list_head list; > - struct acpi_nfit_data_region bdw[0]; > + struct acpi_nfit_data_region bdw[]; > }; > > struct nfit_idt { > struct list_head list; > - struct acpi_nfit_interleave idt[0]; > + struct acpi_nfit_interleave idt[]; > }; > > struct nfit_flush { > struct list_head list; > - struct acpi_nfit_flush_address flush[0]; > + struct acpi_nfit_flush_address flush[]; > }; > > struct nfit_memdev { > struct list_head list; > - struct acpi_nfit_memory_map memdev[0]; > + struct acpi_nfit_memory_map memdev[]; > }; > > enum nfit_mem_flags { > -- > 2.23.0 >