* [PATCH net-next v3 1/2] ch9200: return error on failed register writes in ch9200_bind()
2026-09-23 20:14 [PATCH net-next v3 0/2] ch9200: stop ignoring the register write errors Sergey Shtylyov
@ 2026-09-23 20:14 ` Sergey Shtylyov
2026-09-23 20:14 ` [PATCH net-next v3 2/2] ch9200: do return USB errors from control_write() Sergey Shtylyov
1 sibling, 0 replies; 3+ messages in thread
From: Sergey Shtylyov @ 2026-09-23 20:14 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-usb, netdev
Cc: Sergey Shtylyov, linux-kernel
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.
Signed-off-by: Sergey Shtylyov <s.shtylyov@auroraos.dev>
---
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(+)
diff --git a/drivers/net/usb/ch9200.c b/drivers/net/usb/ch9200.c
index a206ffa76f1b..ab3cd3902ed7 100644
--- a/drivers/net/usb/ch9200.c
+++ b/drivers/net/usb/ch9200.c
@@ -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);
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net-next v3 2/2] ch9200: do return USB errors from control_write()
2026-09-23 20:14 [PATCH net-next v3 0/2] ch9200: stop ignoring the register write errors Sergey Shtylyov
2026-09-23 20:14 ` [PATCH net-next v3 1/2] ch9200: return error on failed register writes in ch9200_bind() Sergey Shtylyov
@ 2026-09-23 20:14 ` Sergey Shtylyov
1 sibling, 0 replies; 3+ messages in thread
From: Sergey Shtylyov @ 2026-09-23 20:14 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-usb, netdev
Cc: Sergey Shtylyov, linux-kernel
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...
Signed-off-by: Sergey Shtylyov <s.shtylyov@auroraos.dev>
---
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(-)
diff --git a/drivers/net/usb/ch9200.c b/drivers/net/usb/ch9200.c
index ab3cd3902ed7..5cd825f26420 100644
--- a/drivers/net/usb/ch9200.c
+++ b/drivers/net/usb/ch9200.c
@@ -168,8 +168,6 @@ static int control_write(struct usbnet *dev, unsigned char request,
err = -EINVAL;
kfree(buf);
- return 0;
-
err_out:
return err;
}
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread