From mboxrd@z Thu Jan 1 00:00:00 1970 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=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 5342CC4338F for ; Tue, 10 Aug 2021 14:22:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DB1D61008 for ; Tue, 10 Aug 2021 14:22:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241017AbhHJOWX (ORCPT ); Tue, 10 Aug 2021 10:22:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:53076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241220AbhHJOSn (ORCPT ); Tue, 10 Aug 2021 10:18:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AD0BA6113A; Tue, 10 Aug 2021 14:16:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628605014; bh=g2axgpEiqQncxrpsW2enPeKOskjYFd7HPcFI71grzX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K8HYG+/+uYRZfUE+icuHMDTNeD3LAT1foqU+JhKGpxEBjjdBeM6DLZnOU4bK1PU3S 1YQVe5WMTdMO9SH22bdYM9RWxxnl6roc5smaKuuS7oHXU/jhDAfOZFMbZAhoyCAMxj XzPUHbUGTSOvyh4juga9TuI/GWsGvmlffJwjUYM0qtEH37u7XRweeQNFoAkCV2WGck s8zJAWY8RKE3yqtokCkZOM8j681y4UxaJGTrfTrkG7ygcPMUuVP4RLbeio9lb70Git zRH0c598w6xX0L3r5UW+mtK5a04pGgUcak1rDlYrWa+yZ8cEFrIeja8ANaYcTGJZNl W8Y5TsYvcnViw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Ivan T. Ivanov" , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 10/10] net: usb: lan78xx: don't modify phy_device state concurrently Date: Tue, 10 Aug 2021 10:16:41 -0400 Message-Id: <20210810141641.3118360-10-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210810141641.3118360-1-sashal@kernel.org> References: <20210810141641.3118360-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: "Ivan T. Ivanov" [ Upstream commit 6b67d4d63edece1033972214704c04f36c5be89a ] Currently phy_device state could be left in inconsistent state shown by following alert message[1]. This is because phy_read_status could be called concurrently from lan78xx_delayedwork, phy_state_machine and __ethtool_get_link. Fix this by making sure that phy_device state is updated atomically. [1] lan78xx 1-1.1.1:1.0 eth0: No phy led trigger registered for speed(-1) Signed-off-by: Ivan T. Ivanov Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/lan78xx.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 120e99914fd6..ff108611c5e4 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -1147,7 +1147,7 @@ static int lan78xx_link_reset(struct lan78xx_net *dev) { struct phy_device *phydev = dev->net->phydev; struct ethtool_link_ksettings ecmd; - int ladv, radv, ret; + int ladv, radv, ret, link; u32 buf; /* clear LAN78xx interrupt status */ @@ -1155,9 +1155,12 @@ static int lan78xx_link_reset(struct lan78xx_net *dev) if (unlikely(ret < 0)) return -EIO; + mutex_lock(&phydev->lock); phy_read_status(phydev); + link = phydev->link; + mutex_unlock(&phydev->lock); - if (!phydev->link && dev->link_on) { + if (!link && dev->link_on) { dev->link_on = false; /* reset MAC */ @@ -1170,7 +1173,7 @@ static int lan78xx_link_reset(struct lan78xx_net *dev) return -EIO; del_timer(&dev->stat_monitor); - } else if (phydev->link && !dev->link_on) { + } else if (link && !dev->link_on) { dev->link_on = true; phy_ethtool_ksettings_get(phydev, &ecmd); @@ -1457,9 +1460,14 @@ static int lan78xx_set_eee(struct net_device *net, struct ethtool_eee *edata) static u32 lan78xx_get_link(struct net_device *net) { + u32 link; + + mutex_lock(&net->phydev->lock); phy_read_status(net->phydev); + link = net->phydev->link; + mutex_unlock(&net->phydev->lock); - return net->phydev->link; + return link; } static void lan78xx_get_drvinfo(struct net_device *net, -- 2.30.2