From nobody Wed Dec 17 19:38:04 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2E6238FA6 for ; Mon, 16 Dec 2024 12:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350996; cv=none; b=a35Dg4TilRgAYV1IDSLV1z+cO5ROKvDCjmeOPS6pOMebHq8PhI9eU9fppMudu/Pl10YGoj4pwcsnBSYygNtb8XwS43rRrie6hfcBbRk/oqh7a0vgoADQHsLBjIZQC2GghzoZFjPUw5KPgdyWjLqNpux/SWfK0xMQQlLcozfuKio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350996; c=relaxed/simple; bh=K8ZLnhui7MxNWTpLIfd7FUINitbEMDvMaUXPUagB+UY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qj44CMxSFHdgVLKpJ9C78LsNkHFk6H5aIj8hF6zvtGZfP71yd+63+dlYz8Y4j5Gt3kZFEUzp/Tyo3cO2aZ+VI4VPfd2LLjtsdCtUN2pQx+XVok0yYa4WXUTcxRs9lkoh+q/b23EfG4mWvKXb2I4YJW+vhHjcR4Gs32xm4tXkhBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tN9v1-0001C2-9H; Mon, 16 Dec 2024 13:09:47 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tN9uw-003h1h-27; Mon, 16 Dec 2024 13:09:43 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1tN9ux-0075tf-1B; Mon, 16 Dec 2024 13:09:43 +0100 From: Oleksij Rempel To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Woojung Huh , Andrew Lunn Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, Phil Elwell Subject: [PATCH net-next v1 1/6] net: usb: lan78xx: Add error handling to lan78xx_get_regs Date: Mon, 16 Dec 2024 13:09:36 +0100 Message-Id: <20241216120941.1690908-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241216120941.1690908-1-o.rempel@pengutronix.de> References: <20241216120941.1690908-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Update `lan78xx_get_regs` to handle errors during register and PHY reads. Log warnings for failed reads and exit the function early if an error occurs. Drop all previously logged registers to signal inconsistent readings to the user space. This ensures that invalid data is not returned to users. Signed-off-by: Oleksij Rempel --- drivers/net/usb/lan78xx.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 4661d131b190..270345fcad65 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -2108,20 +2108,44 @@ static void lan78xx_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf) { - u32 *data =3D buf; - int i, j; struct lan78xx_net *dev =3D netdev_priv(netdev); + unsigned int data_count =3D 0; + u32 *data =3D buf; + int i, j, ret; =20 /* Read Device/MAC registers */ - for (i =3D 0; i < ARRAY_SIZE(lan78xx_regs); i++) - lan78xx_read_reg(dev, lan78xx_regs[i], &data[i]); + for (i =3D 0; i < ARRAY_SIZE(lan78xx_regs); i++) { + ret =3D lan78xx_read_reg(dev, lan78xx_regs[i], &data[i]); + if (ret < 0) { + netdev_warn(dev->net, + "failed to read register 0x%08x\n", + lan78xx_regs[i]); + goto clean_data; + } + + data_count++; + } =20 if (!netdev->phydev) return; =20 /* Read PHY registers */ - for (j =3D 0; j < 32; i++, j++) - data[i] =3D phy_read(netdev->phydev, j); + for (j =3D 0; j < 32; i++, j++) { + ret =3D phy_read(netdev->phydev, j); + if (ret < 0) { + netdev_warn(dev->net, + "failed to read PHY register 0x%02x\n", j); + goto clean_data; + } + + data[i] =3D ret; + data_count++; + } + + return; + +clean_data: + memset(data, 0, data_count * sizeof(u32)); } =20 static const struct ethtool_ops lan78xx_ethtool_ops =3D { --=20 2.39.5 From nobody Wed Dec 17 19:38:04 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44AFD20468A for ; Mon, 16 Dec 2024 12:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350997; cv=none; b=UpHzGrpokrMUPnLUMoKBSivPVJvh7AfuyribbM5aZWSricVCyydk30ETfK7zlrV8IUsI5ao9OjZQhMwPwZhPetEhyHr1WeXnKqinVXK1mhkoRyEYk+FZXE7ZLCCV++6f/GzXJpofANSctmd04EpUGAnoJ72bOWb3BlIn2z9ohFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350997; c=relaxed/simple; bh=smjRVQ6loD7RNSPz3LagPvSvg5qkvEYEgfWW6vwiwRs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eBG7ondsDVgZ9NWA713QF62dy8xMnJjKEg2a4vAn5iyxkUjwFF0e7dzRrkwkqKgkg87JptSu5oDRrC2IxKgNaLqLYSI9QyjxOC0uFSp/6G4SDKSXLiQn0+b8Qc/eJFKqWomJqcEYYifjwytc5pk2ecvrbVbHRuPOJlVVKAdAszI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tN9v1-0001C3-9K; Mon, 16 Dec 2024 13:09:47 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tN9uw-003h1i-2C; Mon, 16 Dec 2024 13:09:43 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1tN9ux-0075tp-1E; Mon, 16 Dec 2024 13:09:43 +0100 From: Oleksij Rempel To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Woojung Huh , Andrew Lunn Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, Phil Elwell Subject: [PATCH net-next v1 2/6] net: usb: lan78xx: Use ETIMEDOUT instead of ETIME in lan78xx_stop_hw Date: Mon, 16 Dec 2024 13:09:37 +0100 Message-Id: <20241216120941.1690908-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241216120941.1690908-1-o.rempel@pengutronix.de> References: <20241216120941.1690908-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Update lan78xx_stop_hw to return -ETIMEDOUT instead of -ETIME when a timeout occurs. While -ETIME indicates a general timer expiration, -ETIMEDOUT is more commonly used for signaling operation timeouts and provides better consistency with standard error handling in the driver. The -ETIME checks in tx_complete() and rx_complete() are unrelated to this error handling change. In these functions, the error values are derived from urb->status, which reflects USB transfer errors. The error value from lan78xx_stop_hw will be exposed in the following cases: - usb_driver::suspend - net_device_ops::ndo_stop (potentially, though currently the return value is not used). Signed-off-by: Oleksij Rempel Reviewed-by: Mateusz Polchlopek --- drivers/net/usb/lan78xx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 270345fcad65..4674051f5c9c 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -844,9 +844,7 @@ static int lan78xx_stop_hw(struct lan78xx_net *dev, u32= reg, u32 hw_enabled, } while (!stopped && !time_after(jiffies, timeout)); } =20 - ret =3D stopped ? 0 : -ETIME; - - return ret; + return stopped ? 0 : -ETIMEDOUT; } =20 static int lan78xx_flush_fifo(struct lan78xx_net *dev, u32 reg, u32 fifo_f= lush) --=20 2.39.5 From nobody Wed Dec 17 19:38:04 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7FA9204681 for ; Mon, 16 Dec 2024 12:09:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350998; cv=none; b=KtF/9Xf+835lQRHlL7qzKF5La4AAt29+BWQNdKpNeFU6+45Ld+WW7lBl72QO4Ak1YPtqiY4wwPQk84nnTcFnJiC6f90ruR0C8nuwsN7YPTYiCcX/dCNdliR3l/L89wgjKutRKKtc++UfuAUttThzg5SNlOXTvigGJIa9a/wuKLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350998; c=relaxed/simple; bh=pfsl2TBxq6ncI2CnbTDx6yfSrPUgIlfFqf6zE4SHubU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YcXjugmDpDggIJbhFVVm6cFAnTz5StEqFoYqSH8+PLs6YSr/50zvgjsne4b0/qKu3K3qczFoP8ZVMxCwFtDKzF4V+BoINdaDSP6FoflspGYpS5SKv/CU7ypd1GGWLfbRRcbtX8NGpiVVl5Jt7D+Kx5iBHne2IMBUbk9rcmjRaCc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tN9v1-0001C4-9F; Mon, 16 Dec 2024 13:09:47 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tN9uw-003h1j-2G; Mon, 16 Dec 2024 13:09:43 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1tN9ux-0075u0-1H; Mon, 16 Dec 2024 13:09:43 +0100 From: Oleksij Rempel To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Woojung Huh , Andrew Lunn Cc: Oleksij Rempel , Andrew Lunn , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, Phil Elwell Subject: [PATCH net-next v1 3/6] net: usb: lan78xx: Use action-specific label in lan78xx_mac_reset Date: Mon, 16 Dec 2024 13:09:38 +0100 Message-Id: <20241216120941.1690908-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241216120941.1690908-1-o.rempel@pengutronix.de> References: <20241216120941.1690908-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rename the generic `done` label to the action-specific `exit_unlock` label in `lan78xx_mac_reset`. This improves clarity by indicating the specific cleanup action (mutex unlock) and aligns with best practices for error handling and cleanup labels. Signed-off-by: Oleksij Rempel Reviewed-by: Andrew Lunn Reviewed-by: Mateusz Polchlopek --- drivers/net/usb/lan78xx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 4674051f5c9c..30301af29ab2 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -1604,16 +1604,16 @@ static int lan78xx_mac_reset(struct lan78xx_net *de= v) */ ret =3D lan78xx_mdiobus_wait_not_busy(dev); if (ret < 0) - goto done; + goto exit_unlock; =20 ret =3D lan78xx_read_reg(dev, MAC_CR, &val); if (ret < 0) - goto done; + goto exit_unlock; =20 val |=3D MAC_CR_RST_; ret =3D lan78xx_write_reg(dev, MAC_CR, val); if (ret < 0) - goto done; + goto exit_unlock; =20 /* Wait for the reset to complete before allowing any further * MAC register accesses otherwise the MAC may lock up. @@ -1621,16 +1621,16 @@ static int lan78xx_mac_reset(struct lan78xx_net *de= v) do { ret =3D lan78xx_read_reg(dev, MAC_CR, &val); if (ret < 0) - goto done; + goto exit_unlock; =20 if (!(val & MAC_CR_RST_)) { ret =3D 0; - goto done; + goto exit_unlock; } } while (!time_after(jiffies, start_time + HZ)); =20 ret =3D -ETIMEDOUT; -done: +exit_unlock: mutex_unlock(&dev->phy_mutex); =20 return ret; --=20 2.39.5 From nobody Wed Dec 17 19:38:04 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 807E4204C03 for ; Mon, 16 Dec 2024 12:09:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350999; cv=none; b=oTeAIuPymoJYYUPm3KvjqohDA6Fafs5k2DRymEpfXcFEcZxIPPkUcI1VKepPM2cXCMDFCr0y0TVDvlNhhUcr0TgtmaxlcjjfE3Tc6Tqcgu7Dp2ynECmaR7mbix/0fpnUPMT5Ja/zHbHeSit92aa1/ur7zdOiuA2HOBjCCoVQ8fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350999; c=relaxed/simple; bh=M6/dmU5gV8hkCd8AiX90yM2U2eMQuPz7bbBpyE91QNM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z+F6ZCzOnOW2HvMZpfiCzreqEfN5DfGuCSc50I2/MIt+cFD81IGvSYlvQgEGENHwLMgMkgpX/jySxzinYqoV+syPlEShMIX+ypBGbsPDFGjfXFaLPg3JRY1etixbLXA/CmZJ4RnqS9PJVy82N5EtsMivtWRf5umo6tmA3wW7Q3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tN9v1-0001C5-9F; Mon, 16 Dec 2024 13:09:47 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tN9uw-003h1k-2O; Mon, 16 Dec 2024 13:09:43 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1tN9ux-0075uA-1K; Mon, 16 Dec 2024 13:09:43 +0100 From: Oleksij Rempel To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Woojung Huh , Andrew Lunn Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, Phil Elwell Subject: [PATCH net-next v1 4/6] net: usb: lan78xx: rename phy_mutex to mdiobus_mutex Date: Mon, 16 Dec 2024 13:09:39 +0100 Message-Id: <20241216120941.1690908-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241216120941.1690908-1-o.rempel@pengutronix.de> References: <20241216120941.1690908-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rename `phy_mutex` to `mdiobus_mutex` for clarity, as the mutex protects MDIO bus access rather than PHY-specific operations. Update all references to ensure consistency. Signed-off-by: Oleksij Rempel --- drivers/net/usb/lan78xx.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 30301af29ab2..78c75599b8f1 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -439,7 +439,7 @@ struct lan78xx_net { struct usb_anchor deferred; =20 struct mutex dev_mutex; /* serialise open/stop wrt suspend/resume */ - struct mutex phy_mutex; /* for phy access */ + struct mutex mdiobus_mutex; /* for MDIO bus access */ unsigned int pipe_in, pipe_out, pipe_intr; =20 unsigned int bulk_in_delay; @@ -952,7 +952,7 @@ static int lan78xx_flush_rx_fifo(struct lan78xx_net *de= v) return lan78xx_flush_fifo(dev, FCT_RX_CTL, FCT_RX_CTL_RST_); } =20 -/* Loop until the read is completed with timeout called with phy_mutex hel= d */ +/* Loop until the read is completed with timeout called with mdiobus_mutex= held */ static int lan78xx_mdiobus_wait_not_busy(struct lan78xx_net *dev) { unsigned long start_time =3D jiffies; @@ -1596,7 +1596,7 @@ static int lan78xx_mac_reset(struct lan78xx_net *dev) u32 val; int ret; =20 - mutex_lock(&dev->phy_mutex); + mutex_lock(&dev->mdiobus_mutex); =20 /* Resetting the device while there is activity on the MDIO * bus can result in the MAC interface locking up and not @@ -1631,7 +1631,7 @@ static int lan78xx_mac_reset(struct lan78xx_net *dev) =20 ret =3D -ETIMEDOUT; exit_unlock: - mutex_unlock(&dev->phy_mutex); + mutex_unlock(&dev->mdiobus_mutex); =20 return ret; } @@ -2249,7 +2249,7 @@ static int lan78xx_mdiobus_read(struct mii_bus *bus, = int phy_id, int idx) if (ret < 0) return ret; =20 - mutex_lock(&dev->phy_mutex); + mutex_lock(&dev->mdiobus_mutex); =20 /* confirm MII not busy */ ret =3D lan78xx_mdiobus_wait_not_busy(dev); @@ -2273,7 +2273,7 @@ static int lan78xx_mdiobus_read(struct mii_bus *bus, = int phy_id, int idx) ret =3D (int)(val & 0xFFFF); =20 done: - mutex_unlock(&dev->phy_mutex); + mutex_unlock(&dev->mdiobus_mutex); usb_autopm_put_interface(dev->intf); =20 return ret; @@ -2290,7 +2290,7 @@ static int lan78xx_mdiobus_write(struct mii_bus *bus,= int phy_id, int idx, if (ret < 0) return ret; =20 - mutex_lock(&dev->phy_mutex); + mutex_lock(&dev->mdiobus_mutex); =20 /* confirm MII not busy */ ret =3D lan78xx_mdiobus_wait_not_busy(dev); @@ -2313,7 +2313,7 @@ static int lan78xx_mdiobus_write(struct mii_bus *bus,= int phy_id, int idx, goto done; =20 done: - mutex_unlock(&dev->phy_mutex); + mutex_unlock(&dev->mdiobus_mutex); usb_autopm_put_interface(dev->intf); return ret; } @@ -4476,7 +4476,7 @@ static int lan78xx_probe(struct usb_interface *intf, skb_queue_head_init(&dev->rxq_done); skb_queue_head_init(&dev->txq_pend); skb_queue_head_init(&dev->rxq_overflow); - mutex_init(&dev->phy_mutex); + mutex_init(&dev->mdiobus_mutex); mutex_init(&dev->dev_mutex); =20 ret =3D lan78xx_urb_config_init(dev); --=20 2.39.5 From nobody Wed Dec 17 19:38:04 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5496620468C for ; Mon, 16 Dec 2024 12:09:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350998; cv=none; b=eyQoVETKf7a5ZXGVmvFkdO2ZzjFvaaoR5DFZrknQ1opgDdsaLWpiSNF4gPpHwvibK1T1wgqgnlsHSaeMXkL+03Ia1YBVN5LlHwERDGqMoD1QzC9xynI8DhDPULF+7n9ntExy7DgX819+b1vUn8Php6ELvCyZQ06AWYCzhbhhw+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350998; c=relaxed/simple; bh=RzI4qsAHPERBhbBj0HS3GCFXD9+RssdnOGbClkUytIc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iHWE9Rl1MIRlJ0a1aB5qmf1xDkHV9T1DUg6Zhsiwx85IscDeZRpXJ1YQ1FV3A+/xWUmEHMXrig9LpstlGzsyRR1PuIcof1o27GB2sU2DAkySxDVMk0X5+8QP6gD/EzPHc4ZLUqTYHq5W4oiniftFzcoY8Q9y4Ozi8xxcD1cSAAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tN9v1-0001C6-9G; Mon, 16 Dec 2024 13:09:47 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tN9uw-003h1l-2N; Mon, 16 Dec 2024 13:09:43 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1tN9ux-0075uK-1N; Mon, 16 Dec 2024 13:09:43 +0100 From: Oleksij Rempel To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Woojung Huh , Andrew Lunn Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, Phil Elwell Subject: [PATCH net-next v1 5/6] net: usb: lan78xx: remove PHY register access from ethtool get_regs Date: Mon, 16 Dec 2024 13:09:40 +0100 Message-Id: <20241216120941.1690908-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241216120941.1690908-1-o.rempel@pengutronix.de> References: <20241216120941.1690908-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove PHY register handling from `lan78xx_get_regs` and `lan78xx_get_regs_len`. Since the controller can have different PHYs attached, the first 32 registers are not universally relevant or the most interesting. Simplify the implementation to focus on MAC and device registers. Signed-off-by: Oleksij Rempel --- drivers/net/usb/lan78xx.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 78c75599b8f1..6c9dab290f3f 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -2096,10 +2096,7 @@ static int lan78xx_set_pause(struct net_device *net, =20 static int lan78xx_get_regs_len(struct net_device *netdev) { - if (!netdev->phydev) - return (sizeof(lan78xx_regs)); - else - return (sizeof(lan78xx_regs) + PHY_REG_SIZE); + return sizeof(lan78xx_regs); } =20 static void @@ -2109,7 +2106,7 @@ lan78xx_get_regs(struct net_device *netdev, struct et= htool_regs *regs, struct lan78xx_net *dev =3D netdev_priv(netdev); unsigned int data_count =3D 0; u32 *data =3D buf; - int i, j, ret; + int i, ret; =20 /* Read Device/MAC registers */ for (i =3D 0; i < ARRAY_SIZE(lan78xx_regs); i++) { @@ -2124,22 +2121,6 @@ lan78xx_get_regs(struct net_device *netdev, struct e= thtool_regs *regs, data_count++; } =20 - if (!netdev->phydev) - return; - - /* Read PHY registers */ - for (j =3D 0; j < 32; i++, j++) { - ret =3D phy_read(netdev->phydev, j); - if (ret < 0) { - netdev_warn(dev->net, - "failed to read PHY register 0x%02x\n", j); - goto clean_data; - } - - data[i] =3D ret; - data_count++; - } - return; =20 clean_data: --=20 2.39.5 From nobody Wed Dec 17 19:38:04 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82714204C06 for ; Mon, 16 Dec 2024 12:09:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350998; cv=none; b=GU+lZRKwFIrhc29J3p+h0oI6iFW96YRTwUKqWR9BaZ5zeLhhyhlm0TsEmI3nCr4UtHZVW5y4HUxlYIn3YUWZoR2X92At+wBDkb4WXVhMg0wVPADUoZIu4AVwCQqemLMkBUzIB8IXFQVQtedjpsWlSCcLm1rn27hwbwPxD0KCWhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734350998; c=relaxed/simple; bh=jc1WfBcyiJoiKMz9KgYkmV4nQ/C4HWUEcdFsqsMSRxg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NA1FpYY4wzTLLv0u2qiz//zVLDW8V0DkHAZ/ERAAQgKbT9hY92Tv+410CwPi1YbW9KYfeB/B6egAKm0ycOCSJnxmalbUSDRl09weGujdPGv0MRGua/P0SeA46ZRLmHfIBNxhe+8uwoOuuSRAC3wzgy1QYPZ2unB2+ElApdGcHyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tN9v1-0001C7-9E; Mon, 16 Dec 2024 13:09:47 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tN9uw-003h1m-2W; Mon, 16 Dec 2024 13:09:43 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1tN9ux-0075uU-1R; Mon, 16 Dec 2024 13:09:43 +0100 From: Oleksij Rempel To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Woojung Huh , Andrew Lunn Cc: Oleksij Rempel , Andrew Lunn , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, Phil Elwell Subject: [PATCH net-next v1 6/6] net: usb: lan78xx: Improve error handling in WoL operations Date: Mon, 16 Dec 2024 13:09:41 +0100 Message-Id: <20241216120941.1690908-7-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241216120941.1690908-1-o.rempel@pengutronix.de> References: <20241216120941.1690908-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Enhance error handling in Wake-on-LAN (WoL) operations: - Log a warning in `lan78xx_get_wol` if `lan78xx_read_reg` fails. - Check and handle errors from `device_set_wakeup_enable` and `phy_ethtool_set_wol` in `lan78xx_set_wol`. - Ensure proper cleanup with a unified error handling path. Signed-off-by: Oleksij Rempel Reviewed-by: Andrew Lunn --- drivers/net/usb/lan78xx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 6c9dab290f3f..a91bf9c7e31d 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -1857,6 +1857,7 @@ static void lan78xx_get_wol(struct net_device *netdev, =20 ret =3D lan78xx_read_reg(dev, USB_CFG0, &buf); if (unlikely(ret < 0)) { + netdev_warn(dev->net, "failed to get WoL %pe", ERR_PTR(ret)); wol->supported =3D 0; wol->wolopts =3D 0; } else { @@ -1888,10 +1889,13 @@ static int lan78xx_set_wol(struct net_device *netde= v, =20 pdata->wol =3D wol->wolopts; =20 - device_set_wakeup_enable(&dev->udev->dev, (bool)wol->wolopts); + ret =3D device_set_wakeup_enable(&dev->udev->dev, (bool)wol->wolopts); + if (ret < 0) + goto exit_pm_put; =20 - phy_ethtool_set_wol(netdev->phydev, wol); + ret =3D phy_ethtool_set_wol(netdev->phydev, wol); =20 +exit_pm_put: usb_autopm_put_interface(dev->intf); =20 return ret; --=20 2.39.5