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=-13.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 E2D48C3F2D1 for ; Tue, 3 Mar 2020 16:45:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C209020870 for ; Tue, 3 Mar 2020 16:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbgCCQpk (ORCPT ); Tue, 3 Mar 2020 11:45:40 -0500 Received: from fieldses.org ([173.255.197.46]:37318 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726899AbgCCQpk (ORCPT ); Tue, 3 Mar 2020 11:45:40 -0500 Received: by fieldses.org (Postfix, from userid 2815) id 24CC11D3E; Tue, 3 Mar 2020 11:45:40 -0500 (EST) Date: Tue, 3 Mar 2020 11:45:40 -0500 From: "J. Bruce Fields" To: "Gustavo A. R. Silva" Cc: Trond Myklebust , Anna Schumaker , Chuck Lever , "David S. Miller" , Jakub Kicinski , linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] svcrdma: Replace zero-length array with flexible-array member Message-ID: <20200303164540.GB19140@fieldses.org> References: <20200217200500.GA7628@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200217200500.GA7628@embeddedor> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Applying for 5.7, thanks.--b. On Mon, Feb 17, 2020 at 02:05:00PM -0600, 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 > --- > net/sunrpc/xprtrdma/svc_rdma_rw.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/sunrpc/xprtrdma/svc_rdma_rw.c b/net/sunrpc/xprtrdma/svc_rdma_rw.c > index 48fe3b16b0d9..003610ce00bc 100644 > --- a/net/sunrpc/xprtrdma/svc_rdma_rw.c > +++ b/net/sunrpc/xprtrdma/svc_rdma_rw.c > @@ -41,7 +41,7 @@ struct svc_rdma_rw_ctxt { > struct rdma_rw_ctx rw_ctx; > int rw_nents; > struct sg_table rw_sg_table; > - struct scatterlist rw_first_sgl[0]; > + struct scatterlist rw_first_sgl[]; > }; > > static inline struct svc_rdma_rw_ctxt * > -- > 2.25.0