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=-8.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 34A5FC43331 for ; Mon, 30 Mar 2020 21:30:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C541206CC for ; Mon, 30 Mar 2020 21:30:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728939AbgC3VaV convert rfc822-to-8bit (ORCPT ); Mon, 30 Mar 2020 17:30:21 -0400 Received: from lithops.sigma-star.at ([195.201.40.130]:52900 "EHLO lithops.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728047AbgC3VaV (ORCPT ); Mon, 30 Mar 2020 17:30:21 -0400 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id D0E3C60D0872; Mon, 30 Mar 2020 23:30:18 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id DLFK5jK_AhlB; Mon, 30 Mar 2020 23:30:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id E572C6091853; Mon, 30 Mar 2020 23:30:15 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7sb4cXn88cVf; Mon, 30 Mar 2020 23:30:15 +0200 (CEST) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 634AE60D086D; Mon, 30 Mar 2020 23:30:15 +0200 (CEST) Date: Mon, 30 Mar 2020 23:30:14 +0200 (CEST) From: Richard Weinberger To: "Gustavo A. R. Silva" Cc: Miquel Raynal , Vignesh Raghavendra , linux-mtd , linux-kernel Message-ID: <2093889665.60398.1585603814979.JavaMail.zimbra@nod.at> In-Reply-To: <20200319224435.GA25590@embeddedor.com> References: <20200319224435.GA25590@embeddedor.com> Subject: Re: [PATCH][next] mtd: ubi: ubi-media.h: Replace zero-length array with flexible-array member MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF68 (Linux)/8.8.12_GA_3809) Thread-Topic: ubi-media.h: Replace zero-length array with flexible-array member Thread-Index: 0me70WajGRQMgkZ2Z4V30jvr1xIZqw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Ursprüngliche Mail ----- > Von: "Gustavo A. R. Silva" > An: "richard" , "Miquel Raynal" , "Vignesh Raghavendra" > CC: "linux-mtd" , "linux-kernel" , "Gustavo A. R. Silva" > > Gesendet: Donnerstag, 19. März 2020 23:44:35 > Betreff: [PATCH][next] mtd: ubi: ubi-media.h: Replace zero-length array with flexible-array member > 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 Applied. Thanks! Thanks, //richard