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 autolearn=unavailable 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 4FAEFC34031 for ; Tue, 18 Feb 2020 01:25:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2939620801 for ; Tue, 18 Feb 2020 01:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581989134; bh=pb51zqziVxV8Pmfvrc//lSYiTlBeb8sT5Aim9mjEJ3E=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=dQKcP3etKyt5C0KQg7gnRNzzr1QR22hLHJHtp7ZDKLp94NjfWRUm8QmME3bZE+hg3 2kDl3V3Mc23R3WecI2Pr8hZlLoyLroeKJtVEXp94xwi17NDFN/qeVDpfvMU5InrRc5 AC12s/xCbMtfHyB3xBfww3yjWdCrG/XFiJk/ze80= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726289AbgBRBZd (ORCPT ); Mon, 17 Feb 2020 20:25:33 -0500 Received: from conssluserg-02.nifty.com ([210.131.2.81]:33554 "EHLO conssluserg-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726070AbgBRBZd (ORCPT ); Mon, 17 Feb 2020 20:25:33 -0500 Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) (authenticated) by conssluserg-02.nifty.com with ESMTP id 01I1POvY029003; Tue, 18 Feb 2020 10:25:24 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com 01I1POvY029003 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1581989125; bh=3MSw5JkyO/9OCsOPRafhwqlFQ7vR48exeqQSqYgqIIk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=YWjMhh0RDcuF1rO+m3rS+CCSH36MMqHbRScYqqwvGFMku4Tq+v22CxsX/fM++yXyw 1DHR6fMH6vHE1heRP/TFE/EXFFbvg9rRE6E6qb/6ZBx5OpdtdNwXGrT/vmdPq+hdqV +7dnSo43yaPKVv3+lBhpbcIJMWkjAvJTFaMoKNvwxvIHpNUMxB0mLcWEDRVu2noWpP BSi55H6OkKOQHkM1t4FXEEBnwuQQbfTdZRjx1OLWKeRVVK447bGPfq8fmZ4KvQBZDD KKh2OrmNwAV2g/99xnOY0M7g8n8yT6NXrHz7zH35sobirTwOt1XTVzuaxNHIFsrPf4 QU1+QB3oo5eHA== X-Nifty-SrcIP: [209.85.222.53] Received: by mail-ua1-f53.google.com with SMTP id g13so6873499uab.7; Mon, 17 Feb 2020 17:25:24 -0800 (PST) X-Gm-Message-State: APjAAAVNZzb3Q+ZiVQpWa2XzDnRhhas7F/k8RZzRx5Xwu9/FZsS3D5Tr UkWI0Xn9jNQrVBaHpYWwZkMI0l5I2jat3a5JXDE= X-Google-Smtp-Source: APXvYqyMjSb6Wor89MN0MqasMN0Ke1opsU3txiROIMZz+gj33FtHTfdKKQM+xuUZHJtMCoN2zBnUWZRVF3IUcxqLjh0= X-Received: by 2002:ab0:2881:: with SMTP id s1mr9271966uap.95.1581989123428; Mon, 17 Feb 2020 17:25:23 -0800 (PST) MIME-Version: 1.0 References: <20200217185437.GA20901@embeddedor> In-Reply-To: <20200217185437.GA20901@embeddedor> From: Masahiro Yamada Date: Tue, 18 Feb 2020 10:24:47 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] pinctrl: uniphier: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" Cc: Linus Walleij , "open list:GPIO SUBSYSTEM" , linux-arm-kernel , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 18, 2020 at 3:52 AM 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 Acked-by: Masahiro Yamada > --- > drivers/pinctrl/uniphier/pinctrl-uniphier-core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c > index 57babf31e320..ade348b49b31 100644 > --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c > +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c > @@ -29,7 +29,7 @@ struct uniphier_pinctrl_reg_region { > struct list_head node; > unsigned int base; > unsigned int nregs; > - u32 vals[0]; > + u32 vals[]; > }; > > struct uniphier_pinctrl_priv { > -- > 2.25.0 > -- Best Regards Masahiro Yamada