Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2508161pxb; Sun, 23 Jan 2022 06:58:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwauijaFmg3+plnDrpmJItZpljGE6aJinIGjF4M8kczGU6VicU6NVI1j8nlya1SFtOfs3ub X-Received: by 2002:a17:902:bf09:b0:149:d2a3:ddac with SMTP id bi9-20020a170902bf0900b00149d2a3ddacmr11087396plb.4.1642949937916; Sun, 23 Jan 2022 06:58:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642949937; cv=none; d=google.com; s=arc-20160816; b=jNd+L27m6fvP/X6OxWVInRQi9HwwaMud92+ysO84denlJn/q0ToRGFHT/bTxh4a35I hBSwpVzPWVgZ+VAgF/s+bd0hr3z+Dy7Apm4vfFAqaUT//Ro6Wh9ARr+shXa9WNp3oJSN u3D8xOVJhAJU4ST77iE9u/k4pOq1JBw91NGNpXAzDRVpzH9LP07VIc9CVJTgeHz5RTIr a4exNaf3OLPiDy+0fdEpmr4aWz7VNfC204I5qjoG8QmyUwrZRg8xL/8ptEpWS2GwB7uF UiS8bXmw/ezmlDuH1zHwmB9SYZCOEl3o3Ftf4v+cQqOKRCif4gju4bkic43N/zHvDBTW Eo+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=x4l7SdSy/ZXICUFfVEpfugcTxefmMymFj4v54f2ETqQ=; b=dtS3v5VDUiSKXH3Gfr8PcbUCjcQOqc7fBVtJSAowJuBrWbyL237jE2hIH/36x/b3ic RZcnTfXvgyyKDn1sscBr915E0RRWzWJm2LOhJKyzg279gvbV7ejJwXDfpbQ2Itc1rwoN dUFDWumApGiSLRoQWMeBQI8bOtWdXX07zt1IFDcOt4qe3qIvQNx0qDsJp+YHCXRRj7nC cJRggnFC8egA+DA/Qlr3W8yTd0GE3eF2p/O81JBPk+BwxNBfi7NcBrIls9RITcNWoRnL RaPDLRjm4GgZFUgjIsClcDqkiiKb87Bs6ZOVmcofGkerwA/Wh9Lm9X0t0/wRirQOF6AM CcVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZtWNhNbC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si11401343pga.784.2022.01.23.06.58.46; Sun, 23 Jan 2022 06:58:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZtWNhNbC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234444AbiAVJUg (ORCPT + 99 others); Sat, 22 Jan 2022 04:20:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234093AbiAVJT4 (ORCPT ); Sat, 22 Jan 2022 04:19:56 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9DC2C061793 for ; Sat, 22 Jan 2022 01:18:53 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id l17so4686151plg.1 for ; Sat, 22 Jan 2022 01:18:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=x4l7SdSy/ZXICUFfVEpfugcTxefmMymFj4v54f2ETqQ=; b=ZtWNhNbC7GUN2q0P8diAFmhrWmdYlpRqqosydKBUFWfUVfCAzBHykWE2mm3SNWMcbt hLqFzAAmx9ZIv0Cd/Qs/0SZ5jFQ+DVHCB/jXrjLgOzlb1ZPwJefdOp1lRBYZCTFC9wNx QhICe9kzg1brGAAj4mFqYZofkdvjCsNcdEdOk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x4l7SdSy/ZXICUFfVEpfugcTxefmMymFj4v54f2ETqQ=; b=BPi+a1rSdTZMUNqIlCqoCZd7A4weMnT/vKJX/EiWiKx4QlnrKrU6IVDQWgE3ywk0Rw EPIDnXtFP1k2O9oppfloiEa+D1cRwZC409Qw5bAGjZPhfT9YjnzLz7pf4h3BJx6s1bnZ iKRU8pJmx/1glEmdCDjkD32VT6dFCqItHkei+i/Az6wa+BKGmCISTMUj7ajFgp3H5oKR SJ6CwVtGPx4qb7JLJNZaFzxl8lhVGBTajSRDQMyLn3xZIfr5rKE2vZxBIxmoZjmuDdPY bGOE2fwILZlBuoU/csqS21WA+t1pgCHbXkupdFbAs/UUD23AQpmIbZf+oqZHk2OuwONa nCMg== X-Gm-Message-State: AOAM530d44wr6NuLCH8ciPcXCg9SK8T0C19Isy+Rn/P5vKysxvLlb125 T8tTt1PjKXzG4Vln1amrU2d5fQ== X-Received: by 2002:a17:90b:4f46:: with SMTP id pj6mr4441477pjb.213.1642843133462; Sat, 22 Jan 2022 01:18:53 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:349f:9373:45d9:eb26]) by smtp.gmail.com with ESMTPSA id s1sm1608100pjn.42.2022.01.22.01.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jan 2022 01:18:53 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 31/31] clk: mediatek: Warn if clk IDs are duplicated Date: Sat, 22 Jan 2022 17:17:31 +0800 Message-Id: <20220122091731.283592-32-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220122091731.283592-1-wenst@chromium.org> References: <20220122091731.283592-1-wenst@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Mediatek clk driver library handles duplicate clock IDs in two different ways: either ignoring the duplicate entry, or overwriting the old clk. Either way may cause unexpected behavior, and the latter also causes an orphan clk that cannot be cleaned up. Align the behavior so that later duplicate entries are ignored, and a warning printed. The warning will also aid in making the issue noticeable. Signed-off-by: Chen-Yu Tsai --- drivers/clk/mediatek/clk-cpumux.c | 6 ++++++ drivers/clk/mediatek/clk-gate.c | 5 ++++- drivers/clk/mediatek/clk-mtk.c | 18 ++++++++++++++---- drivers/clk/mediatek/clk-mux.c | 5 ++++- drivers/clk/mediatek/clk-pll.c | 6 ++++++ 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/drivers/clk/mediatek/clk-cpumux.c b/drivers/clk/mediatek/clk-cpumux.c index 499c60432280..c11b3fae622e 100644 --- a/drivers/clk/mediatek/clk-cpumux.c +++ b/drivers/clk/mediatek/clk-cpumux.c @@ -120,6 +120,12 @@ int mtk_clk_register_cpumuxes(struct device_node *node, for (i = 0; i < num; i++) { const struct mtk_composite *mux = &clks[i]; + if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) { + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", + node, mux->id); + continue; + } + clk = mtk_clk_register_cpumux(mux, regmap); if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", mux->name, clk); diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c index 631ff170b7b9..da52023f8455 100644 --- a/drivers/clk/mediatek/clk-gate.c +++ b/drivers/clk/mediatek/clk-gate.c @@ -224,8 +224,11 @@ int mtk_clk_register_gates_with_dev(struct device_node *node, for (i = 0; i < num; i++) { const struct mtk_gate *gate = &clks[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[gate->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[gate->id])) { + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", + node, gate->id); continue; + } clk = mtk_clk_register_gate(gate->name, gate->parent_name, regmap, diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 6d0b8842971b..b2a3568922b2 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -65,8 +65,10 @@ int mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num, for (i = 0; i < num; i++) { const struct mtk_fixed_clk *rc = &clks[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[rc->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[rc->id])) { + pr_warn("Trying to register duplicate clock ID: %d\n", rc->id); continue; + } clk = clk_register_fixed_rate(NULL, rc->name, rc->parent, 0, rc->rate); @@ -128,8 +130,10 @@ int mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num, for (i = 0; i < num; i++) { const struct mtk_fixed_factor *ff = &clks[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[ff->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[ff->id])) { + pr_warn("Trying to register duplicate clock ID: %d\n", ff->id); continue; + } clk = clk_register_fixed_factor(NULL, ff->name, ff->parent_name, CLK_SET_RATE_PARENT, ff->mult, ff->div); @@ -300,8 +304,11 @@ int mtk_clk_register_composites(const struct mtk_composite *mcs, int num, for (i = 0; i < num; i++) { const struct mtk_composite *mc = &mcs[i]; - if (clk_data && !IS_ERR_OR_NULL(clk_data->clks[mc->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[mc->id])) { + pr_warn("Trying to register duplicate clock ID: %d\n", + mc->id); continue; + } clk = mtk_clk_register_composite(mc, base, lock); @@ -363,8 +370,11 @@ int mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num, for (i = 0; i < num; i++) { const struct mtk_clk_divider *mcd = &mcds[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id])) { + pr_warn("Trying to register duplicate clock ID: %d\n", + mcd->id); continue; + } clk = clk_register_divider(NULL, mcd->name, mcd->parent_name, mcd->flags, base + mcd->div_reg, mcd->div_shift, diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c index f51e67650f03..21ad5a4afd65 100644 --- a/drivers/clk/mediatek/clk-mux.c +++ b/drivers/clk/mediatek/clk-mux.c @@ -208,8 +208,11 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes, for (i = 0; i < num; i++) { const struct mtk_mux *mux = &muxes[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) { + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", + node, mux->id); continue; + } clk = mtk_clk_register_mux(mux, regmap, lock); diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c index 1dd15f560659..e5e9c188be99 100644 --- a/drivers/clk/mediatek/clk-pll.c +++ b/drivers/clk/mediatek/clk-pll.c @@ -386,6 +386,12 @@ int mtk_clk_register_plls(struct device_node *node, for (i = 0; i < num_plls; i++) { const struct mtk_pll_data *pll = &plls[i]; + if (!IS_ERR_OR_NULL(clk_data->clks[pll->id])) { + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", + node, pll->id); + continue; + } + clk = mtk_clk_register_pll(pll, base); if (IS_ERR(clk)) { -- 2.35.0.rc0.227.g00780c9af4-goog