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=-17.9 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL 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 9B251C47257 for ; Fri, 8 May 2020 18:26:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 637C721974 for ; Fri, 8 May 2020 18:26:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uoq8L2xf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 637C721974 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0E7218E0005; Fri, 8 May 2020 14:26:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 070248E0003; Fri, 8 May 2020 14:26:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA1C98E0005; Fri, 8 May 2020 14:26:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id D2BC88E0003 for ; Fri, 8 May 2020 14:26:29 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8DD3C8248047 for ; Fri, 8 May 2020 18:26:29 +0000 (UTC) X-FDA: 76794382098.20.rake28_38a84a04fd33a X-HE-Tag: rake28_38a84a04fd33a X-Filterd-Recvd-Size: 4858 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Fri, 8 May 2020 18:26:29 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id m7so1101501plt.5 for ; Fri, 08 May 2020 11:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=yGCB9uiSAoSgGC4H6BsrZxK0G4i0rxwy4q1TeUNsNGY=; b=uoq8L2xfIgd2892o6m3BUUi737IcFRPoLZTj+nW/FpAQrfQJx+ZJ4Dh/dbRw2FfVZm /eK9PiVqICu093YxzS2CehKztY0h+2iyv9KfkMR6KghQdrOQVCEMyDpv9yfeX4zdQJqW jEJFzHmxVC17Sf/7BHUJR8OHAii3P7i/PqI7yaL+WjAzSK8//WqR01/y5Ko0JgxthwVK VEEyLrLdpFi3jdMTcBx99l1mriCbrlnN5R+xZv+fMrUMW3iUHlLc48GQaOenmUq9DElC DO1lAR1NrwVpCLRCkYsSF3nEw6hzuVhChkm19nyhuIIKFSzBel6juHo04mL+XS15vQym ewrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=yGCB9uiSAoSgGC4H6BsrZxK0G4i0rxwy4q1TeUNsNGY=; b=n7CKKiifgYtUrWug2Hf4zlqr0mKBHC4oytBe7Tz7GmAJgNW0cK/hE5dlDwPTy83sDe U70ZI6kVBKE41W3HYlDVXngdhw3xb6XR9HdSKYFfY2/uVi2pklzbEXY9tqGa21FIsLq5 h9VKngVYnK2h63uj759uRWuPYogtMbsLCQwm9mKlxrfObhqydNSH6T47yhIi2on1CDjP 26bcAtferlbOr2gtLRjA1dow4kxzC4AP9341Xx/oHAl+yUBPMX0wutadPG+DU6+n7frV KLsZbw/uDj7+cqTdCLmy6wDwg0OwkLtVXkS/RARwo4vb2OxeCtMuw1rZWm8WKDWFkL1o yblw== X-Gm-Message-State: AGi0PubEZZtLTwwcmNUjU66QhxBZ3zUUyhH6pFC2VnrRZQm/1j2/4fCj easNRx/z3KjjYNFOmFpQ8vRVPg== X-Google-Smtp-Source: APiQypK/tpjddlgAo4yz9wK1JF1/Zf8llc0RjiRlIYXqnp9UVnGBFIfNA7ECtSeVGwWx7bVOCoseIg== X-Received: by 2002:a17:902:bcc4:: with SMTP id o4mr3353901pls.275.1588962387978; Fri, 08 May 2020 11:26:27 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id 131sm1805269pgg.65.2020.05.08.11.26.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2020 11:26:27 -0700 (PDT) Date: Fri, 8 May 2020 11:26:26 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: "Gustavo A. R. Silva" cc: Andrew Morton , Christoph Lameter , Pekka Enberg , Joonsoo Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] slab: Replace zero-length array with flexible-array In-Reply-To: <20200507192204.GA16270@embeddedor> Message-ID: References: <20200507192204.GA16270@embeddedor> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, 7 May 2020, 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] > > sizeof(flexible-array-member) triggers a warning because flexible array > members have incomplete type[1]. There are some instances of code in > which the sizeof operator is being incorrectly/erroneously applied to > zero-length arrays and the result is zero. Such instances may be hiding > some bugs. So, this work (flexible-array member conversions) will also > help to get completely rid of those sorts of issues. > > 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: David Rientjes