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.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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=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 94EB6C2BA2B for ; Sat, 11 Apr 2020 13:54:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 36EFE206E9 for ; Sat, 11 Apr 2020 13:54:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MifHQEFF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36EFE206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7960A8E00AA; Sat, 11 Apr 2020 09:54:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 747588E0007; Sat, 11 Apr 2020 09:54:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65C008E00AA; Sat, 11 Apr 2020 09:54:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id 4B7DE8E0007 for ; Sat, 11 Apr 2020 09:54:32 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F32A1824556B for ; Sat, 11 Apr 2020 13:54:31 +0000 (UTC) X-FDA: 76695719142.08.noise69_27878af5c4416 X-HE-Tag: noise69_27878af5c4416 X-Filterd-Recvd-Size: 6392 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Sat, 11 Apr 2020 13:54:31 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id t203so5061439wmt.2 for ; Sat, 11 Apr 2020 06:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZyPxhPtUJyOOdfz6RNXnEbqkmJLVwDA4m4uWT+JNL78=; b=MifHQEFFTJj9Q7YXv5uC3KpSFcrt3DFSSwXzGEgHi/k3nvjbPIJE6LQ3I2hiVy8lSs WjTpZbXe+Xqng6Qy2vRafHbxuUhpvGA06oFwaHAdx0THyxBgCVp/68jfp9FdTjFCM+/A HmyFwZMqlew9zJuvwI6qlXqfUiWCNLBEJ1YEYmqYe7j27os961gXocxyaWfZOxo9tLiD z07s8NiuvxQUZpZEjerKtINCoeNdsNmSCqY8RfH47wLCwgwjsh8i5IGGCqkFI3Me0L6O FKcr73rTHzkeQJ+W4JmLgKRu26/cF0cDtIH2ch3j4S7HZD26qiB/7mr95DS80fz7WHui Td9Q== 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:message-id:reply-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=ZyPxhPtUJyOOdfz6RNXnEbqkmJLVwDA4m4uWT+JNL78=; b=IaFdN/JsisSWmwBZYR1kE3P+H3MKL2iQjcCkqFbge+GF+5mUt0Ry9trt47G+tbFEvW 0S6eK69alHsq1/A2XOjC11wwnIN8PmtKiFov2X7N4CZPuJnj/612Si1h0noPloL0isCD m7RkZmVTxBH4oM5SCEpfggk9v0RwGCp4PLuBr2pp3u8mkETYIWNCb5sMDGSqkba9RPkx wjsjCeQjAJ6XMKHoFJDVdoshrcxcOfSBJE4CkB+XbiIWS+KGqEBO3HnBqdJlNRBcoGcm 4CxYk/DXvnyqsDx9A6z9hpt3t1EJCl473KTiwwBP4boTD1qS/seo6WQp2NzEUZ0tJerY AiGQ== X-Gm-Message-State: AGi0PubMcgSQp64OfeDx1ZqPFIImD9no+cTSOGCzf7zdTscmRrPHJcSw qQbLWd636unOsbPUbhzQxCM= X-Google-Smtp-Source: APiQypJm4MGcFCx0VYBPTJZ4uGMXmrSXNv5PNtkXWfY3TPL47Zfk3WaZl3T6jq+SDAnKlbH8itdNqg== X-Received: by 2002:a1c:7d90:: with SMTP id y138mr10641556wmc.121.1586613270320; Sat, 11 Apr 2020 06:54:30 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id s9sm9456954wmc.2.2020.04.11.06.54.29 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 11 Apr 2020 06:54:29 -0700 (PDT) Date: Sat, 11 Apr 2020 13:54:29 +0000 From: Wei Yang To: qiwuchen55@gmail.com Cc: akpm@linux-foundation.org, willy@infradead.org, david@redhat.com, richard.weiyang@gmail.com, mhocko@suse.com, pankaj.gupta.linux@gmail.com, yang.shi@linux.alibaba.com, cai@lca.pw, bhe@redhat.com, linux-mm@kvack.org, chenqiwu Subject: Re: [RESEND PATCH 1/3] mm: Replace zero-length array with flexible-array member Message-ID: <20200411135429.u36ii6vv5nkscxrz@master> Reply-To: Wei Yang References: <1586599916-15456-1-git-send-email-qiwuchen55@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1586599916-15456-1-git-send-email-qiwuchen55@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) 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 Sat, Apr 11, 2020 at 06:11:54PM +0800, qiwuchen55@gmail.com wrote: >From: chenqiwu > >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: chenqiwu The change looks good to me. Reviewed-by: Wei Yang >--- > include/linux/mm.h | 2 +- > include/linux/mmzone.h | 2 +- > include/linux/swap.h | 2 +- > 3 files changed, 3 insertions(+), 3 deletions(-) > >diff --git a/include/linux/mm.h b/include/linux/mm.h >index 5a32342..9831bb5 100644 >--- a/include/linux/mm.h >+++ b/include/linux/mm.h >@@ -1718,7 +1718,7 @@ struct frame_vector { > unsigned int nr_frames; /* Number of frames stored in ptrs array */ > bool got_ref; /* Did we pin pages by getting page ref? */ > bool is_pfns; /* Does array contain pages or pfns? */ >- void *ptrs[0]; /* Array of pinned pfns / pages. Use >+ void *ptrs[]; /* Array of pinned pfns / pages. Use > * pfns_vector_pages() or pfns_vector_pfns() > * for access */ > }; >diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h >index 1b9de7d..f6b9fa9 100644 >--- a/include/linux/mmzone.h >+++ b/include/linux/mmzone.h >@@ -1147,7 +1147,7 @@ struct mem_section_usage { > DECLARE_BITMAP(subsection_map, SUBSECTIONS_PER_SECTION); > #endif > /* See declaration of similar field in struct zone */ >- unsigned long pageblock_flags[0]; >+ unsigned long pageblock_flags[]; > }; > > void subsection_map_init(unsigned long pfn, unsigned long nr_pages); >diff --git a/include/linux/swap.h b/include/linux/swap.h >index b835d8d..e1bbf7a 100644 >--- a/include/linux/swap.h >+++ b/include/linux/swap.h >@@ -275,7 +275,7 @@ struct swap_info_struct { > */ > struct work_struct discard_work; /* discard worker */ > struct swap_cluster_list discard_clusters; /* discard clusters list */ >- struct plist_node avail_lists[0]; /* >+ struct plist_node avail_lists[]; /* > * entries in swap_avail_heads, one > * entry per node. > * Must be last as the number of the >-- >1.9.1 -- Wei Yang Help you, Help me