From patchwork Tue Jun 22 10:15:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 12336737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FE31C2B9F4 for ; Tue, 22 Jun 2021 10:16:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 12BDB613B4 for ; Tue, 22 Jun 2021 10:16:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12BDB613B4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=KAydFUU7d48lhf/szAPMtI4g8xThlG6w+rUmw8C2t/s=; b=0sfajHmp7FeoqL cluhEuWL4rJQnvZfM9JKeLxNVxfygwJLrCiySnBzcga0wX9NwiNQ21fqQVALL0zWwFB0N0YAYUees nuhw+NGSDT7dz+inoe4XaPqb5Cs47xrxatW3qSL7uYFzAG2SLH2dlcS/M28ym3FAPNaFgGHjbdUc8 SKrNeMfrP3M5+IrA6eDxjpBfFI1kIGwcbTtJHDOWlKDEt5Tg89JfwkDuP1PUdp8z6m5OT7VzPL3ff SmRP/TSklnV33nUTXnvRydwa1Nur+JxcgERWE3R5yd2VC08nw6VLcRKv/cy66IA+xEBh4NJoyJRB+ 5u8HBPooSOyBZVu8WDdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lvdRD-006aQk-30; Tue, 22 Jun 2021 10:15:23 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lvdR7-006aOu-DV for linux-arm-kernel@lists.infradead.org; Tue, 22 Jun 2021 10:15:20 +0000 Received: by mail-wr1-x432.google.com with SMTP id n7so22970270wri.3 for ; Tue, 22 Jun 2021 03:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zYV7hqqp2NUmMYcdGW3YHE3qT5LHwub4HNP+0eHal0A=; b=zKhd0Pwpfpit6QP/op/rRTOyEXkXh2gcDJ7Xmn0KHeDskCe+FNDHUIQA2D9japVVRf 1ygggadDXv/i6flr2li5qwx3TllsVkFylc6kwdcMGpkkFN8ZZ+knfYLqygM02lqqPDET /H6YOT1hLtC6vBdhRrA9RIv4ucCQpxYxcJTfpgoIKAJ39tT7oc0u/TDtOWp8Se+vb7Gu DFaSeKncT8ZMzh0kgnKpbet8g06wWCZxT0yWYob2UMNk1bk39BzJWtrJjPVAvGZwtNSC NZlbQ6OcySq/tObHJQtkl+pYePgRXlwSFwFWFOo/+QP3GqoOYI0VoszBWxHN1Ysmx8GE eOWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=zYV7hqqp2NUmMYcdGW3YHE3qT5LHwub4HNP+0eHal0A=; b=roLeIsjR4Z8sOWNm4oav193ffIlUrF7RKXHHCB8iZ9779SdJI46eOtbUvTOGtr5tVm dJkIfhoiQDYw+W7s41124JQbWnNCZs2B2PutiJZkkrS3kAbvKcDx++nI8JMbkPUK2jjg vMSBk47DiCNtnOMbx7h2BvYsAFA2hrLML7FQbyWRZ7guAgsI0CsQE+s0rXI7G3d7YYvP b+q3+Ocqwo/dWZTEUndt7AQSmaXX3oMIrqUrlLMkU30T6mD+71HJ4UZUCcRqvMBncYgE Vz564RWywKXmfxR8Dnek6hfCKwD/M8bV6vkHfQ9pe6s+fVDYqvUHonmaGlkGm1dMSBda ToGQ== X-Gm-Message-State: AOAM532m/KkhcZdGPN2JlV83xarQKzMTK8FrR2jLYEOWJxqcXcSGp3al DdUtnIwK914bFccYXGOMxIlF8g== X-Google-Smtp-Source: ABdhPJxt8obSRXvVypphkRGgMVXcrgAsDsUhRgYgzVfdvQnodGoMOhJQHlzTPJd8yocqaKzzoGWIdA== X-Received: by 2002:adf:eed2:: with SMTP id a18mr3865604wrp.268.1624356915906; Tue, 22 Jun 2021 03:15:15 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id o203sm1999307wmo.36.2021.06.22.03.15.15 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Jun 2021 03:15:15 -0700 (PDT) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu, michal.simek@xilinx.com, git@xilinx.com, quanyang.wang@windriver.com Cc: Arnd Bergmann , Michael Turquette , Punit Agrawal , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org Subject: [PATCH v3] clk: zynqmp: fix compile testing without ZYNQMP_FIRMWARE Date: Tue, 22 Jun 2021 12:15:11 +0200 Message-Id: X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210622_031517_554052_A2A62DA7 X-CRM114-Status: GOOD ( 20.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When the firmware code is disabled, the incomplete error handling in the clk driver causes compile-time warnings: drivers/clk/zynqmp/pll.c: In function 'zynqmp_pll_recalc_rate': drivers/clk/zynqmp/pll.c:147:29: error: 'fbdiv' is used uninitialized [-Werror=uninitialized] 147 | rate = parent_rate * fbdiv; | ~~~~~~~~~~~~^~~~~~~ In function 'zynqmp_pll_get_mode', inlined from 'zynqmp_pll_recalc_rate' at drivers/clk/zynqmp/pll.c:148:6: drivers/clk/zynqmp/pll.c:61:27: error: 'ret_payload' is used uninitialized [-Werror=uninitialized] 61 | return ret_payload[1]; | ~~~~~~~~~~~^~~ drivers/clk/zynqmp/pll.c: In function 'zynqmp_pll_recalc_rate': drivers/clk/zynqmp/pll.c:53:13: note: 'ret_payload' declared here 53 | u32 ret_payload[PAYLOAD_ARG_CNT]; | ^~~~~~~~~~~ drivers/clk/zynqmp/clk-mux-zynqmp.c: In function 'zynqmp_clk_mux_get_parent': drivers/clk/zynqmp/clk-mux-zynqmp.c:57:16: error: 'val' is used uninitialized [-Werror=uninitialized] 57 | return val; | ^~~ As it was apparently intentional to support this for compile testing purposes, change the code to have just enough error handling for the compiler to not notice the remaining bugs. Fixes: 21f237534661 ("clk: zynqmp: Drop dependency on ARCH_ZYNQMP") Co-developed-by: Arnd Bergmann Signed-off-by: Michal Simek --- Changes in v3: - Also check PLL_MODE_ERROR return in zynqmp_pll_recalc_rate() - reported by Quanyang - Change Arnd's authorhip based on our discussing at https://lore.kernel.org/r/CAK8P3a1twOhC8DFxpLxpk8bcy0+JfGZUSE9bX4tdMetVLGTcSQ@mail.gmail.com Changes in v2: Based on discussion here Link: https://lore.kernel.org/r/20210421134844.3297838-1-arnd@kernel.org I have updated error return value which I got from clock core based on error cases. zynqmp_clk_mux_get_parent() should return num_parents() as error defined in clk_core_get_parent_by_index() where num_parents is incorrect index. Extend zynqmp_pll_get_mode() with PLL_MODE_ERROR to handle error case. zynqmp_pll_recalc_rate() returns 0 because __clk_core_init() consider 0 as default rate. But maybe -1ul which was used by Arnd is also good option. --- drivers/clk/zynqmp/clk-mux-zynqmp.c | 10 ++++++++-- drivers/clk/zynqmp/pll.c | 22 ++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/clk/zynqmp/clk-mux-zynqmp.c b/drivers/clk/zynqmp/clk-mux-zynqmp.c index 06194149be83..d576c900dee0 100644 --- a/drivers/clk/zynqmp/clk-mux-zynqmp.c +++ b/drivers/clk/zynqmp/clk-mux-zynqmp.c @@ -38,7 +38,7 @@ struct zynqmp_clk_mux { * zynqmp_clk_mux_get_parent() - Get parent of clock * @hw: handle between common and hardware-specific interfaces * - * Return: Parent index + * Return: Parent index on success or number of parents in case of error */ static u8 zynqmp_clk_mux_get_parent(struct clk_hw *hw) { @@ -50,9 +50,15 @@ static u8 zynqmp_clk_mux_get_parent(struct clk_hw *hw) ret = zynqmp_pm_clock_getparent(clk_id, &val); - if (ret) + if (ret) { pr_warn_once("%s() getparent failed for clock: %s, ret = %d\n", __func__, clk_name, ret); + /* + * clk_core_get_parent_by_index() takes num_parents as incorrect + * index which is exactly what I want to return here + */ + return clk_hw_get_num_parents(hw); + } return val; } diff --git a/drivers/clk/zynqmp/pll.c b/drivers/clk/zynqmp/pll.c index abe6afbf3407..e025581f0d54 100644 --- a/drivers/clk/zynqmp/pll.c +++ b/drivers/clk/zynqmp/pll.c @@ -31,8 +31,9 @@ struct zynqmp_pll { #define PS_PLL_VCO_MAX 3000000000UL enum pll_mode { - PLL_MODE_INT, - PLL_MODE_FRAC, + PLL_MODE_INT = 0, + PLL_MODE_FRAC = 1, + PLL_MODE_ERROR = 2, }; #define FRAC_OFFSET 0x8 @@ -54,9 +55,11 @@ static inline enum pll_mode zynqmp_pll_get_mode(struct clk_hw *hw) int ret; ret = zynqmp_pm_get_pll_frac_mode(clk_id, ret_payload); - if (ret) + if (ret) { pr_warn_once("%s() PLL get frac mode failed for %s, ret = %d\n", __func__, clk_name, ret); + return PLL_MODE_ERROR; + } return ret_payload[1]; } @@ -126,7 +129,7 @@ static long zynqmp_pll_round_rate(struct clk_hw *hw, unsigned long rate, * @hw: Handle between common and hardware-specific interfaces * @parent_rate: Clock frequency of parent clock * - * Return: Current clock frequency + * Return: Current clock frequency or 0 in case of error */ static unsigned long zynqmp_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) @@ -138,14 +141,21 @@ static unsigned long zynqmp_pll_recalc_rate(struct clk_hw *hw, unsigned long rate, frac; u32 ret_payload[PAYLOAD_ARG_CNT]; int ret; + enum pll_mode mode; ret = zynqmp_pm_clock_getdivider(clk_id, &fbdiv); - if (ret) + if (ret) { pr_warn_once("%s() get divider failed for %s, ret = %d\n", __func__, clk_name, ret); + return 0ul; + } + + mode = zynqmp_pll_get_mode(hw); + if (mode == PLL_MODE_ERROR) + return 0ul; rate = parent_rate * fbdiv; - if (zynqmp_pll_get_mode(hw) == PLL_MODE_FRAC) { + if (mode == PLL_MODE_FRAC) { zynqmp_pm_get_pll_frac_data(clk_id, ret_payload); data = ret_payload[1]; frac = (parent_rate * data) / FRAC_DIV;