diff mbox series

net: usb: dm9601: fix wrong return value in dm9601_mdio_read

Message ID 20240225-dm9601_ret_err-v1-1-02c1d959ea59@gmail.com (mailing list archive)
State Accepted
Commit c68b2c9eba38ec3f60f4894b189090febf4d8d22
Delegated to: Netdev Maintainers
Headers show
Series net: usb: dm9601: fix wrong return value in dm9601_mdio_read | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 940 this patch: 940
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 957 this patch: 957
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 957 this patch: 957
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-25--03-00 (tests: 1457)

Commit Message

Javier Carrasco Feb. 24, 2024, 11:20 p.m. UTC
The MII code does not check the return value of mdio_read (among
others), and therefore no error code should be sent. A previous fix to
the use of an uninitialized variable propagates negative error codes,
that might lead to wrong operations by the MII library.

An example of such issues is the use of mii_nway_restart by the dm9601
driver. The mii_nway_restart function does not check the value returned
by mdio_read, which in this case might be a negative number which could
contain the exact bit the function checks (BMCR_ANENABLE = 0x1000).

Return zero in case of error, as it is common practice in users of
mdio_read to avoid wrong uses of the return value.

Fixes: 8f8abb863fa5 ("net: usb: dm9601: fix uninitialized variable use in dm9601_mdio_read")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/net/usb/dm9601.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


---
base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d
change-id: 20240224-dm9601_ret_err-0a9c9d95cd10

Best regards,

Comments

Simon Horman Feb. 27, 2024, 4:09 p.m. UTC | #1
On Sun, Feb 25, 2024 at 12:20:06AM +0100, Javier Carrasco wrote:
> The MII code does not check the return value of mdio_read (among
> others), and therefore no error code should be sent. A previous fix to
> the use of an uninitialized variable propagates negative error codes,
> that might lead to wrong operations by the MII library.
> 
> An example of such issues is the use of mii_nway_restart by the dm9601
> driver. The mii_nway_restart function does not check the value returned
> by mdio_read, which in this case might be a negative number which could
> contain the exact bit the function checks (BMCR_ANENABLE = 0x1000).
> 
> Return zero in case of error, as it is common practice in users of
> mdio_read to avoid wrong uses of the return value.
> 
> Fixes: 8f8abb863fa5 ("net: usb: dm9601: fix uninitialized variable use in dm9601_mdio_read")
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

I guess it would be nice if error values could be used,
but as you have described, that does not seem to be the case here.

Reviewed-by: Simon Horman <horms@kernel.org>
Peter Korsgaard Feb. 27, 2024, 4:53 p.m. UTC | #2
>>>>> "Javier" == Javier Carrasco <javier.carrasco.cruz@gmail.com> writes:

 > The MII code does not check the return value of mdio_read (among
 > others), and therefore no error code should be sent. A previous fix to
 > the use of an uninitialized variable propagates negative error codes,
 > that might lead to wrong operations by the MII library.

 > An example of such issues is the use of mii_nway_restart by the dm9601
 > driver. The mii_nway_restart function does not check the value returned
 > by mdio_read, which in this case might be a negative number which could
 > contain the exact bit the function checks (BMCR_ANENABLE = 0x1000).

 > Return zero in case of error, as it is common practice in users of
 > mdio_read to avoid wrong uses of the return value.

 > Fixes: 8f8abb863fa5 ("net: usb: dm9601: fix uninitialized variable use in dm9601_mdio_read")
 > Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

Reviewed-by: Peter Korsgaard <peter@korsgaard.com>
Jakub Kicinski Feb. 28, 2024, 2:17 a.m. UTC | #3
On Sun, 25 Feb 2024 00:20:06 +0100 Javier Carrasco wrote:
> The MII code does not check the return value of mdio_read (among
> others), and therefore no error code should be sent. A previous fix to
> the use of an uninitialized variable propagates negative error codes,
> that might lead to wrong operations by the MII library.
> 
> An example of such issues is the use of mii_nway_restart by the dm9601
> driver. The mii_nway_restart function does not check the value returned
> by mdio_read, which in this case might be a negative number which could
> contain the exact bit the function checks (BMCR_ANENABLE = 0x1000).
> 
> Return zero in case of error, as it is common practice in users of
> mdio_read to avoid wrong uses of the return value.

A bit odd but appears to be true, so I'll apply, thank you!

Andrew, 
mii.h files seem to fall under PHYLIB in MAINTAINERS, but mii.c does
not. Is this intentional?
patchwork-bot+netdevbpf@kernel.org Feb. 28, 2024, 3:20 a.m. UTC | #4
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sun, 25 Feb 2024 00:20:06 +0100 you wrote:
> The MII code does not check the return value of mdio_read (among
> others), and therefore no error code should be sent. A previous fix to
> the use of an uninitialized variable propagates negative error codes,
> that might lead to wrong operations by the MII library.
> 
> An example of such issues is the use of mii_nway_restart by the dm9601
> driver. The mii_nway_restart function does not check the value returned
> by mdio_read, which in this case might be a negative number which could
> contain the exact bit the function checks (BMCR_ANENABLE = 0x1000).
> 
> [...]

Here is the summary with links:
  - net: usb: dm9601: fix wrong return value in dm9601_mdio_read
    https://git.kernel.org/netdev/net/c/c68b2c9eba38

You are awesome, thank you!
Andrew Lunn Feb. 28, 2024, 3:10 p.m. UTC | #5
> Andrew, 
> mii.h files seem to fall under PHYLIB in MAINTAINERS, but mii.c does
> not. Is this intentional?

Probably. There are big parts of linux/mii.h which phylib
uses. However drivers/net/mii.c is not part of phylib and is
unmaintained.

      Andrew
diff mbox series

Patch

diff --git a/drivers/net/usb/dm9601.c b/drivers/net/usb/dm9601.c
index 99ec1d4a972d..8b6d6a1b3c2e 100644
--- a/drivers/net/usb/dm9601.c
+++ b/drivers/net/usb/dm9601.c
@@ -232,7 +232,7 @@  static int dm9601_mdio_read(struct net_device *netdev, int phy_id, int loc)
 	err = dm_read_shared_word(dev, 1, loc, &res);
 	if (err < 0) {
 		netdev_err(dev->net, "MDIO read error: %d\n", err);
-		return err;
+		return 0;
 	}
 
 	netdev_dbg(dev->net,