* [PATCH net v1 1/1] net: usb: lan78xx: Sanitize return values of register read/write functions
@ 2025-03-07 10:12 Oleksij Rempel
2025-03-07 13:50 ` Woojung.Huh
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Oleksij Rempel @ 2025-03-07 10:12 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Woojung Huh, Andrew Lunn
Cc: Oleksij Rempel, Mark Brown, kernel, linux-kernel, netdev,
UNGLinuxDriver, Phil Elwell
usb_control_msg() returns the number of transferred bytes or a negative
error code. The current implementation propagates the transferred byte
count, which is unintended. This affects code paths that assume a
boolean success/failure check, such as the EEPROM detection logic.
Fix this by ensuring lan78xx_read_reg() and lan78xx_write_reg() return
only 0 on success and preserve negative error codes.
This approach is consistent with existing usage, as the transferred byte
count is not explicitly checked elsewhere.
Fixes: 8b1b2ca83b20 ("net: usb: lan78xx: Improve error handling in EEPROM and OTP operations")
Reported-by: Mark Brown <broonie@kernel.org>
Closes: https://lore.kernel.org/all/ac965de8-f320-430f-80f6-b16f4e1ba06d@sirena.org.uk
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/net/usb/lan78xx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index a91bf9c7e31d..137adf6d5b08 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -627,7 +627,7 @@ static int lan78xx_read_reg(struct lan78xx_net *dev, u32 index, u32 *data)
kfree(buf);
- return ret;
+ return ret < 0 ? ret : 0;
}
static int lan78xx_write_reg(struct lan78xx_net *dev, u32 index, u32 data)
@@ -658,7 +658,7 @@ static int lan78xx_write_reg(struct lan78xx_net *dev, u32 index, u32 data)
kfree(buf);
- return ret;
+ return ret < 0 ? ret : 0;
}
static int lan78xx_update_reg(struct lan78xx_net *dev, u32 reg, u32 mask,
--
2.39.5
^ permalink raw reply [flat|nested] 4+ messages in thread* RE: [PATCH net v1 1/1] net: usb: lan78xx: Sanitize return values of register read/write functions
2025-03-07 10:12 [PATCH net v1 1/1] net: usb: lan78xx: Sanitize return values of register read/write functions Oleksij Rempel
@ 2025-03-07 13:50 ` Woojung.Huh
2025-03-10 13:17 ` Mark Brown
2025-03-10 20:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Woojung.Huh @ 2025-03-07 13:50 UTC (permalink / raw)
To: o.rempel, davem, edumazet, kuba, pabeni, andrew+netdev,
Thangaraj.S, Rengarajan.S
Cc: broonie, kernel, linux-kernel, netdev, UNGLinuxDriver, phil
Add proper maintainers in the list
Thangaraj Samynathan <Thangaraj.S@microchip.com>
Rengarajan Sundararajan <Rengarajan.S@microchip.com>
https://web.git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/MAINTAINERS#n24528
> -----Original Message-----
> From: Oleksij Rempel <o.rempel@pengutronix.de>
> Sent: Friday, March 7, 2025 5:12 AM
> To: David S. Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Woojung Huh - C21699 <Woojung.Huh@microchip.com>;
> Andrew Lunn <andrew+netdev@lunn.ch>
> Cc: Oleksij Rempel <o.rempel@pengutronix.de>; Mark Brown
> <broonie@kernel.org>; kernel@pengutronix.de; linux-kernel@vger.kernel.org;
> netdev@vger.kernel.org; UNGLinuxDriver <UNGLinuxDriver@microchip.com>; Phil
> Elwell <phil@raspberrypi.org>
> Subject: [PATCH net v1 1/1] net: usb: lan78xx: Sanitize return values of
> register read/write functions
>
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
>
> usb_control_msg() returns the number of transferred bytes or a negative
> error code. The current implementation propagates the transferred byte
> count, which is unintended. This affects code paths that assume a
> boolean success/failure check, such as the EEPROM detection logic.
>
> Fix this by ensuring lan78xx_read_reg() and lan78xx_write_reg() return
> only 0 on success and preserve negative error codes.
>
> This approach is consistent with existing usage, as the transferred byte
> count is not explicitly checked elsewhere.
>
> Fixes: 8b1b2ca83b20 ("net: usb: lan78xx: Improve error handling in EEPROM
> and OTP operations")
> Reported-by: Mark Brown <broonie@kernel.org>
> Closes: https://lore.kernel.org/all/ac965de8-f320-430f-80f6-
> b16f4e1ba06d@sirena.org.uk
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> drivers/net/usb/lan78xx.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
> index a91bf9c7e31d..137adf6d5b08 100644
> --- a/drivers/net/usb/lan78xx.c
> +++ b/drivers/net/usb/lan78xx.c
> @@ -627,7 +627,7 @@ static int lan78xx_read_reg(struct lan78xx_net *dev, u32
> index, u32 *data)
>
> kfree(buf);
>
> - return ret;
> + return ret < 0 ? ret : 0;
> }
>
> static int lan78xx_write_reg(struct lan78xx_net *dev, u32 index, u32 data)
> @@ -658,7 +658,7 @@ static int lan78xx_write_reg(struct lan78xx_net *dev,
> u32 index, u32 data)
>
> kfree(buf);
>
> - return ret;
> + return ret < 0 ? ret : 0;
> }
>
> static int lan78xx_update_reg(struct lan78xx_net *dev, u32 reg, u32 mask,
> --
> 2.39.5
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net v1 1/1] net: usb: lan78xx: Sanitize return values of register read/write functions
2025-03-07 10:12 [PATCH net v1 1/1] net: usb: lan78xx: Sanitize return values of register read/write functions Oleksij Rempel
2025-03-07 13:50 ` Woojung.Huh
@ 2025-03-10 13:17 ` Mark Brown
2025-03-10 20:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2025-03-10 13:17 UTC (permalink / raw)
To: Oleksij Rempel
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Woojung Huh, Andrew Lunn, kernel, linux-kernel, netdev,
UNGLinuxDriver, Phil Elwell
[-- Attachment #1: Type: text/plain, Size: 616 bytes --]
On Fri, Mar 07, 2025 at 11:12:23AM +0100, Oleksij Rempel wrote:
> usb_control_msg() returns the number of transferred bytes or a negative
> error code. The current implementation propagates the transferred byte
> count, which is unintended. This affects code paths that assume a
> boolean success/failure check, such as the EEPROM detection logic.
>
> Fix this by ensuring lan78xx_read_reg() and lan78xx_write_reg() return
> only 0 on success and preserve negative error codes.
Tested-by: Mark Brown <broonie@kernel.org>
This fixes NFS boot on the Raspberry Pi 3+, it'd be good to get it into
v6.14.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v1 1/1] net: usb: lan78xx: Sanitize return values of register read/write functions
2025-03-07 10:12 [PATCH net v1 1/1] net: usb: lan78xx: Sanitize return values of register read/write functions Oleksij Rempel
2025-03-07 13:50 ` Woojung.Huh
2025-03-10 13:17 ` Mark Brown
@ 2025-03-10 20:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-03-10 20:40 UTC (permalink / raw)
To: Oleksij Rempel
Cc: davem, edumazet, kuba, pabeni, woojung.huh, andrew+netdev,
broonie, kernel, linux-kernel, netdev, UNGLinuxDriver, phil
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 7 Mar 2025 11:12:23 +0100 you wrote:
> usb_control_msg() returns the number of transferred bytes or a negative
> error code. The current implementation propagates the transferred byte
> count, which is unintended. This affects code paths that assume a
> boolean success/failure check, such as the EEPROM detection logic.
>
> Fix this by ensuring lan78xx_read_reg() and lan78xx_write_reg() return
> only 0 on success and preserve negative error codes.
>
> [...]
Here is the summary with links:
- [net,v1,1/1] net: usb: lan78xx: Sanitize return values of register read/write functions
https://git.kernel.org/netdev/net/c/cfa693bf9d53
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-10 20:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-07 10:12 [PATCH net v1 1/1] net: usb: lan78xx: Sanitize return values of register read/write functions Oleksij Rempel
2025-03-07 13:50 ` Woojung.Huh
2025-03-10 13:17 ` Mark Brown
2025-03-10 20:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®