Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp273284ybj; Fri, 8 May 2020 11:28:16 -0700 (PDT) X-Google-Smtp-Source: APiQypKrL350c/9fGHsRJJWTlHgHqS1MIKl9wid8pZuhD+7yDkyMOZ09IBeu3mlFfp7cxXyoY+Xg X-Received: by 2002:a05:6402:c84:: with SMTP id cm4mr3173190edb.316.1588962496599; Fri, 08 May 2020 11:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588962496; cv=none; d=google.com; s=arc-20160816; b=iKDm232g9H01yPHszMKgw05+prqDIYMmcis3633ewj594HgFga+ZJY8JUSAX3J4BsA xPkRoxSsN2VHUH377PiO+bTSAMWcY2H4zW6wMujlBRZr/TrWvsylM9TOm+ZZPOnRZn8h uaznFxynQRJZ612mxzJ5HY57P66gHMJQiwmembJMYndT3nDNlUPuB3NyWp4A9nHSSQY3 ssx5VBofrP54HwVMXNMMzJtMwKvhdWJOTj7THIzSuNoQX9YgbzcUlPDz/T11buRcmlow 4n2SfrmTn2qLX4ImPzp3gPxVDaeX9WCojbp2R/Y70GwqBMEuiCRtoU9E48ylRYjU7X39 CkNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=yGCB9uiSAoSgGC4H6BsrZxK0G4i0rxwy4q1TeUNsNGY=; b=sPB2WNjLzIng7/ZRqKQrb7A9Uk5glHDQR2ndz+C/9qG8Nhat5mquR5at9LX+C5baNK 513HNm3wVHhUDSV/wAzT2KjwGqgHe1Vn3SgE79xSw9x8RTaPTPQ8Ely+yr/D0J+FRQH+ qJ04H8uAJRiq3ExU/9Vw3ICKRM+5mITooXsL6BqGG5sg6MrQ6joXuhkkkdrgY8IU2rnO 5tUaevQrjOUtDR8ZmX12Wd1zdCElb7TxHuGy3mtalsB6mpjgtQI25htn6hnRMBSsras2 2klNIyA03EObVoKFXH9rO+3tQGllyS5rnDo3+/bQk2BD+adCmM13Yt3Qd5GfT7MadOuD 8y+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uoq8L2xf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ck5si1433688ejb.12.2020.05.08.11.27.53; Fri, 08 May 2020 11:28:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uoq8L2xf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727030AbgEHS03 (ORCPT + 99 others); Fri, 8 May 2020 14:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726817AbgEHS02 (ORCPT ); Fri, 8 May 2020 14:26:28 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B92F2C061A0C for ; Fri, 8 May 2020 11:26:28 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id f8so1106301plt.2 for ; Fri, 08 May 2020 11:26:28 -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=Rz5Hz2EHqGo9oB1Sz48p8YenmG0jSiVHV6Ygl8KLZbfs5EKZ0CYpHM0zN2v3Bddd74 Kf8NjMwdLeZM3DYo7pU/byFAFWar05D4AMoXl5SREpP6l/TwBh+AfIMYJtySd2iroyxd kRVw30CwD4sNC2uar4bnpGgATe0kvxgDuScDGgFmT8VAbyLfwfyRM4uE2GcL/F6xu6tF EZQllg6ICsOvs4qcXjIcqORR8UCgqFBuDYyNuPz6fJtkE1Wtw1ReNElVznMbAjPDeJs8 Y2yJJWgzxIB/NNMKgfIWkTUSZpvk82Q5TrrIihJey58V9hWZw2uDip+Hz0vDM7fBy22c XW4A== X-Gm-Message-State: AGi0PuZZs/N9lqkDYXLML5VN5kMcKki+9lwU1SmBFH0CvSPSH+Y8p2Ys zqPnB4LtWg74x5ohNCEnpbNo/w== 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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