Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1596725pxx; Fri, 30 Oct 2020 14:01:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzomNK22zvhXLir5Pnrb0H4wyC4rCP88GJzc8gNHV18dgYw6znBT1OIc7N/KJWeq5ajiWYV X-Received: by 2002:a17:906:76d3:: with SMTP id q19mr3496584ejn.162.1604091689054; Fri, 30 Oct 2020 14:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604091689; cv=none; d=google.com; s=arc-20160816; b=kG6986K+WXhpd4ZDo8Zym1kcYPuiuJDL2Qu1B6FzxN4S+yeDyud38c0mn3WjPm+AOz ec3VxKCvU4EoujM/tM4KejJ4kAkZl5FvUZrviFPyb0riYkNtVYr8nLZFCeKnt32yL1Bl N4m3ScS9yqQS9eeRPkuksq0ZRlf4DnsNAoozd5CSzFqcHc+bpfvBMvGVM5zTaPnY/VBG xON1wmr2UYsOnE5jbpfGqcd24owbuqpy/IyzddlcJhiLsu1Mr37W61SYIklvWLGBN98g ouXAY+11iz3ENvVWXL0MHTCTWlTxWaVBklKugxw1LrBMeI9lHW34mBvMwKQNSrP2OA69 eGhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0UF2Pmf+rwRBHY8l9mzh5Ann9thyXoIS3meDLoOTDgU=; b=v1vp068SHFgRe3DB4bSA8g+Tm3JfkVCfpceTrU1/sPsqK2fvD6eSzTZYxFWg18hTOE L2/oSx1x7qmmhENDT1GzflhM3SVoT8uMoHuACCSKLqGU/1ZaHIek/pkTmUzZg0c7BHfH i44MN/kVo6e6/sm0mFbGR09WpVjgmQf5nNcNuoAEKf9G3AB9mWNUGnv1KgbFQ247m71L wByYskJfYL2aMQlS+NnFFSE6k+qVTwDCn3vUaW93VMa2oAIMCr7myCWj7NqAyB5tXWfJ Iz85lAu38h/pwDqFG+HeQ4RfmS+q3ZgjnRpvpC3RKwWzM9yJ7e6m0yWQ3nKArVGRRZfv SNFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id h13si5343414edt.581.2020.10.30.14.01.05; Fri, 30 Oct 2020 14:01:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727536AbgJ3U7V (ORCPT + 99 others); Fri, 30 Oct 2020 16:59:21 -0400 Received: from mail-ua1-f68.google.com ([209.85.222.68]:35655 "EHLO mail-ua1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbgJ3U7U (ORCPT ); Fri, 30 Oct 2020 16:59:20 -0400 Received: by mail-ua1-f68.google.com with SMTP id f20so2139459uap.2 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=iC5u3aBoMuTm4wozxh9IV2gbv/eULJVvGJwWISRtlH6/QZ/5QTNObNPgcRygnPoup2 gJWynJb0Vzl7r/V/GgAPFNSXlWHl5B4S03tw8+ncgQxSD/z+KPAoeu10j/zc0m6Dm44n oqeYKNPVGz4Qi8Vm9tkC+G7kQWnu2guC+ftnk1apgb4XBkO0Erzmv5gD9QhZ8Id/fOKs XTDydJGK0o9drRmRXXX8tN+r2E09Qt+ivQKlzJ+Zn8n6pW2PF1JEmvPIQBpE5g9Co9vg 0ZWH+CfvBi9Wu3t63KanwE32eTBNGwfVaezmN5leKDkEKr02TcRy5C+1HmLlu+V5mM3N Oj4A== X-Gm-Message-State: AOAM533sEhzdyBLMNYl2xUAmGQ4yfSWjlJHCq1wMFMbt5Sv5J8oHzKpl HyK1dWdtCuPVJOnm0YY34NY= 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.29.1.341.ge80a0c044ae-goog