diff mbox series

[net-next] net: usb: sr9700: only store little-endian values in __le16 variable

Message ID 20241016-blackbird-le16-v1-1-97ba8de6b38f@kernel.org (mailing list archive)
State Accepted
Commit 4b726103796a9058ea77fd0905879ecc04951ef1
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: usb: sr9700: only store little-endian values in __le16 variable | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for 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: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: make24@iscas.ac.cn
netdev/build_clang success Errors and warnings before: 3 this patch: 3
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 28 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-10-17--00-00 (tests: 776)

Commit Message

Simon Horman Oct. 16, 2024, 2:31 p.m. UTC
In sr_mdio_read() the local variable res is used to store both
little-endian and host byte order values. This prevents Sparse
from helping us by flagging when endian miss matches occur - the
detection process hinges on the type of variables matching the
byte order of values stored in them.

Address this by adding a new local variable, word, to store little-endian
values; change the type of res to int, and use it to store host-byte
order values.

Flagged by Sparse as:

.../sr9700.c:205:21: warning: incorrect type in assignment (different base types)
.../sr9700.c:205:21:    expected restricted __le16 [addressable] [usertype] res
.../sr9700.c:205:21:    got int
.../sr9700.c:207:21: warning: incorrect type in assignment (different base types)
.../sr9700.c:207:21:    expected restricted __le16 [addressable] [usertype] res
.../sr9700.c:207:21:    got int
.../sr9700.c:212:16: warning: incorrect type in return expression (different base types)
.../sr9700.c:212:16:    expected int
.../sr9700.c:212:16:    got restricted __le16 [addressable] [usertype] res

Compile tested only.
No functional change intended.

Signed-off-by: Simon Horman <horms@kernel.org>
---
 drivers/net/usb/sr9700.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Oct. 18, 2024, 2:30 a.m. UTC | #1
Hello:

This patch was applied to netdev/net-next.git (main)
by Andrew Lunn <andrew@lunn.ch>:

On Wed, 16 Oct 2024 15:31:14 +0100 you wrote:
> In sr_mdio_read() the local variable res is used to store both
> little-endian and host byte order values. This prevents Sparse
> from helping us by flagging when endian miss matches occur - the
> detection process hinges on the type of variables matching the
> byte order of values stored in them.
> 
> Address this by adding a new local variable, word, to store little-endian
> values; change the type of res to int, and use it to store host-byte
> order values.
> 
> [...]

Here is the summary with links:
  - [net-next] net: usb: sr9700: only store little-endian values in __le16 variable
    https://git.kernel.org/netdev/net-next/c/4b726103796a

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/usb/sr9700.c b/drivers/net/usb/sr9700.c
index cb7d2f798fb4..091bc2aca7e8 100644
--- a/drivers/net/usb/sr9700.c
+++ b/drivers/net/usb/sr9700.c
@@ -177,9 +177,9 @@  static int sr9700_get_eeprom(struct net_device *netdev,
 static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
 {
 	struct usbnet *dev = netdev_priv(netdev);
-	__le16 res;
+	int err, res;
+	__le16 word;
 	int rc = 0;
-	int err;
 
 	if (phy_id) {
 		netdev_dbg(netdev, "Only internal phy supported\n");
@@ -197,14 +197,14 @@  static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
 		if (value & NSR_LINKST)
 			rc = 1;
 	}
-	err = sr_share_read_word(dev, 1, loc, &res);
+	err = sr_share_read_word(dev, 1, loc, &word);
 	if (err < 0)
 		return err;
 
 	if (rc == 1)
-		res = le16_to_cpu(res) | BMSR_LSTATUS;
+		res = le16_to_cpu(word) | BMSR_LSTATUS;
 	else
-		res = le16_to_cpu(res) & ~BMSR_LSTATUS;
+		res = le16_to_cpu(word) & ~BMSR_LSTATUS;
 
 	netdev_dbg(netdev, "sr_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
 		   phy_id, loc, res);