Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4530253imu; Tue, 8 Jan 2019 01:41:17 -0800 (PST) X-Google-Smtp-Source: ALg8bN7QlFE4BBoTMhVlmI4wWysDb38q2+LPemGt9DvfvU3U798woUzTb4UYpSE1lFW/fbdyWE+f X-Received: by 2002:a17:902:a5c3:: with SMTP id t3mr1014848plq.117.1546940477855; Tue, 08 Jan 2019 01:41:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546940477; cv=none; d=google.com; s=arc-20160816; b=tqb2xyGb38b3qQvmgNokV/gVK6VKInaP274tXMKCEmC6pV065D2B9m/6Oj0pqTJLAH CDh5wcrqsluDSNa2sOevr3Y2xCAPhT8QkHECoXQytJ/dv5D0ugIMXCZ5b/BgBpdbuzLL 6okYgozlbMe4XN+EcD2uPaLuAZ3iXY4aW8R0ylZU0uqkubwsUuNt7KD9AriAV7xBU1lP pnX+jGk40Jv5SU50iYxn7K6yvoR20jB4rSvoSs/48iJP/WpND2+fHJzidR+m8kDth/zZ FIpBuyFMMbj16y8RaGs+tbmQfe5mEGthd3wu2k1VJVJCPsXi3geb4tburCCqrghzpD39 cz4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=YfklabTgsHvJ2L2Y89MWXPVx8rVL9yuyBIXhy3dm7V0=; b=yu+2p6o9AfcpeIaGJJI0x6Ub7+lE6OYn5Y4P6pv2uWp44ccCRhjTwkDhJmHoA7Ozq5 0itlCOant+rkaoyasobSwphf7+T/J05f8bwBdm0YSFCVR6X3RQjbOPDfrB9RME9pj0Th XHyoSetowbI3lk2bdFQ06tMsEfzlf+Q+Aj3gF66m4lx9uG2VA6r54+pRHXim2n4MkVjq P5l/BK3WVFP0NAA5UdWolqJXSDJhnPT4dD1qdamG8+Jx8G3eFJhjaSPranutZ11n/Vmo 7ZPrccmVJULCT2JLV5X0Jlaghaosd3dR766ePIpbv4MZ1nVZxawdAodKHjCUixHMXvMG yOdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=B9jwlpqn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p15si7284160plq.24.2019.01.08.01.41.02; Tue, 08 Jan 2019 01:41:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=B9jwlpqn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728412AbfAHJjV (ORCPT + 99 others); Tue, 8 Jan 2019 04:39:21 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:8886 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728409AbfAHJis (ORCPT ); Tue, 8 Jan 2019 04:38:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1546940328; x=1578476328; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=bojnfVslHWWf25l3Qcim0lvK5HIdSXIJ0sC4JHd9reg=; b=B9jwlpqnqe0Pv5njUMfTyxMsQuLZxmrKGi7Y7fDTpuPjl4ndtqETJATg W9IlIlNgObgKuSQqcGdLcnr765Yybf59/VK6gn/TipYrhtoi/6aAOnGUY 0rCIsj/JsYqPV8XvsMybniTZb8pvFePEudpnmS6vlDm5zJaLV6spBgsyj neHu+d4W8/nynZWlu5qapNsQDR92h89o8IV7vTJVcWZj1SXk/3MYx17H5 bCuw70Ox9+jZ4IjZEWpgIUmatdElGI2oiOYxSrZBcZKnZCnru4836i5sz 6+2NkG1zEtqRKl/xECa3KrSNHJ8hM3uf/HlOxpxfVt0cYoDx0sR9dNz6H w==; X-IronPort-AV: E=Sophos;i="5.56,453,1539619200"; d="scan'208";a="99458409" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Jan 2019 17:38:47 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 08 Jan 2019 01:18:52 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jan 2019 01:38:47 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Cc: Atish Patra , Alan Kao , Albert Ou , Andreas Schwab , Anup Patel , Daniel Lezcano , Dmitriy Cherkasov , Jason Cooper , linux-kernel@vger.kernel.org, Marc Zyngier , Michael Clark , Palmer Dabbelt , =?UTF-8?q?Patrick=20St=C3=A4hlin?= , Thomas Gleixner , Zong Li Subject: [PATCH v2 5/8] RISC-V: Compare cpuid with NR_CPUS before mapping. Date: Tue, 8 Jan 2019 01:38:35 -0800 Message-Id: <1546940318-9752-6-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> References: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We should never have a cpuid greater that NR_CPUS. Compare with NR_CPUS before creating the mapping between logical and physical CPU ids. This is also mandatory as NR_CPUS check is removed from riscv_of_processor_hartid. Signed-off-by: Atish Patra --- arch/riscv/kernel/smpboot.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 32e14572..7954470b 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -69,6 +69,11 @@ void __init setup_smp(void) of_node_put(dn); continue; } + if (cpuid >= NR_CPUS) { + pr_warn("Invalid cpuid [%d] for hartid [%d]\n", + cpuid, hart); + break; + } cpuid_to_hartid_map(cpuid) = hart; set_cpu_possible(cpuid, true); -- 2.7.4