Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp258493imw; Tue, 12 Jul 2022 19:20:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uf2Meh+4xcP28opy4DDMHULNyw79yF+fgL7GxTbguMZ7tpqjY5HOPabMzIYBkBCUxDSzg3 X-Received: by 2002:a05:6402:f2a:b0:43a:9d53:e0e6 with SMTP id i42-20020a0564020f2a00b0043a9d53e0e6mr1632594eda.394.1657678822971; Tue, 12 Jul 2022 19:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657678822; cv=none; d=google.com; s=arc-20160816; b=KAeG2Z20ao8bUGONOPZIsELBi7P8137Du/MzOMDH6IaImkjPuayW0YXEGhuGbMD7Om /WPB81bWNND0K3z5NUi1Js5x1r0Xvw9YbAlVqeF3dEwHbecA3ExuOL5dNdgmhyGI/pTt T7HZvn9lx8gPE0UJb0yEJ+W2jLvsmqn8zy0cDDUTeoZ0awnYU1VyTHOafFBCkq98Ku3p BhW2d/zS39+xQfdLErTfFEH1IlLE/jMc1v7M6lPvrxjsaL084zMY6ktv8eBk3YTyYPkX kpDfKcuSIerxOGSLrkXPWxiVyGWotajviAmxLQ6ZLTSNw2WShaBMIqhf+t7TrKPCr6oQ 7xQg== 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:dkim-signature; bh=ikHA27jOWrf1Qm3cFev3aWzpCFTLu3KuD8nMhC9QKso=; b=IJvdcGvBvwuP4qwaxSCb2NwMUQ+ZRz0ykz/UxxQKBx5ev8Tf2EFDTwYO6UwgFcJFH6 WtA3iefguNJ0lnxFnkiMp/mT2Cvqip5Rk7w7ITUrfFIN1TJk3otPP1VMIGl9rGnvfSsM n1ovdoOLdAzvYv2FH8LytgAiuGM1D5f38knDV1k1aJ1xKlJn2AzTSm6mHbwSUJVEW7zh B+lf5428FrlSi5QFhrOBsoQW36YVJ5uD38B5OM7itLFYscQJEIVBphZTaxD4FL4+jc+A wQi7OHWiO/6qWq71ajF/DMzL9+x42QU5nt9ATx7tMQxJpO9TxhQEIKgm8Mnfc8CoLtJC 13/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=dhfVW77W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd10-20020a170907968a00b0072b7fac8a7asi5046086ejc.926.2022.07.12.19.19.57; Tue, 12 Jul 2022 19:20:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=dhfVW77W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233997AbiGMCO3 (ORCPT + 99 others); Tue, 12 Jul 2022 22:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233956AbiGMCO0 (ORCPT ); Tue, 12 Jul 2022 22:14:26 -0400 Received: from m12-17.163.com (m12-17.163.com [220.181.12.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ABEC14F659 for ; Tue, 12 Jul 2022 19:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=ikHA2 7jOWrf1Qm3cFev3aWzpCFTLu3KuD8nMhC9QKso=; b=dhfVW77WPi/zA9iuSew0M jWT1+ue2JcM4dFd0/rmTdVZTql2IZ2L3OLwmptdJMavqTru2yPc0wbsrA6u7ZqjQ reVSeGjejtOh502m7w970L2WyKAcpZK3eZxDmdPKjVwfUr7DmRXdYQcvOZATF27H 4v7WbDGvXPMwenl6HdYQKM= Received: from localhost.localdomain (unknown [111.48.58.12]) by smtp13 (Coremail) with SMTP id EcCowADXQZ9AKs5iAfn3NA--.40687S2; Wed, 13 Jul 2022 10:13:22 +0800 (CST) From: huhai <15815827059@163.com> To: linux@armlinux.org.uk, dietmar.eggemann@arm.com, mingo@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, huhai Subject: [PATCH] ARM, sched/topology: fix possible memory allocation failure Date: Wed, 13 Jul 2022 10:11:29 +0800 Message-Id: <20220713021129.103155-1-15815827059@163.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: EcCowADXQZ9AKs5iAfn3NA--.40687S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tr1rAFyUXw1DZF1rur13twb_yoW8ZrW3pw 40krW7tw4fWFZ7J397Xw1xZrykKr9rXw17GayUJ3y5J3W3Ar1xGFZav3yaqry7uryFqr1f tr4Uta4DWFZ2v37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jzuWdUUUUU= X-Originating-IP: [111.48.58.12] X-CM-SenderInfo: rprvmiivyslimvzbiqqrwthudrp/1tbiqwM9hVUMemdMkQAAsJ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: huhai When kcalloc in parse_dt_topology() fails and it will lead to a null pointer access. Considering update_cpu_capacity() also uses __cpu_capacity, and refer to the implementation of parse_dt_topology() in drivers/base/arch_topology.c, use global variables to store capacity in this patch. Signed-off-by: huhai --- arch/arm/kernel/topology.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c index ef0058de432b..383eaac1dbd2 100644 --- a/arch/arm/kernel/topology.c +++ b/arch/arm/kernel/topology.c @@ -68,8 +68,7 @@ static const struct cpu_efficiency table_efficiency[] = { {NULL, }, }; -static unsigned long *__cpu_capacity; -#define cpu_capacity(cpu) __cpu_capacity[cpu] +static unsigned long cpu_capacity[NR_CPUS]; static unsigned long middle_capacity = 1; static bool cap_from_dt = true; @@ -91,9 +90,6 @@ static void __init parse_dt_topology(void) unsigned long capacity = 0; int cpu = 0; - __cpu_capacity = kcalloc(nr_cpu_ids, sizeof(*__cpu_capacity), - GFP_NOWAIT); - for_each_possible_cpu(cpu) { const __be32 *rate; int len; @@ -135,7 +131,7 @@ static void __init parse_dt_topology(void) if (capacity > max_capacity) max_capacity = capacity; - cpu_capacity(cpu) = capacity; + cpu_capacity[cpu] = capacity; } /* If min and max capacities are equals, we bypass the update of the @@ -163,10 +159,10 @@ static void __init parse_dt_topology(void) */ static void update_cpu_capacity(unsigned int cpu) { - if (!cpu_capacity(cpu) || cap_from_dt) + if (!cpu_capacity[cpu] || cap_from_dt) return; - topology_set_cpu_scale(cpu, cpu_capacity(cpu) / middle_capacity); + topology_set_cpu_scale(cpu, cpu_capacity[cpu] / middle_capacity); pr_info("CPU%u: update cpu_capacity %lu\n", cpu, topology_get_cpu_scale(cpu)); -- 2.27.0