Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp1815127imc; Fri, 22 Feb 2019 11:42:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IYv43EHEERtADC+UQO0rA2v7Td4XjhpCApRsg5J1+Ki/GczvsPO/5MtqOM9poxz57F7BCDX X-Received: by 2002:a62:e911:: with SMTP id j17mr5368578pfh.107.1550864563483; Fri, 22 Feb 2019 11:42:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550864563; cv=none; d=google.com; s=arc-20160816; b=oEwmT9hs8vovQ/V5VC9mBzl2XobgkseUg6kLi0Sa1ejBj6H9bwTBWdUHbCr/TWcTPk fKi7+Q3o/txXTQYpqOR/G+s8Lzc4rhqO+Pc2yA5MuWoPIvII6BTfwoZiMhQM1tXQwjfU NX0rm9tOPrF5iCdWjFiJ7vaNC/cr5gpNK9Hq5wwp6u9iHV2RbInrO0DLAIRzYkerjUnx xV3I5dWrHysyzmwwRhkMI3eBlQ1jU+hnF7Htt9Zg2LVPdzbN5MO+xC6JGnj/SXiUEGZ1 P+JKFWC2838wCGBNbKdoPd/w56k57m4FZJTBYUOJ1YTT1NT1Oh76iFLvWrLhTr4kBzpe HgsQ== 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=0SBLs2ablRcawLLX/Ui1Bp54R4lP/dGgzYRcTvIrS396z2099wvFmWRMSK/bemff0+ HUlu8yweP3T57G4KefzuafL0snwW52PAWdfgeMpUY3ANINJ/iQoYH4kp8QOh++w5XrDu uQKSwGPiKtbVNym2nIZbO1J5ETpyoBZSQW0gLOl0hEXN4ZQfn+buEuPa9bVa4mjnAlMr oR+/NDk/CTS1SXeCyvVSot7wKijCrZaF2JNGnzLnlAqzknuApVt7YwFWj5HQbnyfWecA HsKMXASByHtMAfKR/s4lCcVF+QBYQDJfGjtFhyA3ZvikiwlxS5ElB6fAqANA62s5I4e5 dnQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=jXtRS1mO; 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 a90si2021554plc.314.2019.02.22.11.42.28; Fri, 22 Feb 2019 11:42:43 -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=jXtRS1mO; 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 S1726893AbfBVTlu (ORCPT + 99 others); Fri, 22 Feb 2019 14:41:50 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:9381 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725832AbfBVTlp (ORCPT ); Fri, 22 Feb 2019 14:41:45 -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=1550864506; x=1582400506; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=bTj3ZFVXgC5G434PAQjLdqn3TV1DqlyoGc/NiuvITNw=; b=jXtRS1mOhCFWbkSLnCUlU8GpU5DhgLlGcCqlyWAGWA9JfKdW7Gi9hqqb B56gfdN7qg5Eq/CF6gTFq6Zh411g4JYGoBFNysioD6Rcnx2y+0myOqgyC z4WgejNAqBsUOeueVfPB37vmqP8jhOY3IL6pZ0RzXrvV4VTEfPsEAnm4P vLC2gk897WGWlbx0hXeovDnmM4I5utGXOxYayjOnU7eTYM73eyyZ1Ef2X lXhnWoH03PaPnIRhUEjqy7EgWEWAlDChs6yinmUtLuuvTDsiwwvQbcuEt 38GhtQyPhr7cLObdRbSOedPtPLeFPySAqjSLCBnKntVOOw18cDcX3PMQn Q==; X-IronPort-AV: E=Sophos;i="5.58,400,1544457600"; d="scan'208";a="103727138" 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; 23 Feb 2019 03:41:46 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 22 Feb 2019 11:22:04 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip01.wdc.com with ESMTP; 22 Feb 2019 11:41:45 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Cc: Atish Patra , Alan Kao , Albert Ou , Andreas Schwab , Anup Patel , Dmitriy Cherkasov , Johan Hovold , linux-kernel@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Thomas Gleixner Subject: [v6 PATCH 5/6] RISC-V: Compare cpuid with NR_CPUS before mapping. Date: Fri, 22 Feb 2019 11:41:39 -0800 Message-Id: <1550864500-13652-6-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550864500-13652-1-git-send-email-atish.patra@wdc.com> References: <1550864500-13652-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