Skip to content

Commit cfa693b

Browse files
oleremkuba-moo
authored andcommitted
net: usb: lan78xx: Sanitize return values of register read/write functions
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: 8b1b2ca ("net: usb: lan78xx: Improve error handling in EEPROM and OTP operations") Reported-by: Mark Brown <[email protected]> Closes: https://lore.kernel.org/all/[email protected] Signed-off-by: Oleksij Rempel <[email protected]> Tested-by: Mark Brown <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d0a4a1b commit cfa693b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/usb/lan78xx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static int lan78xx_read_reg(struct lan78xx_net *dev, u32 index, u32 *data)
627627

628628
kfree(buf);
629629

630-
return ret;
630+
return ret < 0 ? ret : 0;
631631
}
632632

633633
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)
658658

659659
kfree(buf);
660660

661-
return ret;
661+
return ret < 0 ? ret : 0;
662662
}
663663

664664
static int lan78xx_update_reg(struct lan78xx_net *dev, u32 reg, u32 mask,

0 commit comments

Comments
 (0)