Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1063537imj; Thu, 14 Feb 2019 00:14:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IbT7MtEnGYm26HOEe96NzQVOaeOTllVbtL24sm1yDsXRaTCtRX0OHbjr/jyXggjde9wdmVq X-Received: by 2002:a17:902:44c:: with SMTP id 70mr1532995ple.318.1550132081874; Thu, 14 Feb 2019 00:14:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550132081; cv=none; d=google.com; s=arc-20160816; b=L0mYxhjBJNhYLnsvck9twJ6f7JNJgabOnjodDGsSUvWAK5hwD//Peb6F9dthpjn+Sg hiBpcJHNvnOYRzOGXeUJNo4lWdxhoht+ELLx7jjbdbcQZolSxVPKPOgPvLQKoG79XXUA QklA0iJBlbs6FF+IEkMaMt5kLqwX1wuhDEXP3tbTSfO/fN+hqnVmg8GFJx67Gj4AQU8y 9i03AHIN9kr+8+OYjTMtn81sIxX/7xkV1C1MTof7U6BFq9svb/S+ffn6Q6oIcIGGsMYa 50fykmZh1L90ycBWs7T+RlGa5PwC3SWoQ+8IFODXb4ALY+lglc4Rua+3wymOt54kqaLh AV0Q== 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=QVO63NOX5tDzY/+rQlfa78Ixx9zdFaOoNM337hTZJng=; b=jViWAdIyQwt4fgeIfDm63AQ/ptXcTqGrKQQsK+2AOCdXfCEfF4hYA4Fj8XbMbmU9sh 02ZqLqOCfaVlJkQXEG+zYQZFnCdObXqR/xaotKBz822Iq6bULzXoFOPeNjEmdN8+bfFj QJaShviCF9mr8lFuLQa3++iJYNhy16AcrR6o7vVUhFIhY1dEANEr9aSRJYj8BbNEIT/i mVR414C7N5W+0BSd91KPjY7/6wwzMAe9ldFIuKG1Jih/Tz/Y4ZBT6cZtaXaAA9soAx22 jsnlJo2yMHI54ryqJNo+EXxSvfpLXI6ApmDh2grLRK7gk2lV/g7VdEjRVxIBB0Jx4TTa rt5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=RVUWr1Uk; 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 y14si156808plr.78.2019.02.14.00.14.25; Thu, 14 Feb 2019 00:14:41 -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=RVUWr1Uk; 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 S2436622AbfBMUSj (ORCPT + 99 others); Wed, 13 Feb 2019 15:18:39 -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 S2394564AbfBMUSW (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=1550089102; x=1581625102; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=vnRdayaz5Pz6NDhpDj4PwPWoeZAvCxUKf5wSxkfkfNk=; b=RVUWr1Uke1QhInA4f4nnTiKa9LB0CYYazHLFiTaSHtacyWu8+DCBEP0P ifHKq4rrHk6SVDvTW8FIQGN/q1sxMq+t3RwVuzWpqy3BpFRJK4wl83xGr NP/8vmCn4lBJYj2hD+ybHuTFlpjEXzmHXHP4o5fWK2eSY3I3qAQNi9ZWb 1JJX5auf3VRm9HrELFiq3Rl1JBHvnBP5jVObampV1qKuUwjP7f2N0BIuZ xQccllc1BDlhai8rffvkHT7dv5aGfqfxSf0ZJVorvzNHyxTNdiLVD/hcr fhqeVpurEBIwuV+KEX77tYZx3HNy/yEul4ByGZ5fTAtYBS0+Nb/JENnVa g==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="106167287" 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 6/8] clocksource/drivers/riscv: Add required checks during clock source init Date: Wed, 13 Feb 2019 12:18:10 -0800 Message-Id: <1550089092-28783-7-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 Currently, clocksource registration happens for an invalid cpu for non-smp kernels. This lead to kernel panic as cpu hotplug registration will fail for those cpus. Moreover, riscv_hartid_to_cpuid can return errors now. Do not proceed if hartid or cpuid is invalid. Take this opprtunity to print appropriate error strings for different failure cases. Signed-off-by: Atish Patra --- drivers/clocksource/timer-riscv.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c index 43189220..e8163693 100644 --- a/drivers/clocksource/timer-riscv.c +++ b/drivers/clocksource/timer-riscv.c @@ -95,13 +95,30 @@ static int __init riscv_timer_init_dt(struct device_node *n) struct clocksource *cs; hartid = riscv_of_processor_hartid(n); + if (hartid < 0) { + pr_warn("Not valid hartid for node [%pOF] error = [%d]\n", + n, hartid); + return hartid; + } + cpuid = riscv_hartid_to_cpuid(hartid); + if (cpuid < 0) { + pr_warn("Invalid cpuid for hartid [%d]\n", hartid); + return cpuid; + } if (cpuid != smp_processor_id()) return 0; + pr_info("%s: Registering clocksource cpuid [%d] hartid [%d]\n", + __func__, cpuid, hartid); cs = per_cpu_ptr(&riscv_clocksource, cpuid); - clocksource_register_hz(cs, riscv_timebase); + error = clocksource_register_hz(cs, riscv_timebase); + if (error) { + pr_err("RISCV timer register failed [%d] for cpu = [%d]\n", + error, cpuid); + return error; + } sched_clock_register(riscv_sched_clock, BITS_PER_LONG, riscv_timebase); @@ -110,8 +127,8 @@ static int __init riscv_timer_init_dt(struct device_node *n) "clockevents/riscv/timer:starting", riscv_timer_starting_cpu, riscv_timer_dying_cpu); if (error) - pr_err("RISCV timer register failed [%d] for cpu = [%d]\n", - error, cpuid); + pr_err("cpu hp setup state failed for RISCV timer [%d]\n", + error); return error; } -- 2.7.4