Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp7151691ybf; Fri, 6 Mar 2020 11:21:35 -0800 (PST) X-Google-Smtp-Source: ADFU+vvT+MPb5TPS2BEsXc3H8bxjbt37QB67UGem+LL20ytE8/kDXjd6clUW/6vwyDXabQk4WAVS X-Received: by 2002:a9d:6443:: with SMTP id m3mr3760817otl.20.1583522495481; Fri, 06 Mar 2020 11:21:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583522495; cv=none; d=google.com; s=arc-20160816; b=YaWiC8h9HmzT8Joipqcmjq5qetU4AyeEDedh2lC9KXF4i4o6mDUcIUuL4RqmzPg9vA IEzR5v8na0eNSxKCIt8Kk3TpzDTLrHYQehCNvdEHi8eCExYP0pEog6YvBDCVXMz5rpCy h6uYIYtLu05bJMh6DQx02iSvE05oa5Zu3t5DfwdoSUR0SgSHJXYiHnQjQkGu4az+QeXQ 5/ZroblerZrGrCprhfhg3FTtNSkoRc6IY8gzx1HQbZIOIIYrBQR0VoTxHIZDDytptE+8 6Tr3RnK6mM+mBQbkqBtxpXwxDIafL2/NfdTmsPT6JCOk6Cc4oEx0v+mRk2/8tUe0ztYq sL6A== 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:message-id :in-reply-to:date:references:subject:cc:to:from:dkim-signature; bh=t0H1vkQmPmzBSwnwF8uzFghL+fUOg4p2orNUbsJWNSo=; b=hbcMdF6eo+wkNoJ6M05uyx/m78t6IH7qnP9lSIbo0l0YFBPJIRob+rSffR0YT74YEa 5xxVpRTjLrY4YRzRQfngGc4RrKV/PVEBduBhKg8xVXn0zePlqKEJXHFPKjnfESp/rt49 MZh6RpWlinVzzn5cc65MoBoOXNtCGdns8+4im+IjN7T0VYwq0I3oM35u4Z6m4+AjycMT JSyJWX3Lqol0FThQtaoKa7pXUxq0XkCGhxIGJPxN5O8S/8nHQD6CX3AeBttHhvTPU8dV 7IPHu25zmyxAGAIRyQTocYfPQj19m1Oy+MbOCMxdhVMVYJPtWBTKymsOtE+UsWPHJkPD ELrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TNBW1Hsq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j36si1873220ota.58.2020.03.06.11.21.22; Fri, 06 Mar 2020 11:21:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TNBW1Hsq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726251AbgCFTU6 (ORCPT + 99 others); Fri, 6 Mar 2020 14:20:58 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:38993 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726171AbgCFTU5 (ORCPT ); Fri, 6 Mar 2020 14:20:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583522457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=t0H1vkQmPmzBSwnwF8uzFghL+fUOg4p2orNUbsJWNSo=; b=TNBW1Hsq8NSExzCYqVWyzyLM4bzRh3m1on8fa7YBOiTQD9afbNlLYezFoc9zckK6FOpUe5 BtIy+rcsbrHT2jH0YebK30JAiMNQ77Chnnutn69vJIhB7HbndOhXRQY2NfUkRmy6JzMkag rTPUqDBMA9LmH9OExkSdH/YgJxQb+l4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-307-QzDKrNssNASCS4pYajeMpQ-1; Fri, 06 Mar 2020 14:20:53 -0500 X-MC-Unique: QzDKrNssNASCS4pYajeMpQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1F30190D344; Fri, 6 Mar 2020 19:20:51 +0000 (UTC) Received: from segfault.boston.devel.redhat.com (segfault.boston.devel.redhat.com [10.19.60.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0932C90795; Fri, 6 Mar 2020 19:20:50 +0000 (UTC) From: Jeff Moyer To: "Gustavo A. R. Silva" Cc: Alexander Viro , Benjamin LaHaise , linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] aio: Replace zero-length array with flexible-array member References: <20200306164446.GA21604@embeddedor> X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 Date: Fri, 06 Mar 2020 14:20:49 -0500 In-Reply-To: <20200306164446.GA21604@embeddedor> (Gustavo A. R. Silva's message of "Fri, 6 Mar 2020 10:44:46 -0600") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Gustavo A. R. Silva" writes: > 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 > --- > fs/aio.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/aio.c b/fs/aio.c > index 94f2b9256c0c..13c4be7f00f0 100644 > --- a/fs/aio.c > +++ b/fs/aio.c > @@ -68,7 +68,7 @@ struct aio_ring { > unsigned header_length; /* size of aio_ring */ > > > - struct io_event io_events[0]; > + struct io_event io_events[]; > }; /* 128 bytes + ring size */ > > /* Acked-by: Jeff Moyer