From patchwork Fri Oct 30 20:58:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 11870817 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 B4CB492C for ; Fri, 30 Oct 2020 20:59:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 58328208B6 for ; Fri, 30 Oct 2020 20:59:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58328208B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3F90D6B0036; Fri, 30 Oct 2020 16:59:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3AC8F6B005C; Fri, 30 Oct 2020 16:59: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 29A8E6B005D; Fri, 30 Oct 2020 16:59:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0199.hostedemail.com [216.40.44.199]) by kanga.kvack.org (Postfix) with ESMTP id EF2096B0036 for ; Fri, 30 Oct 2020 16:59:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8CD60181AEF1A for ; Fri, 30 Oct 2020 20:59:20 +0000 (UTC) X-FDA: 77429807280.22.heart68_030a1fd27299 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 77DDB18038E67 for ; Fri, 30 Oct 2020 20:59:20 +0000 (UTC) X-Spam-Summary: 1,0,0,73ec017884bccb3b,d41d8cd98f00b204,dennisszhou@gmail.com,,RULES_HIT:41:355:379:541:800:960:967:973:988:989:1260:1311:1314:1345:1437:1515:1534:1541:1711:1730:1747:1777:1792:2194:2199:2393:2525:2559:2563:2682:2685:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3867:3870:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:5007:6261:7903:9025:9036:10004:11026:11232:11233:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12696:12737:12895:12986:13069:13311:13357:13894:14181:14384:14394:14721:21080:21444:21451:21626:21811:30054,0,RBL:209.85.222.66:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y8i6mt7qsuzo86gdu49sk8aifqrypw3kg9f4bcdo4hdjktopdxiwz8wyebh3s.gdgdkutub71j418n45ez5j7td37nb9djnwg68qdhuwesm881ai339c8bedkrcxb.1-lbl8.mailshell.net-223.238.255.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:66,LUA_SUMMAR Y:none X-HE-Tag: heart68_030a1fd27299 X-Filterd-Recvd-Size: 3655 Received: from mail-ua1-f66.google.com (mail-ua1-f66.google.com [209.85.222.66]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 20:59:20 +0000 (UTC) Received: by mail-ua1-f66.google.com with SMTP id 52so2135916uaj.4 for ; Fri, 30 Oct 2020 13:59:19 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=0UF2Pmf+rwRBHY8l9mzh5Ann9thyXoIS3meDLoOTDgU=; b=CHkLDkgfJPgWXQafKM7aDNY4m2bKE4WzonFK/2fS57FCJtGFURbLaTO4FIP09LUjx0 ePHayeVbBgqUhGclZ7fyJAva3yPZ3ZJL03VdavnmlGhPK3oHL1c6ogAE6oAr2RA4fEjr 98hQ6JTRarvl+R5ixyadSxrRiY5kO9/qGTwbMxQHXGJIgCmcQsvXw0g/OkVuQwkg0PkZ xnwQUG06UfarOII1AC4BHB+eZhBW0J9uCxlfNhLTiHmlkZWESlckW1NA3H890jpBAJOP StUOJXPGr6AmmC5xHrvYTcQ+YCfGqelXeH8oixeS3uPEDV8uv9r/PQciyAq6QIw1h7cd 1nTw== X-Gm-Message-State: AOAM530AeVARemVj6aDeAc086cbNbXdMgb3m+T3IvRWzuymagBaKef81 uAdsgX/DhH44lEnG5dwui44= X-Google-Smtp-Source: ABdhPJyH72AuFmsvzp0sbpVX9j78iQsXQAIeLz8oNvMQJ3HePx7NsJR7CYskCVyb7OINrFDNoMoQWg== X-Received: by 2002:a9f:2212:: with SMTP id 18mr3048462uad.89.1604091559492; Fri, 30 Oct 2020 13:59:19 -0700 (PDT) Received: from killington.c.googlers.com.com (239.145.196.35.bc.googleusercontent.com. [35.196.145.239]) by smtp.gmail.com with ESMTPSA id w123sm874205vke.26.2020.10.30.13.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 13:59:18 -0700 (PDT) From: Dennis Zhou To: Tejun Heo , Christoph Lameter Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH] percpu: convert flexible array initializers to use struct_size() Date: Fri, 30 Oct 2020 20:58:46 +0000 Message-Id: <20201030205846.1105106-1-dennis@kernel.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog MIME-Version: 1.0 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: Use the safer macro as sparked by the long discussion in [1]. [1] https://lore.kernel.org/lkml/20200917204514.GA2880159@google.com/ Signed-off-by: Dennis Zhou Reviewed-by: Gustavo A. R. Silva --- I'll apply it to for-5.10-fixes. mm/percpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index 66a93f096394..ad7a37ee74ef 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1315,8 +1315,8 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr, region_size = ALIGN(start_offset + map_size, lcm_align); /* allocate chunk */ - alloc_size = sizeof(struct pcpu_chunk) + - BITS_TO_LONGS(region_size >> PAGE_SHIFT) * sizeof(unsigned long); + alloc_size = struct_size(chunk, populated, + BITS_TO_LONGS(region_size >> PAGE_SHIFT)); chunk = memblock_alloc(alloc_size, SMP_CACHE_BYTES); if (!chunk) panic("%s: Failed to allocate %zu bytes\n", __func__, @@ -2521,8 +2521,8 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, pcpu_unit_pages = ai->unit_size >> PAGE_SHIFT; pcpu_unit_size = pcpu_unit_pages << PAGE_SHIFT; pcpu_atom_size = ai->atom_size; - pcpu_chunk_struct_size = sizeof(struct pcpu_chunk) + - BITS_TO_LONGS(pcpu_unit_pages) * sizeof(unsigned long); + pcpu_chunk_struct_size = struct_size(chunk, populated, + BITS_TO_LONGS(pcpu_unit_pages)); pcpu_stats_save_ai(ai);