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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 76F60C43603 for ; Mon, 16 Dec 2019 17:59:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BB7E21582 for ; Mon, 16 Dec 2019 17:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576519160; bh=2JwDM7TaPeUxhQ0KNFjZ43IsJOHsVpWhexDGziKV0Ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=byEpGr4Lxu7t8UZo+yn7iBsCXcxnih2kKHiYVuPJ/h16/SW13ASbYcgRMwzdalSVP FZSnBhd5yKaSVLWhlXMguC6/pxO037z/kdRpj6ZsRqZemY4QXRnj9V7hmko+22CrIe +e5lKdPcJM2NDunOo50CI2UfyMgLsorAUmr/gQso= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726696AbfLPR7T (ORCPT ); Mon, 16 Dec 2019 12:59:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:59874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728181AbfLPR7O (ORCPT ); Mon, 16 Dec 2019 12:59:14 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 44ED221582; Mon, 16 Dec 2019 17:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576519153; bh=2JwDM7TaPeUxhQ0KNFjZ43IsJOHsVpWhexDGziKV0Ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gGlZOQvJetKflbwAK8hr3OxFcs6F56wWurq3NykBgZY9kY0I1QOvsfdBGSAMqaaVv Syb3Xj7TCawnR7Dm1fCU9sHOfXKy6o/aYTVLxsI/MaSYa5EYbeiBw/tA9zk6h1sjjq hoSdwc1euwBJtxr22Iqw9ogKdxVLBKfuUKuCXmQk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Hubbard , Viresh Kumar , "Rafael J. Wysocki" Subject: [PATCH 4.14 216/267] cpufreq: powernv: fix stack bloat and hard limit on number of CPUs Date: Mon, 16 Dec 2019 18:49:02 +0100 Message-Id: <20191216174914.391297366@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191216174848.701533383@linuxfoundation.org> References: <20191216174848.701533383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Hubbard commit db0d32d84031188443e25edbd50a71a6e7ac5d1d upstream. The following build warning occurred on powerpc 64-bit builds: drivers/cpufreq/powernv-cpufreq.c: In function 'init_chip_info': drivers/cpufreq/powernv-cpufreq.c:1070:1: warning: the frame size of 1040 bytes is larger than 1024 bytes [-Wframe-larger-than=] This is with a cross-compiler based on gcc 8.1.0, which I got from: https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.1.0/ The warning is due to putting 1024 bytes on the stack: unsigned int chip[256]; ...and it's also undesirable to have a hard limit on the number of CPUs here. Fix both problems by dynamically allocating based on num_possible_cpus, as recommended by Michael Ellerman. Fixes: 053819e0bf840 ("cpufreq: powernv: Handle throttling due to Pmax capping at chip level") Signed-off-by: John Hubbard Acked-by: Viresh Kumar Cc: 4.10+ # 4.10+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/powernv-cpufreq.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) --- a/drivers/cpufreq/powernv-cpufreq.c +++ b/drivers/cpufreq/powernv-cpufreq.c @@ -1002,9 +1002,14 @@ static struct cpufreq_driver powernv_cpu static int init_chip_info(void) { - unsigned int chip[256]; + unsigned int *chip; unsigned int cpu, i; unsigned int prev_chip_id = UINT_MAX; + int ret = 0; + + chip = kcalloc(num_possible_cpus(), sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; for_each_possible_cpu(cpu) { unsigned int id = cpu_to_chip_id(cpu); @@ -1016,8 +1021,10 @@ static int init_chip_info(void) } chips = kcalloc(nr_chips, sizeof(struct chip), GFP_KERNEL); - if (!chips) - return -ENOMEM; + if (!chips) { + ret = -ENOMEM; + goto free_and_return; + } for (i = 0; i < nr_chips; i++) { chips[i].id = chip[i]; @@ -1027,7 +1034,9 @@ static int init_chip_info(void) per_cpu(chip_info, cpu) = &chips[i]; } - return 0; +free_and_return: + kfree(chip); + return ret; } static inline void clean_chip_info(void)