Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp26292pxb; Fri, 15 Jan 2021 05:02:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyI01VWwl+/hL970dYtshjT/TluOsWBeCjNzz/6sBbyvAjtXxLfIR6YrmJvbIZyrPpU/bq0 X-Received: by 2002:a17:906:1194:: with SMTP id n20mr8556635eja.269.1610715769263; Fri, 15 Jan 2021 05:02:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610715769; cv=none; d=google.com; s=arc-20160816; b=li3YABHI9S8y5T1ONO0a+2zSZdwHNVYSYUKiJEZ4Vew/7nWXR7ZAtkUt0G74MLbFqI 0GxJi1OchS0n1xbTiT21uuBgXhsxt2GJeEWUZonIajvPtgaStQ3eEz+bO8pvsumm8aGb uScTLDXjPCJcrmhl8t1YQ01ZZB/6AEW8KnQQpiF1okkgJ07NEQcyAtlgeZdUVdZuqpAS EqE4rju3M1KxgPzUmpDrngxs0W7Ww1WhofTCl0qEj6GaKaGau6N9DHfVoeelWAupIJgF 48JE3aPgfVjUmUqj1GbeaEG6O29aI/2iv+U8iMplgC//z+ZNrPWJWsggT3pqAoKm5ZHH lmmQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ERAmlbye3JDUxK5Yk4GFOe4rDjkIO7/sGWUwVtruA88=; b=fDlOEs9fLmutAeDinFYVLCpyBSPUUZokNBo5Ca69cP0LEmtlZ0QIY7HhESYhAdRhsm s/4v8ZbaaH8CRMdvAZI5CLb7wkj2YRrs5CPUo4FMI+r0EWbl8ur8ndcxm0ERaw2qhfX/ 8hsCs0a0dJYpcK165VPRlzeuZkWuRLmXjjgZ5+6DoMFD1HHEOZjzUAg4ThRzbGiifAdd cUUEpKwxiX4b4zvDS0l0PqS4xFEFw3mTxqRKJLJ+MVh4qj0u/1EPkF5+shOmEt7wt1A3 AcwmMhhTuo2kEk9aMWEX54eepOTBTLtmICY7fyJ5pU1+vo74605E7shk8bW7KB0oq5/d hAtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xHM79AvL; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si4105095ejd.572.2021.01.15.05.02.25; Fri, 15 Jan 2021 05:02:49 -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=@linuxfoundation.org header.s=korg header.b=xHM79AvL; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732118AbhAOMd1 (ORCPT + 99 others); Fri, 15 Jan 2021 07:33:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:40158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733114AbhAOMdS (ORCPT ); Fri, 15 Jan 2021 07:33:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BEDC1236FB; Fri, 15 Jan 2021 12:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610713958; bh=yWfLeIEoVaTz3bbqeY31OXGdT7qEDtlO7fclFC3PiE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xHM79AvLHpE/C4z/uorvw1R1x8umVDryV2uXyOVkwJ5KaZDzqlfcIYvW7VVc/zc2O gcYuC7z0843Bhy/eo+0OA2cpK3IissaKycrKTDBIyojkNo3+N2DcKnbbE5X0TnPW4W AvQ7sM2S6vQQFboXTFUmc5QOAcMNganox3Vz26/0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Samuel Holland , Chen-Yu Tsai , "David S. Miller" Subject: [PATCH 4.19 03/43] net: stmmac: dwmac-sun8i: Balance internal PHY resource references Date: Fri, 15 Jan 2021 13:27:33 +0100 Message-Id: <20210115121957.214412897@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121957.037407908@linuxfoundation.org> References: <20210115121957.037407908@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Samuel Holland [ Upstream commit 529254216773acd5039c07aa18cf06fd1f9fccdd ] 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 Reviewed-by: Chen-Yu Tsai Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -977,17 +977,12 @@ static void sun8i_dwmac_exit(struct plat 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) @@ -1200,12 +1195,32 @@ static int sun8i_dwmac_probe(struct plat return ret; dwmac_mux: + reset_control_put(gmac->rst_ephy); + clk_put(gmac->ephy_clk); sun8i_dwmac_unset_syscon(gmac); dwmac_exit: stmmac_pltfr_remove(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 }, @@ -1223,7 +1238,7 @@ MODULE_DEVICE_TABLE(of, sun8i_dwmac_matc 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,