Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp3070977pxy; Wed, 4 Aug 2021 01:18:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypSBJUa7SohKOfPz01PNgRaJFu0GA4BQAyAbLaiPyxqSbrilEZpvKskZtW/R8McOydRbTL X-Received: by 2002:a17:906:dfe8:: with SMTP id lc8mr25399613ejc.347.1628065092326; Wed, 04 Aug 2021 01:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628065092; cv=none; d=google.com; s=arc-20160816; b=VPusDhNUmFgLCEQzBrbsg2igamMCwiNYqJjSuZ0seSeXyEJfQOkPB6mJcX0hszOfbQ C+c1FWb0u6kvySZ7gbbOZoVLWoZcaw+5vxh0KHnpsuMlOt64Dp+qQWdxGCFRF1FJDcb9 jrPSuv2Q9zpWYdvucHd2cGQ3p/efJIHSR31bQ4oAIuDRWYzOKg1qz1+9cNl3V6Q1Jnnd /H4qJXRktP0NGDynDutMGxwa5WswNv418zL/od3fS0JnyGzQ3JwhQiYy8uvKodUsH16a e5Dl8tER8zL9Qe5/nIfgbW0vMI8VCKsQbKNfcHHTIAMQREReGnmelzGxqjBVbsUbtr8a a+6w== 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:dkim-signature; bh=8keho363Sl2gUx4aN/xeXttCB1j0pnXy2aa4KQk3nRM=; b=IkPHvbvw1i3TyEFDTn9PpZ8pfYuhwjPkx2KDF8Ydf9q6W+DqJJFozYTpMWNsKplGew 36RlL43lDA58ch1v/ZjaAl4pN6N6bpENC3BQWfdt7r6Gn45AUgY2mGx1xQ00TPYWfXb7 L6ltsRlrzcAZnFiP1tO//8GrFI7KX6BFvQFuMxFm+tKttPwK6NHjywhGilzAl8II5+ss ywqodZYeAq4HWQGMEAgPHH4597Wf2UH4GlE47arjeZxwaPz7oEE66uJpuzwg1oEzNTzJ Sl5tu5khfQaTlnSuv6ntFErU3TuiTbnY+SiGzcQXMKo5p/GT6PWkXQ8gL4RyD+cpq4nV ar9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=wPyEEXFX; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=JUgqddh4; 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 v11si1576198edx.190.2021.08.04.01.17.48; Wed, 04 Aug 2021 01:18:12 -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=@suse.de header.s=susede2_rsa header.b=wPyEEXFX; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=JUgqddh4; 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 S236182AbhHDIOQ (ORCPT + 99 others); Wed, 4 Aug 2021 04:14:16 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:54750 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236243AbhHDIOO (ORCPT ); Wed, 4 Aug 2021 04:14:14 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C0411221B5; Wed, 4 Aug 2021 08:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1628064840; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=8keho363Sl2gUx4aN/xeXttCB1j0pnXy2aa4KQk3nRM=; b=wPyEEXFXSSLesVtRLQGtfXXzmJN2Z3mDLpd8xT2x6uaUOoUTzyck+ifeUjhyanzcbcHIOy glsUMfwk9uOCmkNSw99WPGeYN6usUt0L+JuiQw09g6nTUiXYZcNqtcEfzsSt2OBe7yGnre TEKxS/qfMLhOJlrLKFGWZDb/NH90y3Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1628064840; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=8keho363Sl2gUx4aN/xeXttCB1j0pnXy2aa4KQk3nRM=; b=JUgqddh4j6SPOHYkwbkbzhRr4EaqgolGBClh9M0980M5lk8xPI/nX1VgeTFp/zfNUHwd/1 w5L0R8WB1eXUpoBw== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id A2AAA13790; Wed, 4 Aug 2021 08:14:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id ZdW2JkhMCmGgVQAAGKfGzw (envelope-from ); Wed, 04 Aug 2021 08:14:00 +0000 From: "Ivan T. Ivanov" To: Woojung Huh Cc: UNGLinuxDriver@microchip.com, "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Ivan T. Ivanov" Subject: [PATCH] net: usb: lan78xx: don't modify phy_device state concurrently Date: Wed, 4 Aug 2021 11:13:39 +0300 Message-Id: <20210804081339.19909-1-iivanov@suse.de> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 b27229d34425..0c964d0bd2d6 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -1154,7 +1154,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 */ @@ -1162,9 +1162,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 */ @@ -1177,7 +1180,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); @@ -1464,9 +1467,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.32.0