Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3711770imj; Tue, 12 Feb 2019 03:26:40 -0800 (PST) X-Google-Smtp-Source: AHgI3IZmqlp1EjTFg04lhpJdiyI7g3DEry9DxJPxrjSaUPKjgBsANGl9sozAdoYczwE9gkWaH4vj X-Received: by 2002:a62:ee13:: with SMTP id e19mr194393pfi.224.1549970800879; Tue, 12 Feb 2019 03:26:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549970800; cv=none; d=google.com; s=arc-20160816; b=OmGdSZb03oy+ffxP4oELroaAh2OpkcZcas3WJHv1qI+0YS0chm292cij5a9RsmtAZ7 jzSGhDYZybcJaWRMWqOsa91qirZrv4FIa0DE6WpnPgvivC5vWEX344pnp9v4JH0tnBf5 ucDMz1C8Pb2xew+0GTbiuJGu0F+DeDRCzMh/NSXQrx8ZFSTNebDrLaO/GdgHje+9Gh9r JQBycIk9jT8P7zSOzD5LGb9P08wjA/ANgJrJhdVR8EQKgPqO5l4d8hQSmzmEtobbOKbQ vNX3TYQHvhEp+VHy0/XVoI4oCNxwOc6CgAk64g8cPctlY01tc8F8CDZXWhqSrqIb12jD yPUw== 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=ZggfVn5tXV6u2E9G5C5rF9A1vi1JM7C14bxVn+avC68BfkkafWz6k/LoKgZT+zkOK9 AhV55lOIW2Ew1dJtYnMk1cu47A47JAm9Nw4m0t7OFitqY4XSCsl7e0kxriFnTABFbbC1 AglMTRi5ueVpNX9vyadPELmbW4S2Tf4TaNuc6C8OakNYQ9qsm1Pu1n/jXxhk6+qWichO x23MM4t1WoDWrfLFZAzkE7XtLrLEHdGCOjzUsiyRtS/eJaZ8tjZNrUcAPs+7aYevFNoo DSEquJtZCYIPVcyQNb17zKs3psP5R6e2jtjEP15md1a2qQpJ2wfQrIb+hXmvKpI+mq4j 1AIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=K1ZfHf8x; 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 b8si3586748ple.5.2019.02.12.03.26.25; Tue, 12 Feb 2019 03:26:40 -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=K1ZfHf8x; 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 S1729370AbfBLLKu (ORCPT + 99 others); Tue, 12 Feb 2019 06:10:50 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42878 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729304AbfBLLKe (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=vnRdayaz5Pz6NDhpDj4PwPWoeZAvCxUKf5wSxkfkfNk=; b=K1ZfHf8xyqd1n5iHX/NrcwZy0PniwWHm1xwifJ7dHf2UFTIVOUJ5XrFr 7cpwyceZ5IuJ0Ow71ofWfM6yHm1/SVyF2LikLiX/oSsevx9zJR087KLgg HWQtl/wFbNiOT82SiWpEJzq5/efEUF/48voZjgxgiZIsEl9hBs5Mxk0Oy /Cm4hpYuLc/PXhwXFefXSobMpxaVTRO59g1RlQRjSNer/b9F2Y1WIgCv0 x//eAmIr+VP+5IRio7iZxX/zlIniHu9yijkz4+KULe9fBTMFx/L76+UPO NGu6oR68qhVXY2/YltUkAW+6/G8bMEeWvEYEmbZbXp2C9yAtX0dBry5Z2 Q==; X-IronPort-AV: E=Sophos;i="5.58,361,1544457600"; d="scan'208";a="199201836" 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:12 +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 6/8] clocksource/drivers/riscv: Add required checks during clock source init Date: Tue, 12 Feb 2019 03:10:10 -0800 Message-Id: <1549969812-22502-7-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 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