Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3711872imj; Tue, 12 Feb 2019 03:26:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IZOGpZGZtZuyUhxho8C5v6Q+EwV3+UtcsocAmkWbCAYT/wwXbQzfYEsS3dmp5iQH6A2oyPc X-Received: by 2002:a63:1e17:: with SMTP id e23mr3203186pge.130.1549970806972; Tue, 12 Feb 2019 03:26:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549970806; cv=none; d=google.com; s=arc-20160816; b=BUc73cXY4+py2qsBunJV866CP04fb6P+oQTCe/mBW2DIGTNDzhIxbtKBKNZ28PDhRr R8lQ7SnGXdJlXEuFg6pTWV6Z+LTobxARNIKw547YVHCBnyiKWOmZT1yQFjToTeChzmrt D3bOHuj1ruXLOhXdLozKJlAKqpDrRPGJA97N/4KYzc9G0oIwi/nldH/TRGaYH/zsEbX1 wzH+H5vBxC5CM1+vTtOFp4fVkwRNbew6SoZjI0CJQAlwtHZg15nXSG+a6lo8bAfiDqOf DtzepPIV1nvmw5f3t23u5LBZ92qAUy+RVFAnyHPBGtG8uCrJHgPUTmT25kJK2YuABRQ5 lVlA== 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=GjP7tIzsx1Masu4ls54B34i3wb2Qkn7G+t3f8uDkcg8=; b=DQ0UPDy6f7YLtFHIG0wVj+3iS0GaawaJrpovwiI8dmLpHkW4qxzsxsU8cu/ceKyTkw 1Rh4Q7Ou0rpf2q1ccCSRcsYTG1gUaoTLHdMI4NbTmsK8WXEFzgGncqxCinWkseaRs34l Ke9HZv/sonc5JK2tmNQrwHo+W/WC1eD3hCHTPIJpTk6fTu7ZAiHLIEyvrn7+7ylJaA4E V6O7cw1LPZEGIYv69yMxFxJstvsbmJ17JfXrldBx+IX2ty4iWUlFwb/QlfM3vMIlSqqc iaREVGLYO9bDx4wdIErp6avtDyzq4gE3yyxI6EA4ABVP0ImVRrj8SYWNyIW8wRLhF/Fe RI8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b="d/57ePjB"; 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 y6si12811995plk.44.2019.02.12.03.26.30; Tue, 12 Feb 2019 03:26:46 -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="d/57ePjB"; 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 S1729357AbfBLLKs (ORCPT + 99 others); Tue, 12 Feb 2019 06:10:48 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42875 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729298AbfBLLKe (ORCPT ); Tue, 12 Feb 2019 06:10:34 -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=1549969890; x=1581505890; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=bTj3ZFVXgC5G434PAQjLdqn3TV1DqlyoGc/NiuvITNw=; b=d/57ePjBDrxuOeck2ow9TLt3NYRKz3SUno9aOGRdMg6Z0QWUoOJcLzXF px4vu9XFbeWbyeI8F61lxT+VNti2nMi13sq2FMPSPrH9l9S6R9U8WM2rJ zWtPRQ6j11N7eSsbMs8/IEOHIlJiEl7JE/ootUH6CP7jPx092bfi43Jdl 6OuRv/An/cJZVaVaHtxplAL5966aOcIMoiYVvVjR7bwloLEUG/w/ZeJMl NtDr416FW4xVB1zB89sel0C7Rbm3aVbJzMpLrdhKCVYZz2tSxtr5oTGLz VNCq3CEPBsGra3cRrhXslD80BSfRfLRVGkHnnHZPee7eP3RPm2Ycf+m35 g==; X-IronPort-AV: E=Sophos;i="5.58,361,1544457600"; d="scan'208";a="199201834" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Feb 2019 19:11:11 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 12 Feb 2019 02:50:58 -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; 12 Feb 2019 03:10:22 -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 , Johan Hovold , linux-kernel@vger.kernel.org, Marc Zyngier , Palmer Dabbelt , Paul Walmsley , Rob Herring , Thomas Gleixner Subject: [v4 PATCH 5/8] RISC-V: Compare cpuid with NR_CPUS before mapping. Date: Tue, 12 Feb 2019 03:10:09 -0800 Message-Id: <1549969812-22502-6-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549969812-22502-1-git-send-email-atish.patra@wdc.com> References: <1549969812-22502-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 Reviewed-by: Anup Patel Reviewed-by: Christoph Hellwig --- 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 d369b669..eb533b5c 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -66,6 +66,11 @@ void __init setup_smp(void) found_boot_cpu = 1; 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