Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp512544pxk; Thu, 1 Oct 2020 07:53:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBkUmyQUDGubgT5U3LOliL9FoVds0VITsjhSht4cPLhfBmETXHJwdh6OkNTZcA5elOBPC9 X-Received: by 2002:a17:906:770c:: with SMTP id q12mr8386036ejm.518.1601564037563; Thu, 01 Oct 2020 07:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601564037; cv=none; d=google.com; s=arc-20160816; b=zmctu3on7Bp9PA33gFHN2oeQnxg7YPawwOtyQcX/kXJf7S/1a24G16cTYOqpJFSG7p cbLqlWKFD7EVRo6b5iJ8ylgnGrVoMFo7pCBjRf0UAxIExE086/8JBdjlLdF7npUicM6V u1qp8c+UEpu46yd8UZoo4cb3wrA7aT+S/BPMWDK8z9OzhBSnrKU06JqBEm2YzAgR9Uz1 WdDywwAFrdRVl7wHhAZ4ezXI8lqta32axE9o+tDBnZlee9Y3vmvZhZKA1D3rungQzpxt El+y9gJ84TlryjFA8ZSDQf4bii7SIDNZxhFnysYlVNpjThyTJUMkZBiHEfDJQNJfTI3s 30mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=hYUKpsQo34bDRRayTl2GkUdesjudOgTOdIKq+ZpVDqs=; b=mISa7/gDMWkW79Jl5VnUScafvJwIG0Y27XCC/oNF4QY/mDOE8H5t9JMPW/DDd6i8j5 v/Hqo14cWP9z1kcDycAZ5bD9ab80JI2GGE09blDiVdLyXQaFPiZf+gIBlW6e2eTady2y iGIKMOh27/YIom6gXjBV6c/2EHSDDwFaRNVH9ijl10r8Y/zKGQEaa1GGWjafmJTOrObY V6WImVjcjYG7LtlBt88i7PqnWEJaVTlUJMsx7xfgqkfxdMaCmrmCqHFr4xHJ870kVyoO PZQOFlkVJ8TCwI69KKRDwDDlZncuhnPHdqaH99NvwjqaVMPlxwwbo6dLRf5lqk3S0YYF 7kEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gGUnxK0b; 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 m3si3498806edp.33.2020.10.01.07.53.34; Thu, 01 Oct 2020 07:53:57 -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; dkim=pass header.i=@kernel.org header.s=default header.b=gGUnxK0b; 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 S1732462AbgJAOuY (ORCPT + 99 others); Thu, 1 Oct 2020 10:50:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:35746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732020AbgJAOuY (ORCPT ); Thu, 1 Oct 2020 10:50:24 -0400 Received: from embeddedor (187-162-31-110.static.axtel.net [187.162.31.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 57372207DE; Thu, 1 Oct 2020 14:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601563823; bh=t8pOQPAK1E1iVKSe7VQdeI0ZfBGmMSWbeGcL4rn3VQ0=; h=Date:From:To:Cc:Subject:From; b=gGUnxK0b49/8l/Ban0p0C38wTdm7W6PISlJuygjueQPbWtEPIqAAwuAvQb9tUuMfB Lc/AH8TjKM9lM8FQRlHBrdvbwNUG3zSIAQaHAMlU+Ls0GijEe150gfUm4z7O0r0iA5 caldDvo0ksv9T0h4JmNunFORCh9CkV/UtXYo5EW4= Date: Thu, 1 Oct 2020 09:56:08 -0500 From: "Gustavo A. R. Silva" To: Steve Wahl , Dimitri Sivanich , Russ Anderson , Darren Hart , Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Cc: x86@kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , Kees Cook , linux-hardening@vger.kernel.org Subject: [PATCH v2][next] x86/uv/time: Replace one-element array and save heap space Message-ID: <20201001145608.GA10204@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2]. struct uv_rtc_timer_head contains a one-element array cpu[1]. Switch it to a flexible array and use the struct_size() helper to calculate the allocation size. Also, save some heap space in the process[3]. [1] https://en.wikipedia.org/wiki/Flexible_array_member [2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays [3] https://lore.kernel.org/lkml/20200518190114.GA7757@embeddedor/ Reviewed-by: Kees Cook Build-tested-by: kernel test robot Link: https://lore.kernel.org/lkml/5f75bc0a.rQcNS6620b2eA74S%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva --- Changes in v2: - Modify changelog text (Thomas). - Add Reviewed-by and Build-tested-by tags. - Add a public link to the build-test results. arch/x86/platform/uv/uv_time.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/x86/platform/uv/uv_time.c b/arch/x86/platform/uv/uv_time.c index f82a1337a608..6c348c2d0def 100644 --- a/arch/x86/platform/uv/uv_time.c +++ b/arch/x86/platform/uv/uv_time.c @@ -52,7 +52,7 @@ struct uv_rtc_timer_head { struct { int lcpu; /* systemwide logical cpu number */ u64 expires; /* next timer expiration for this cpu */ - } cpu[1]; + } cpu[]; }; /* @@ -148,9 +148,8 @@ static __init int uv_rtc_allocate_timers(void) struct uv_rtc_timer_head *head = blade_info[bid]; if (!head) { - head = kmalloc_node(sizeof(struct uv_rtc_timer_head) + - (uv_blade_nr_possible_cpus(bid) * - 2 * sizeof(u64)), + head = kmalloc_node(struct_size(head, cpu, + uv_blade_nr_possible_cpus(bid)), GFP_KERNEL, nid); if (!head) { uv_rtc_deallocate_timers(); -- 2.27.0