Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1101973ybh; Tue, 10 Mar 2020 14:46:49 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvbx550K6WKN2Qswz3kzBWVqRnfKF6Iejit9DiZkbxtCiNQXgyuE1RjWDrznepIDLedWuwz X-Received: by 2002:aca:1a17:: with SMTP id a23mr2627318oia.84.1583876809519; Tue, 10 Mar 2020 14:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583876809; cv=none; d=google.com; s=arc-20160816; b=qGgHJO3mwktpoMOWR7MQMQ3E7oOAPNSog/spMb0uBKuOhrX7JCRFYbM8jt6qErG914 IlUk8h7sNOukWOb9Tty+teQU3RCFe1WwdAbfNHaT02EH59C4OhSLpEwQRATdR/wFm3lR x7NbV2OyUi9AmkxPgypCAswIqm0TCLPMxVXv/Kp6TzQl59YZEnfS+HOcOwl86Z3dHfkW UXTSDoYv4bJC+Wd6nqEIpaKcpVsKvT/SA0V77NlSbxUI3i+FJroyoki+QxZ6a19Xf4li 8k+X9XSymqU2sehjqzCOwl6rwpVrykSkNkqw7k48VBrDumD0UFPJivJHy3VDZZ+88qMx uj/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=yA199LVIr+KxFNzyUvEgXQep4MXDLiCOADA3vFqZe+I=; b=qLBI3nXjQojvgCv+uFHGJ6XZKgTb6oei62T7TkW9pGCd8ohDYWDPdNG7Ua0MsYbEo/ RER5PfiSLwAEtqoEVXyOG/CY+nKXXmbq4xs2x3t4P494FaaZ2m3ULVYRX3rURRFa879Q E7QIhC8XTXae/WogYm+Z6i8FNDoBzbBB6QTeemXswjk1MHwuuruWiYPFlqykdsUxGm4/ nBA6EyvGxKrvnwOFgK5Ufgj5FsRD9XaI1hWOcO3OIN9dbWWVsRc0bQzYd4zbRXllFsps Ro2UX6O9+d2B3ud3MJZmfk8v8BihjpDsRfYY6rkK9AgPvwNhQBJ4usJ7DjujN6hdr01S 9m/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kTqCUIIN; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16si9051843otm.231.2020.03.10.14.46.36; Tue, 10 Mar 2020 14:46:49 -0700 (PDT) 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=@kernel.org header.s=default header.b=kTqCUIIN; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727311AbgCJVpA (ORCPT + 99 others); Tue, 10 Mar 2020 17:45:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:39240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbgCJVo7 (ORCPT ); Tue, 10 Mar 2020 17:44:59 -0400 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A1EB6222C4; Tue, 10 Mar 2020 21:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583876699; bh=TSDq+N2Xq2WKyqJ3qt/mNkLFgoX8wRRyVlS3iwmICTU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=kTqCUIINSdaOLvEUJkpfj+zxHUv2VmENXtessPZ2QSqtxfYpAq5PyMDLChRa7IqcF zWCZ64h7LizTEN6hwinBZyENwh9IZK7iYBqRcrgcRP0RKjvTgQ/FST6PwoOO1O5bEI SvcOgw+uYfTECt4ylGFXYIPw1avWaRF9zQ/eMPqo= Received: by mail-lf1-f45.google.com with SMTP id g4so5916467lfh.2; Tue, 10 Mar 2020 14:44:58 -0700 (PDT) X-Gm-Message-State: ANhLgQ24Tqg97JtRVTaZ6bI/MIqDQKpbJFQlcIFyzA1baEnH0H2dGIOl WW/GiqKhgFTEzUb1UKC6ImPuWSXbA2SLAGLNjp0= X-Received: by 2002:ac2:4116:: with SMTP id b22mr90742lfi.172.1583876696820; Tue, 10 Mar 2020 14:44:56 -0700 (PDT) MIME-Version: 1.0 References: <20200226221804.GA8564@embeddedor> In-Reply-To: <20200226221804.GA8564@embeddedor> From: Song Liu Date: Tue, 10 Mar 2020 14:44:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH][next] md: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" Cc: Alasdair Kergon , Mike Snitzer , open list , linux-raid Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 26, 2020 at 2:16 PM 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 For md part: Acked-by: Song Liu Alasdair and Mike, would you like to route the patch via dm tree? Thanks, Song