Skip to contentSkip to conversation

ch9200: stop ignoring the register write errors

PATCH Applied Sergey Shtylyov 2 participants 4 messages Sep 23 – Sep 26

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover ch9200: stop ignoring the register write errors

The successful register writes, done via the USB control requests, seem vital for the normal functioning of the device, however the driver tends to completely ignore the register write errors, even though it could well propagate the errors from its bind() method. Additionally, it masks any USB errors returned by usb_control_msg(), pretending that the call was successful. Let's stop doing all that and see how it goes... :-)

Sergey Shtylyov (2):
ch9200: return error on failed register writes in ch9200_bind()
ch9200: do return USB errors from control_write()

 drivers/net/usb/ch9200.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v3 1/2 ch9200: return error on failed register writes in ch9200_bind()

The successful register writes, done via the USB control requests in control_write(), seem vital for the normal functioning of the device, however the driver's bind() method ignores error codes returned from control_write(). Do bail out of ch9200_bind() on failed writes...

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
Changes in version 3:
- dropped the Fixes tag, retargeting the patch to the net-next.git repo again.

Changes in version 2:
- switched to checking for the negative error values instead of non-zero;
- added the Fixes tag, retargeting the patch to the net.git repo;
- dropped [RFT] from the subject.

 drivers/net/usb/ch9200.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/usb/ch9200.c +12 -0
index a206ffa76f1b..ab3cd3902ed7 100644
@@ -360,32 +360,44 @@ static int ch9200_bind(struct usbnet *dev, struct usb_interface *intf)
 	data[1] = 0x0F;
 	retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_THRESHOLD, data,
 			       0x02, CONTROL_TIMEOUT_MS);
+	if (retval < 0)
+		return retval;
 
 	data[0] = 0xA0;
 	data[1] = 0x90;
 	retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_FIFO_DEPTH, data,
 			       0x02, CONTROL_TIMEOUT_MS);
+	if (retval < 0)
+		return retval;
 
 	data[0] = 0x30;
 	data[1] = 0x00;
 	retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_PAUSE, data,
 			       0x02, CONTROL_TIMEOUT_MS);
+	if (retval < 0)
+		return retval;
 
 	data[0] = 0x17;
 	data[1] = 0xD8;
 	retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_FLOW_CONTROL,
 			       data, 0x02, CONTROL_TIMEOUT_MS);
+	if (retval < 0)
+		return retval;
 
 	/* Undocumented register */
 	data[0] = 0x01;
 	data[1] = 0x00;
 	retval = control_write(dev, REQUEST_WRITE, 0, 254, data, 0x02,
 			       CONTROL_TIMEOUT_MS);
+	if (retval < 0)
+		return retval;
 
 	data[0] = 0x5F;
 	data[1] = 0x0D;
 	retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_CTRL, data, 0x02,
 			       CONTROL_TIMEOUT_MS);
+	if (retval < 0)
+		return retval;
 
 	retval = get_mac_address(dev, addr);
 	eth_hw_addr_set(dev->net, addr);
Signature · 1 line
2.55.0
#2 lore raw

PATCH v3 2/2 ch9200: do return USB errors from control_write()

In reply to Sergey Shtylyov

Compared with control_read(), control_write() looks really strange:
it ignores any errors returned by usb_control_msg(), always returning 0 instead, despite overriding a positive result of usb_control_msg() (indicating short transfer) to -EINVAL before doing that. Drop that dubious *return* and propagate USB errors to the callers...

---
Changes in version 2:
- dropped the Fixes tag, retargeting the patch to the net-next.git repo;
- dropped [RFT] from the subject.

 drivers/net/usb/ch9200.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/usb/ch9200.c +0 -2
index ab3cd3902ed7..5cd825f26420 100644
@@ -168,8 +168,6 @@ static int control_write(struct usbnet *dev, unsigned char request,
 		err = -EINVAL;
 	kfree(buf);
 
-	return 0;
-
 err_out:
 	return err;
 }
Signature · 1 line
2.55.0
#3 lore raw
In reply to Sergey Shtylyov
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 23 Sep 2026 23:14:37 +0300 you wrote:

The successful register writes, done via the USB control requests, seem vital for the normal functioning of the device, however the driver tends to completely ignore the register write errors, even though it could well propagate the errors from its bind() method. Additionally, it masks any USB errors returned by usb_control_msg(), pretending that the call was successful. Let's stop doing all that and see how it goes... :-)

[...]

Here is the summary with links:
- [net-next,v3,1/2] ch9200: return error on failed register writes in ch9200_bind()

    https://git.kernel.org/netdev/net-next/c/52c895f638fe
  - [net-next,v3,2/2] ch9200: do return USB errors from control_write()
    https://git.kernel.org/netdev/net-next/c/7bfc50171800

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html