From patchwork Tue Mar 31 06:08:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 11466763 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0EAD3912 for ; Tue, 31 Mar 2020 06:08:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C565F20748 for ; Tue, 31 Mar 2020 06:08:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u10SpUwd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C565F20748 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 06DAF6B0032; Tue, 31 Mar 2020 02:08:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 01FF76B0037; Tue, 31 Mar 2020 02:08:21 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4E9D6B006C; Tue, 31 Mar 2020 02:08:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0001.hostedemail.com [216.40.44.1]) by kanga.kvack.org (Postfix) with ESMTP id CDAE06B0032 for ; Tue, 31 Mar 2020 02:08:21 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8360F181AD0A2 for ; Tue, 31 Mar 2020 06:08:21 +0000 (UTC) X-FDA: 76654627602.30.grape98_831df072ffb42 X-Spam-Summary: 2,0,0,9f6a36f81c192854,d41d8cd98f00b204,qiwuchen55@gmail.com,,RULES_HIT:41:355:379:541:800:960:967:973:988:989:1260:1345:1437:1534:1542:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2525:2553:2559:2564:2682:2685:2693:2859:2901:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6117:6261:6653:7576:7903:9025:9413:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:12986:13138:13161:13229:13231:14181:14394:14721:21067:21080:21444:21451:21524:21627:21666:21972:30034:30054:30070:30090,0,RBL:209.85.215.193:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:212,LUA_SUMMARY:none X-HE-Tag: grape98_831df072ffb42 X-Filterd-Recvd-Size: 4918 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 31 Mar 2020 06:08:20 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id k191so9852404pgc.13 for ; Mon, 30 Mar 2020 23:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=hUeMyZXwhEwxA2pTgUgOHD5pi6gNLXqmjrpmUkxG2Wo=; b=u10SpUwd62wLoa1TJ5QtgY19S+dkESZxOeVrj6t8td1nsMtfM88WQLy2LkH4T93/99 XxIu0OV0m08I+kz8rjanmZzARPnVNo6Q+WaspddgJNM+BWDBKcB+CWxvQIZnstjt7aJB BSgwZMCX75jbmlGO7Y/mygs5ksGltt83rmquOUtl01i8Kfw7Bl2+Hvcya+XgC+4PflLR mSnJ41aRJg6uJccVw/bvn3s0xVetQ8A/mpbIW7L7PpgWIbUsx0t6gUnj5XDh0Y4Ze9Hf rtCtdLlTf1epYE4FMVH7xvLplTq9AAKR7uWMDwnhPLoyF+/Nb//kM5Lv074Hsti3rFyP qWFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=hUeMyZXwhEwxA2pTgUgOHD5pi6gNLXqmjrpmUkxG2Wo=; b=L7rlFRlq8BzhJ+SmQNf5qZlYvj/Ovn1z30k1yl7VmYoH+iLjOHE1jhBztKwK8CtsWW omj9v5uQuCtqJ0Yx/HNT44ELR9SV9nHRQ39hqTuf4tDHEMEPcSi38CFNa0T5QC5sh39P n90VinM1gj+OqNi6U6IDAlHOgFyfnZkzuju3GuNFysRqAhVtdZJi+jLOY5YoY/Tl05yk 4ZZz0GV1xFruEFREQJy2tbsH50poK8TmkY5gYzy+iWDeuclXtxbG45t/QuTPnQclmp9f VDjxyTI/KN69/fs+JeTuGCNGZFyFWSispsVGzDe8c4iXij4tRGOsLxPr99ZbqlfwSMrD RvZA== X-Gm-Message-State: AGi0PuY33Hvsrnr+16uAAhlA88bvv8+Gyh9ttnIND2un/f5iWQa/XeH9 CpSCuSRTCZWK2hTWRu8hAlc= X-Google-Smtp-Source: APiQypIja011cwNWQBvst72wEchEQZYXlW1UWUoqYEzL+DRKK5N1s3S/HtkCWiKr76fFcbsie+lyyg== X-Received: by 2002:a63:a35a:: with SMTP id v26mr2900840pgn.40.1585634899842; Mon, 30 Mar 2020 23:08:19 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id k5sm10834351pgl.3.2020.03.30.23.08.18 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 30 Mar 2020 23:08:19 -0700 (PDT) From: qiwuchen55@gmail.com To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, chenqiwu Subject: [PATCH] mm: Replace zero-length array with flexible-array member Date: Tue, 31 Mar 2020 14:08:14 +0800 Message-Id: <1585634894-4276-1-git-send-email-qiwuchen55@gmail.com> X-Mailer: git-send-email 1.9.1 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: 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 --- include/linux/mm.h | 2 +- include/linux/mmzone.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index c54fb96..8dc699a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1528,7 +1528,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 462f687..0e3c685 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1187,7 +1187,7 @@ static inline unsigned long section_nr_to_pfn(unsigned long sec) struct mem_section_usage { DECLARE_BITMAP(subsection_map, SUBSECTIONS_PER_SECTION); /* 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);