Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13133118pxu; Sun, 3 Jan 2021 03:20:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyD3oD2e7T2I8OUJzxv4Pt7M2j5Z76KZrmaA/+nZiUBiwg4qhIwD5FvPZUG0c726dSiKZKM X-Received: by 2002:a17:906:4705:: with SMTP id y5mr62470724ejq.112.1609672855265; Sun, 03 Jan 2021 03:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609672855; cv=none; d=google.com; s=arc-20160816; b=0omG7hm4DbwkaVxv49UJOlExHIv8eTa9ruAa/UOHYFBdPwuufWvf6px90UfEVTfT/3 YOsPlpO5aQZ6wMlv2YgoUz5O0/+gyWhG7YJUif76Pjg4pAWHdfdAgGXs/kMzordPhY5E 64ID1u1vWcotRIy6+Rd7Bd3yg+uwpxVAkJ53Qe+nwJo8ftzLzdmgu6yGYRwxaOjsCTnU K6ReumtIZx7rfboaFL4B/AlNPw4FWrj8Dubx8peT4hmzv1GU8fg36mgZi75Gy0oLFY2k qnXEewxLR7AcILX9kcwI50zUnsz65bXVpkjvDAeuIV4Ku+X8Eew3x4yHAcYd4X3TO+V7 H+qA== 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:dkim-signature; bh=J5Cq+Ae4IPa+R9jD99wSE69PUYZG8kpNxitzJfWW+B0=; b=LYhXBJh9MTmMsFhrgVmNzJG9dQIoFboHCYwY5GFbinB8WGlMfmk9jmMVBv32IaWf9T lV3MNbkUafl/ckYC/O72iTG/mXTJSEwEsmAp0WLoRmJ0XaDtLcAVtdEzmca2MAVmKlu3 UU9Rcy8qeucx+d+jw4Uow8JV5jRfUVHqlayBssUaxCu996TmRPUwWT8IGLvT1cIAj0Zx zPk6JP1+geuzy9ig4NCB4pRZOGSnErAdb/kUJukwi1DtrnAs2W56O9dhMZFiCsmgJ+Az nldb+Tb7aLuc9N015hbtbbcGHZ9e3cwEOw6DlKT9+B3C2LLlJfPUDLa2pYXAOJAQ8Sku yRpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm1 header.b=PhbZctLp; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ZmLtaDcI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n18si27919356ejr.448.2021.01.03.03.20.32; Sun, 03 Jan 2021 03:20:55 -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=@sholland.org header.s=fm1 header.b=PhbZctLp; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ZmLtaDcI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726487AbhACLSg (ORCPT + 99 others); Sun, 3 Jan 2021 06:18:36 -0500 Received: from wnew4-smtp.messagingengine.com ([64.147.123.18]:48299 "EHLO wnew4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726074AbhACLSe (ORCPT ); Sun, 3 Jan 2021 06:18:34 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.west.internal (Postfix) with ESMTP id 70660548; Sun, 3 Jan 2021 06:17:47 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sun, 03 Jan 2021 06:17:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=J5Cq+Ae4IPa+R 9jD99wSE69PUYZG8kpNxitzJfWW+B0=; b=PhbZctLps1kZBBbDdz5hYMa1IVRkt AVFIW2QokrvxIMeuWiZ6McJKN72VOndxLHsUaDTic+auyrhWAaSCgDRFk8+aQBWa 7ZG18QFr12SVLjMYszVX5HQVYH1syexUIEhS/9gOn0BN7l4ltjzQSNTDUXOv/BPj S829E0WrK/YnoNTyyuUqnVMM64YiRntnZFD4wdWFg25bvTb7Zi43vLu3Phhh3CD5 KHdIIdHo1dFHVvvwOPv5k7zLrEc0Zh6olpXFUSLwqtmTEVEAz+Uf6DJMiwyVGIRd CU/OHKKlqP5HqG7IUyYlsouGU/PGskAoSvXowRML385z0CCQUlVLA9odg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=J5Cq+Ae4IPa+R9jD99wSE69PUYZG8kpNxitzJfWW+B0=; b=ZmLtaDcI pkFbM+OiRbDP+yltkdEg13hAWg0eM9pdHEFXcNcDYLNY9Wt4uFxjZ1UzB0P5IFkC 7NrhYE9IJ4FBfz/72k1kdlg3UIGzeKRe23ZpmtTG9idy6dGREHp80DaJJC8+LIGY +nUWkwlJ4xH96/rWBVAFt6uQgAkm0b9mOM507+bo+UCCwc5ww6mRVFeZy2aisnn8 fdi/2xr4BwmhFFm+MrGXX3Yqfy3H0F/CMFhu6d+XAmlU1HBLcsOrYC9hC05WIl17 oAFaQerIAuAYtM953DNvweyfEM08no5rOxHcatXXxLoZ5FCw2YznUAKG0OGx0urg TUSvFBnG8papmQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdefuddgvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucfkphepjedtrddufeehrddugeekrdduhedunecuvehluhhsthgvrhfuih iivgepudenucfrrghrrghmpehmrghilhhfrhhomhepshgrmhhuvghlsehshhholhhlrghn ugdrohhrgh X-ME-Proxy: Received: from titanium.stl.sholland.net (70-135-148-151.lightspeed.stlsmo.sbcglobal.net [70.135.148.151]) by mail.messagingengine.com (Postfix) with ESMTPA id CF6781080059; Sun, 3 Jan 2021 06:17:45 -0500 (EST) From: Samuel Holland To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec , Corentin Labbe Cc: Ondrej Jirman , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH net 2/4] net: stmmac: dwmac-sun8i: Balance internal PHY resource references Date: Sun, 3 Jan 2021 05:17:42 -0600 Message-Id: <20210103111744.34989-3-samuel@sholland.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103111744.34989-1-samuel@sholland.org> References: <20210103111744.34989-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While stmmac_pltfr_remove calls sun8i_dwmac_exit, the sun8i_dwmac_init and sun8i_dwmac_exit functions are also called by the stmmac_platform suspend/resume callbacks. They may be called many times during the device's lifetime and should not release resources used by the driver. Furthermore, there was no error handling in case registering the MDIO mux failed during probe, and the EPHY clock was never released at all. Fix all of these issues by moving the deinitialization code to a driver removal callback. Also ensure the EPHY is powered down before removal. Fixes: 634db83b8265 ("net: stmmac: dwmac-sun8i: Handle integrated/external MDIOs") Signed-off-by: Samuel Holland --- .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index b20f261fce5b..a05dee5d4584 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -1004,17 +1004,12 @@ static void sun8i_dwmac_exit(struct platform_device *pdev, void *priv) struct sunxi_priv_data *gmac = priv; if (gmac->variant->soc_has_internal_phy) { - /* sun8i_dwmac_exit could be called with mdiomux uninit */ - if (gmac->mux_handle) - mdio_mux_uninit(gmac->mux_handle); if (gmac->internal_phy_powered) sun8i_dwmac_unpower_internal_phy(gmac); } sun8i_dwmac_unset_syscon(gmac); - reset_control_put(gmac->rst_ephy); - clk_disable_unprepare(gmac->tx_clk); if (gmac->regulator) @@ -1244,6 +1239,8 @@ static int sun8i_dwmac_probe(struct platform_device *pdev) return ret; dwmac_mux: + reset_control_put(gmac->rst_ephy); + clk_put(gmac->ephy_clk); sun8i_dwmac_unset_syscon(gmac); dwmac_remove: stmmac_dvr_remove(&pdev->dev); @@ -1255,6 +1252,24 @@ static int sun8i_dwmac_probe(struct platform_device *pdev) return ret; } +static int sun8i_dwmac_remove(struct platform_device *pdev) +{ + struct net_device *ndev = platform_get_drvdata(pdev); + struct stmmac_priv *priv = netdev_priv(ndev); + struct sunxi_priv_data *gmac = priv->plat->bsp_priv; + + if (gmac->variant->soc_has_internal_phy) { + mdio_mux_uninit(gmac->mux_handle); + sun8i_dwmac_unpower_internal_phy(gmac); + reset_control_put(gmac->rst_ephy); + clk_put(gmac->ephy_clk); + } + + stmmac_pltfr_remove(pdev); + + return 0; +} + static const struct of_device_id sun8i_dwmac_match[] = { { .compatible = "allwinner,sun8i-h3-emac", .data = &emac_variant_h3 }, @@ -1274,7 +1289,7 @@ MODULE_DEVICE_TABLE(of, sun8i_dwmac_match); static struct platform_driver sun8i_dwmac_driver = { .probe = sun8i_dwmac_probe, - .remove = stmmac_pltfr_remove, + .remove = sun8i_dwmac_remove, .driver = { .name = "dwmac-sun8i", .pm = &stmmac_pltfr_pm_ops, -- 2.26.2