Message ID | 20221104083004.2212520-1-linux@rasmusvillemoes.dk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp251098wru; Fri, 4 Nov 2022 01:33:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM68Q/Ci7KV14Fb5RSzbLJoeAPsXNSRluR0gtXL5d/eG9ismNgCgHfs/tV3gYutCH8GJhPP0 X-Received: by 2002:a17:90a:cb8b:b0:211:7744:d155 with SMTP id a11-20020a17090acb8b00b002117744d155mr51950285pju.187.1667550832407; Fri, 04 Nov 2022 01:33:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667550832; cv=none; d=google.com; s=arc-20160816; b=OA4Z9nkUrty6mQM/B6t4jvoCeG81sdcdHB5YZj5gjr5Lux39KKSGoaDbor4RSNHOcX BrbVq/Um3jzrlyf9b5Wi3i/4544giySOR0qU0UciKAuKJO+ReixhqwfdUx1PUX+z0nDV V3HSa6iy0B4jHg4iBuRwpD/cZm6ksGwEkR5UWMYniiJ55/jlvu0dCDsQbifopQlCkF4H cB6yy7r8qjHoUtg9kZr7X3qhtYMhoIJkfgLVHzDzRfFaKWcyhKwOYTmDd2+FvETzwWrF HvXj6ncwzkTD4oDiVRy/BCbp6xDY8h73zbRuByYVExIGTlFOf9EYQth5+vF4US097Fc5 UorQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=J0WWDPjFFiB5FkqfAdkJr8kHG7tGk0wrcMV56w0EsG4=; b=OewTXJJDWd9qrKAcO5mIJl7i+Ak1MTund8gj+Vo3AB68l+ZdJILEIDyIh1aslTPjYi fK7cKVwQiiZm2PTwsq66saElm1vaZYsqGMf60HeDcsNe/V/3j9zhI3MGY/S/WrB05alj PvRwVvpgsmh/D7gCnMXRFVjGstAU9kkU+htpY6hYXn9cZgC5Jlk+ilcdIB/jVb022DTD 8TF+bkORT34lVNnOhLi/A1Nk+4X6Mn4+M2OwXbavZYq9qPJwYBiRhnlCxnwd5Ki+uuli KaxyZCz7c/goYY6rEVYMW8CecVOO5G+Ra5qZibP5l9zVkzTnWKXnGe3jWTK0D17Bz812 1uTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=io9r1osc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4-20020a170902e5c400b00176c0e055d8si3519361plf.102.2022.11.04.01.33.39; Fri, 04 Nov 2022 01:33:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=io9r1osc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230509AbiKDIaP (ORCPT <rfc822;jimliu8233@gmail.com> + 99 others); Fri, 4 Nov 2022 04:30:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230526AbiKDIaJ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 4 Nov 2022 04:30:09 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A94FD275F6 for <linux-kernel@vger.kernel.org>; Fri, 4 Nov 2022 01:30:08 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id ud5so11431945ejc.4 for <linux-kernel@vger.kernel.org>; Fri, 04 Nov 2022 01:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=J0WWDPjFFiB5FkqfAdkJr8kHG7tGk0wrcMV56w0EsG4=; b=io9r1oscZpSSorDwWffkeSVLwWaxKhBdOA8oHFnKzyms3Tu9/GHZ+y5kkr+SNxbxnz FxrQVrq2wOxmdMFLrCsI00zYdSEF23biFhxbj/bl8ISM3fVUw61gZMvo/1cmH5G/2Ivu FLz0Xuiw5RyRILnUExDVTfN+uGp7F1vi5bSTo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=J0WWDPjFFiB5FkqfAdkJr8kHG7tGk0wrcMV56w0EsG4=; b=OuI1qA2l61J8zTO69zj5plT0nMRTb0mrPeYHKehwCnO8KAynrPFmfiqvclPSTMAN+X dsdC5e6jKNZQdQ4lj2nbKoNXmnHsl1AqO5HRwFs+P3o4R8UNXzBHF2g6ioA6mWFgpndp k/Q7H9KTVJokjBbSyfOCt+oPHHwbFVAGlHCdJq429Hy7v9SzyLYcSqqHRSHHkLTNvSCL 6KwimJFzTzeWgCwMlbwSaKinvN7P1IVDsDABJArnEo4XV4Rciy3DQyz8OXkJzRcYYoIQ ouLpY2gpVrsK54d//CDt6Xs3QZsfGuvzj8fpB1TlGUXmiiDc4lw5OBKkN8Si5qQc1lWE +V8A== X-Gm-Message-State: ACrzQf0420LTAUMis3FI1J0yBZBvLhyNmbRnDEIREkxHn8hfe1Ugb+Ar 5rJ7AE7yzB7+MWnaZnBIT0tgSmyifWdIpeVjqKA= X-Received: by 2002:a17:907:97ca:b0:791:644c:491e with SMTP id js10-20020a17090797ca00b00791644c491emr33081519ejc.555.1667550607180; Fri, 04 Nov 2022 01:30:07 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id d8-20020a170906344800b0073dc5bb7c32sm1505870ejb.64.2022.11.04.01.30.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 01:30:06 -0700 (PDT) From: Rasmus Villemoes <linux@rasmusvillemoes.dk> To: Martin Blumenstingl <martin.blumenstingl@googlemail.com>, Andrew Lunn <andrew@lunn.ch>, "David S . Miller" <davem@davemloft.net> Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Rasmus Villemoes <linux@rasmusvillemoes.dk> Subject: [PATCH] net: stmmac: dwmac-meson8b: fix meson8b_devm_clk_prepare_enable() Date: Fri, 4 Nov 2022 09:30:04 +0100 Message-Id: <20221104083004.2212520-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748553781634546871?= X-GMAIL-MSGID: =?utf-8?q?1748553781634546871?= |
Series |
net: stmmac: dwmac-meson8b: fix meson8b_devm_clk_prepare_enable()
|
|
Commit Message
Rasmus Villemoes
Nov. 4, 2022, 8:30 a.m. UTC
There are two problems with meson8b_devm_clk_prepare_enable(),
introduced in a54dc4a49045 (net: stmmac: dwmac-meson8b: Make the clock
enabling code re-usable):
- It doesn't pass the clk argument, but instead always the
rgmii_tx_clk of the device.
- It silently ignores the return value of devm_add_action_or_reset().
The former didn't become an actual bug until another user showed up in
the next commit, 9308c47640d5 (net: stmmac: dwmac-meson8b: add support
for the RX delay configuration). The latter means the callers could
end up with the clock not actually prepared/enabled.
Fixes: a54dc4a49045 (net: stmmac: dwmac-meson8b: Make the clock enabling code re-usable)
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
Not tested in any way, just stumbled on this which didn't seem right.
It seems that the timing_adj_clk could be changed (with a bit of
refactoring) to use devm_clk_get_enabled() - i.e. don't make it
optional, but only get/prepare/enable it in the (delay_config &
PRG_ETH0_ADJ_ENABLE) branch where the code actually requires it.
But since there's no official devm_clk_prepare_enable, and the
rgmii_tx_clk isn't obtained via a clk_get, I don't see a simple way to
avoid this private implmentation of devm_clk_prepare_enable().
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
Comments
Hello Rasmus, Thanks for your patch! It would be great if you could Cc linux-amlogic@lists.infradead.org in v2 of this patch, so other Amlogic SoC maintainers can also provide their feedback. On Fri, Nov 4, 2022 at 9:30 AM Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote: > > There are two problems with meson8b_devm_clk_prepare_enable(), > introduced in a54dc4a49045 (net: stmmac: dwmac-meson8b: Make the clock > enabling code re-usable): > > - It doesn't pass the clk argument, but instead always the > rgmii_tx_clk of the device. Indeed, this is a problem - thanks for fixing this! > - It silently ignores the return value of devm_add_action_or_reset(). This second part is not so easy. The thought process back when this code was implemented was: let's continue loading of the driver even if devm_add_action_or_reset() fails as this just means during shutdown/rmmod we don't disable all clocks. If we want to propagate the error code returned by devm_add_action_or_reset() then we also need to do the clean up within meson8b_devm_clk_prepare_enable(), meaning we need to call clk_disable_unprepare() in case devm_add_action_or_reset() failed. Your change just propagates the error code without disabling and unpreparing the clock. [...] > The latter means the callers could > end up with the clock not actually prepared/enabled. In my opinion this statement is not correct: even if devm_add_action_or_reset() fails the clock will be prepared and enabled (by clk_prepare_enable() right before). Personally I would just change the clk argument and keep the return 0. What do you think? Best regards, Martin
Rasmus replied to me off-list yesterday. His reply is important so I am sharing it here. On Fri, Nov 4, 2022 at 10:02 PM Martin Blumenstingl <martin.blumenstingl@googlemail.com> wrote: [...] > If we want to propagate the error code returned by > devm_add_action_or_reset() then we also need to do the clean up within > meson8b_devm_clk_prepare_enable(), meaning we need to call > clk_disable_unprepare() in case devm_add_action_or_reset() failed. > Your change just propagates the error code without disabling and > unpreparing the clock. Rasmus replied to me: "devm_add_action_or_reset precisely calls the reset callback for you if the add action falls..." I was not aware of this but it's actually true, which makes the patch perfectly valid. Thanks for the heads up Rasmus! So this patch gets my: Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com> I suggest applying it to net-next (even though it carries a Fixes tag) so the various kernel auto testing labs can try it out on as many Amlogic SoCs as possible. Best regards, Martin
Hello: This patch was applied to netdev/net.git (master) by Jakub Kicinski <kuba@kernel.org>: On Fri, 4 Nov 2022 09:30:04 +0100 you wrote: > There are two problems with meson8b_devm_clk_prepare_enable(), > introduced in a54dc4a49045 (net: stmmac: dwmac-meson8b: Make the clock > enabling code re-usable): > > - It doesn't pass the clk argument, but instead always the > rgmii_tx_clk of the device. > > [...] Here is the summary with links: - net: stmmac: dwmac-meson8b: fix meson8b_devm_clk_prepare_enable() https://git.kernel.org/netdev/net/c/ed4314f77297 You are awesome, thank you!
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c index c7a6588d9398..e8b507f88fbc 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c @@ -272,11 +272,9 @@ static int meson8b_devm_clk_prepare_enable(struct meson8b_dwmac *dwmac, if (ret) return ret; - devm_add_action_or_reset(dwmac->dev, - (void(*)(void *))clk_disable_unprepare, - dwmac->rgmii_tx_clk); - - return 0; + return devm_add_action_or_reset(dwmac->dev, + (void(*)(void *))clk_disable_unprepare, + clk); } static int meson8b_init_rgmii_delays(struct meson8b_dwmac *dwmac)