Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1064522imj; Thu, 14 Feb 2019 00:15:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IYGwxcP3pJ/4WQ3AXLjbfZr3Md/JMkAadY/BmJi2yIiw+h94hc5VGOxNcVNt6f4Bs84dyvd X-Received: by 2002:a17:902:7805:: with SMTP id p5mr2808471pll.261.1550132155667; Thu, 14 Feb 2019 00:15:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550132155; cv=none; d=google.com; s=arc-20160816; b=cdFyRteRn50RGW5HMRtWH/4BDAuhBtQJRR8sRqzN4dLBo7IgFCMGZ28v7jTAIt4GfH N4v1GPkREpCNWq+Q+DNT/mY045L7EwJtylUYuZn+ZZGeuHJJjaYktvN00jVzE+4X0tPe 5zfETe3SqX9fdjq8qOgBA9b1E0qIHyeeAQC2SuYrLNc+LNemGv4TxjDOcMvk/8CvVYNN gxPrJ8SfA3XUMVq5NpjJwc3MCl8x96C7Thn9rBu/VKi1BFvVlFI37n5DjvtyEPGgyVYa ldaz19cphDOeAg7U8QuRc+gWUOLDIPMh/5PcxaKIYu8EVMCRZ1WvFCcVG5rRGuW0qG4y BaxQ== 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=laYxqIPUtfk6xb5vO1kbFGiktRYfQDLopP1B7h8zUfqXonvvrPNpITc/0lQS32EsR5 nOrL1ZQLO4ONut+cyJQswdsR0vrxcD7aJqb8Aa6fCKP/8262NM1TOBMNSN0l9P7quWz0 KYsRzKRP/yrFumjzIxFfQExZgnKlYwrrBl1bZzBvdjRX21K9CK9uO72NFhf8VcXB1kAi 0lYvrv501qvd+YKWIw7r9jNrA8Z3x0CicPXDmCsZEv77DbL00DE38LvD+YihcvFiEAXm 0FEL0ZGljNQCWmTkwPC2q82m1br2Th1LhAYCUSmoW8DTDtnDo5i9leZuaFjzL3JHgWOK UUKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=OjoR8m3q; 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 o6si1822936plh.23.2019.02.14.00.15.39; Thu, 14 Feb 2019 00:15:55 -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=OjoR8m3q; 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 S2436633AbfBMUSp (ORCPT + 99 others); Wed, 13 Feb 2019 15:18:45 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:65222 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfBMUSW (ORCPT ); Wed, 13 Feb 2019 15:18:22 -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=1550089101; x=1581625101; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=bTj3ZFVXgC5G434PAQjLdqn3TV1DqlyoGc/NiuvITNw=; b=OjoR8m3qPWNSohjNDQsm/ljW9y2pZh1bxhklxSrdozCnnomOpB50j0SC kTtnT9NGJPW92T2hZwv7UC1GvDOmzeGGvBDuemdMsPybe+cX6cyqE4jIm DXBE/rDJkWOrS/Pts+OMD2hc4Zhwo59MwDxHF5nK3FOzdXLjdj5H1l+QD gPUEHlO6X3o6/dntRUnpIOXO5tn/fQehRP4tDaSnu02vufU5HxXhePhI+ B6WliO3B3zw9gg+WlP0jdRTnVnxRVpsRJytFDOWmGUErTY+VwlSTWwzS2 OQi4aA2mB2HhG86TrE+rPRbpiFHhCkmLeE4wE95V6rKwA64CJb9y/q1+1 Q==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="106167281" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2019 04:18:21 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 13 Feb 2019 11:58:55 -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; 13 Feb 2019 12:18: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 , Guenter Roeck , Jason Cooper , Johan Hovold , linux-kernel@vger.kernel.org, Marc Zyngier , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner Subject: [v5 PATCH 5/8] RISC-V: Compare cpuid with NR_CPUS before mapping. Date: Wed, 13 Feb 2019 12:18:09 -0800 Message-Id: <1550089092-28783-6-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> References: <1550089092-28783-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