Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2905685pxb; Tue, 24 Aug 2021 10:17:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIL2TZVNqQmhanpk+Nfzj349uQq/A3IOBkux6j0rAUX/b56YUeu5RiVXXKKRsjm8kRe0U0 X-Received: by 2002:a92:cb08:: with SMTP id s8mr26565390ilo.166.1629825464718; Tue, 24 Aug 2021 10:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825464; cv=none; d=google.com; s=arc-20160816; b=l3DoybJkgH3lNm65oifsvO74ewQASV8Ry3ZZjJxJi++oCbLhYS9q2PWdVzcJ/q6zqA jui2bWmti9rhaSS+9v8jCJBc7OeyLlfoIiZBE+MUyzxeOPT2LkNwir88NpIPI9OWd2qF iZiGkzcieWwyM+ogqH/vSCY/CzZZC5AllCc4+oDrdTCyXnUqNf735GNDZ04iGPXxvr/B uKECo55BrDjKicLLZjaMDDF3rJ/qxEaOAQq4jO9Zjk24ataiHJEfo5Xc60x9/38XJUhX U34Gd4BqUyLoEii3c6b/Z6fCIX3muOOsWO/znDVWTZ0qSGQEVOV+aMqlfdv4HrH+YYda x1uA== 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=jgJNZjOoS8AmWSxIxJli/SrRXKksx7PtZzbLF0VDNj4=; b=U4xnu542V68yhjlA4qYhaCccZvUH0EAC0PZcgkmM+diUP7KQrd0Ddn7JKvfcHECxKk FOUHGg/bzmwstJJsda6ko7Qd35sP5tMwa9WYhiWSApLCYGoXWSjpFFa87RJfhGOcIJ2A 9DCFSlM2r2W8CsjyjPWGwG9KP/ybc/czM2BFnjRrhF9IKQbbXmEyxYkyuMOFUzye/WZt ZY3K63umXG4W0oMD0Diz/sL96Ru+mGxg3nf8dfSrZDtiSMCbcVrSBNmeBVsVu5y2LYc9 Y8gT96igFhtCAPuX9OiWKV7ztHFmAh+OsMm5P0z0K5QdQJpmM09yUMpG+1RxhacTKpGN cZ9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G1kMt2Oq; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si18174868ilu.92.2021.08.24.10.17.33; Tue, 24 Aug 2021 10:17:44 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=G1kMt2Oq; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239607AbhHXRQo (ORCPT + 99 others); Tue, 24 Aug 2021 13:16:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:51854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240006AbhHXRNa (ORCPT ); Tue, 24 Aug 2021 13:13:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C8966152B; Tue, 24 Aug 2021 17:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824490; bh=yPkuca/mvbHkZv4BfPorv3z/PyxKy5kugxNdJIkTiOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G1kMt2OqyMqPsj6mcXNYhFEmPdRn4lIij1Nr0rSIVa7dvWro8NpfvEVUEdcGBLk/z AwMoMufPJXhpLhqJYVzIEeQIALte7a8ny5kUWYwm/HYBDjVuM0oSoG5rUroqjnuJa6 MEpHAKhG9Mb0XbT2om5CTUnKkcR6Xw3imXyeShZ0VkxNJHxy4fd7ubh78vL0A0cMER TGSE7XizGvkWJByEfsjxPnTrRDjhgu/zOWpb9u6zYzb6i+1OMsVtRrb6pA+1ymbbU6 YlJROCDasEkXJGNZA/BTcRwLJiDjlJ2ygPbcDKDqigDmqpRKZrjmiP4mz1RbRIEAqj il+APXCq4zbFQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Ivan T. Ivanov" , "David S . Miller" , Sasha Levin Subject: [PATCH 5.4 22/61] net: usb: lan78xx: don't modify phy_device state concurrently Date: Tue, 24 Aug 2021 13:00:27 -0400 Message-Id: <20210824170106.710221-23-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170106.710221-1-sashal@kernel.org> References: <20210824170106.710221-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.143-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.4.143-rc1 X-KernelTest-Deadline: 2021-08-26T17:01+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 71cc5b63d8ce..92d9d3407b79 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -1159,7 +1159,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 */ @@ -1167,9 +1167,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 */ @@ -1182,7 +1185,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); @@ -1471,9 +1474,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