From patchwork Sat Feb 23 13:06:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 10827475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 860EA1575 for ; Sat, 23 Feb 2019 13:08:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 674782A726 for ; Sat, 23 Feb 2019 13:08:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 555762AAAB; Sat, 23 Feb 2019 13:08:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D31392AC3B for ; Sat, 23 Feb 2019 13:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UXI3uaF5tVjBwnX3yrEuyoYJSJKRvDReDMwUaJCoU04=; b=N67fHgyDcXAyAX2k9zxxAvZ6ht MAzc7cpafV5SLJ2sLoiq5R1YW2UixhFQ9/dmx+yRoEwZnh+MzRhH1CVy8XEsUeVUtWvsK/ifofPns a7heewVimG4J+8+z8duqM7yBvEzVGuxnUscBAjnZMgbUyTZzxyzWazxCQlWmymZKc06egMchTQQCU 9eckAgeSPd0ckL050wDYYLDs6Qt2TyxMqFRGxrifupCaWfRCDLETzydqeV56jnwv1Lr+JFF9R9Qxh LybCqebCATvR/4BLINLrez9ywPBk77bfwjB0pQgmayK0wlwf+Q24+KS2Gj90u9dfXyK7LmQ/jwR3M PKn/dVww==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gxX31-0002Gv-1f; Sat, 23 Feb 2019 13:08:55 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gxX2E-0001Kv-NV for linux-riscv@lists.infradead.org; Sat, 23 Feb 2019 13:08:12 +0000 Received: by mail-wm1-x341.google.com with SMTP id j125so4275738wmj.1 for ; Sat, 23 Feb 2019 05:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FvWbQwT7yD0J6wXiJv9iSEtwBLiuq9ZwuzA1XeKrA9g=; b=IwFsOfX98LVVF+r7B8EMzjeW6rylRGOIFvg/d1eTz8NQWX5DF2V0ksBTYDYAo9pKRm oZ9ycTByKDlmw5uywBGZH1GzlmrQToRsQEq4uz8L6EX4XvUbEHGHtWlGX540oZaB5OFK s3oKIVSQ71Hc7brd87dYmPE84xFwU5RPM/j3ht/ljkSWwm65jWXyKbvaMQP7kRbbG0cs tR/rwvkPFHQI21Wc90u3M41xkavzkyTAC1DCRcSxjDGfhjlrwE08/zmVDgcjWIznom3G rhdPt6QwydZbX3+fvqcxMC/3HpfZtTpFwURHceq+80/6Y45hdAkHVQnZ+WTBUF/1YaWS MQdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FvWbQwT7yD0J6wXiJv9iSEtwBLiuq9ZwuzA1XeKrA9g=; b=igemVE2wAE1ejnR+SiCASLTv0wSlrqtAHRM+pu6pE67WpGri+cb57oz8mnlzHkgZCo RUxQYJ/T1ItDgIwjyqU6Azeea1OGqQ96piwOlaoyFn343YECyrxWTnuBkFDSxCyCuAGr Zk6OXFmf5XTDmXcxG38IaFlOdfSdhMqhNHk9lzUXGoxyBBioWDS8a5tAsAHcR3u/tJLp dhaNNdjyYgLmNwoMJXPyyD5ORde7HBrTXBuMrI7Q5clZtUekGjMroeBFy8hX6L1yifQZ +2hci6h2ZcRS48tUUvqNt/CtIMAxFwgAO7sIo6JysdVVFMdhvJfAjVFLo+X4+/HyZA8c TSNg== X-Gm-Message-State: AHQUAuZjviaEutsCA+uaDCM0+fCretrsdHnI3AgwMbtQVaT2JrrqRBat /f1J44fHCWVWcIhpRHII+rZ1cHbtzD8= X-Google-Smtp-Source: AHgI3Ias4KcVPoc17ozN6m5RJJSZcPhaaIFTt5CqkYQhqOaBZ+y9ug5Nv4yZQD5V3FVg4SQT75Hy5g== X-Received: by 2002:a1c:2743:: with SMTP id n64mr4706807wmn.143.1550927284690; Sat, 23 Feb 2019 05:08:04 -0800 (PST) Received: from clegane.local (189.126.130.77.rev.sfr.net. [77.130.126.189]) by smtp.gmail.com with ESMTPSA id i12sm7830746wrq.21.2019.02.23.05.08.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Feb 2019 05:08:04 -0800 (PST) From: Daniel Lezcano To: tglx@linutronix.de Subject: [PATCH 07/18] clocksource/drivers/riscv: Add required checks during clock source init Date: Sat, 23 Feb 2019 14:06:55 +0100 Message-Id: <20190223130707.16704-7-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190223130707.16704-1-daniel.lezcano@linaro.org> References: <20190223130707.16704-1-daniel.lezcano@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190223_050807_334053_18A4D560 X-CRM114-Status: GOOD ( 11.76 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Palmer Dabbelt , linux-kernel@vger.kernel.org, Atish Patra , Paul Walmsley , "open list:RISC-V ARCHITECTURE" MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Atish Patra 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 opportunity to print appropriate error strings for different failure cases. Signed-off-by: Atish Patra Reviewed-by: Anup Patel Reviewed-by: Palmer Dabbelt Signed-off-by: Daniel Lezcano --- 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 431892200a08..e8163693e936 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; }