ch9200: do return USB errors from control_write()
Subsystems (4)
PATCH v2 1/1 ch9200: do return USB errors from control_write()
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
@@ -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
Quoted 7 lines · Sergey Shtylyov
Compared with
control_read(),control_write()looks really strange:
it ignores any errors returned byusb_control_msg(), always returning 0 instead, despite overriding a positive result ofusb_control_msg()(indicating short transfer) to-EINVALbefore doing that. Drop that dubious *return* and propagate USB errors to the callers...Signed-off-by Sergey Shtylyov <[email protected]>
Andrew
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 1 · Medium: 0 · Low: 0
- [High] Incomplete fix: after removing return 0; from control_write() (drivers/net/usb/ch9200.c:137-171), the helper now returns the…
--
ch9200: do return USB errors from control_write()
This removes the unconditional "return 0;" at the end of control_write() in drivers/net/usb/ch9200.c so that the function falls through to "return err;" instead. The stated intent is to propagate usb_control_msg() errors to the callers.
drivers/net/usb/ch9200.c static int control_write(struct usbnet *dev, unsigned char request, · line 173
Quoted 13 lines
drivers/net/usb/ch9200.c +0
-2@@ -168,8 +168,6 @@ static int control_write(struct usbnet *dev, unsigned char request, err = -EINVAL ;kfree (buf); -return 0 ; - err_out:return err; }
[Severity: High]
The commit message says this will "propagate USB errors to the callers", but do any of the callers actually consume the value?
There are two in-tree callers. ch9200_mdio_write() is void and calls it as a bare statement:
drivers/net/usb/ch9200.c:ch9200_mdio_write() {
...
control_write(dev, REQUEST_WRITE, 0, loc * 2, buff, 0x02,
CONTROL_TIMEOUT_MS);
}ch9200_bind() stores the result six times and overwrites it every time, with the last store clobbered by get_mac_address():
drivers/net/usb/ch9200.c:ch9200_bind() {
...
retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_THRESHOLD, data,
0x02, CONTROL_TIMEOUT_MS);
...
retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_CTRL, data, 0x02,
CONTROL_TIMEOUT_MS);
retval = get_mac_address(dev, addr);
eth_hw_addr_set(dev->net, addr);
return retval;
}Since usbnet_probe() only aborts on a negative bind() status:
drivers/net/usb/usbnet.c:usbnet_probe() {
...
status = info->bind(dev, udev);
if (status < 0)
goto out1;
}bind still reports success when every register write failed, for example when a failed MAC_REG_THRESHOLD/MAC_REG_FIFO_DEPTH write is followed by a successful MAC_REG_CTRL = 0x0D5F write that arms DMA/receiver/transmitter with unprogrammed FIFO and flow-control watermarks, or when the MAC_REG_CTRL write itself fails and the netdev is registered with the datapath never enabled. Is the observable behaviour of the driver changed at all by this patch?
There is a second point about the resulting contract. On success usb_control_msg() returns the transferred length, so control_write() now returns a positive value (2 for these register writes) rather than 0:
err = usb_control_msg(dev->udev, ...); if (err >= 0 && err < size) err = -EINVAL;
Would the obvious caller-side follow-up "if (retval) return retval;" then treat every successful 2-byte register write as a failure? Would it be better to normalize success to 0 in control_write(), or to check "retval < 0" in each caller and update the callers in the same patch so the errors being returned are actually acted upon?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260915185805.38712-1-s.shtylyov%40auroraos.dev
Quoted 25 lines · On 9/16/26 10:23 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 1 · Medium: 0 · Low: 0
- [High] Incomplete fix: after removing
return 0;fromcontrol_write()(drivers/net/usb/ch9200.c:137-171), the helper now returns the…--
ch9200: do return USB errors from
control_write()This removes the unconditional "return 0;" at the end of
control_write()indrivers/net/usb/ch9200.cso that the function falls through to "return err;" instead. The stated intent is to propagateusb_control_msg()errors to the callers.Quoted 8 lines
drivers/net/usb/ch9200.c +0
-0@@ -168,8 +168,6 @@ static int control_write(struct usbnet *dev, unsigned char request, err = -EINVAL ;kfree (buf);
Quoted 7 lines
drivers/net/usb/ch9200.c static int control_write(struct usbnet *dev, unsigned char request, · line 173
Quoted 5 lines
drivers/net/usb/ch9200.c +0
-2-return 0 ; - err_out:return err; }[Severity: High]
But why? 8-)
Quoted 2 lines
The commit message says this will "propagate USB errors to the callers", but do any of the callers actually consume the value?
Most will -- after another patch:
https://lore.kernel.org/all/[email protected]/
[...]
Quoted 8 lines
There is a second point about the resulting contract. On success
usb_control_msg()returns the transferred length, socontrol_write()now returns a positive value (2 for these register writes) rather than 0:err = usb_control_msg(dev->udev, ...); if (err >= 0 && err < size) err = -EINVAL;
Quoted 5 lines
Would the obvious caller-side follow-up "if (retval) return retval;" then treat every successful 2-byte register write as a failure? Would it be better to normalize success to 0 in
control_write(), or to check "retval < 0" in each caller and update the callers in the same patch so the errors being returned are actually acted upon?
That's what the patch I linked to does...
[...]
MBR, Sergey
Jakub Kicinski
maintainerQuoted 8 lines · On Wed, 16 Sep 2026 19:21:04 +0300 Sergey Shtylyov wrote:
Quoted 8 lines
There is a second point about the resulting contract. On success
usb_control_msg()returns the transferred length, socontrol_write()now returns a positive value (2 for these register writes) rather than 0:err = usb_control_msg(dev->udev, ...); if (err >= 0 && err < size) err = -EINVAL;
Quoted 6 lines
Quoted 5 lines
Would the obvious caller-side follow-up "if (retval) return retval;" then treat every successful 2-byte register write as a failure? Would it be better to normalize success to 0 in
control_write(), or to check "retval < 0" in each caller and update the callers in the same patch so the errors being returned are actually acted upon?That's what the patch I linked to does...
Please fix the issues in one series or not at all.
We have too many patches in flight these days to be chasing people's linked series. Too many LLM-happy "helpers".
Please explain how you discovered the issue and how you tested the fix.
On 9/19/26 4:21 AM, Jakub Kicinski wrote:
[...]
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
There is a second point about the resulting contract. On success
usb_control_msg()returns the transferred length, socontrol_write()now returns a positive value (2 for these register writes) rather than 0:err = usb_control_msg(dev->udev, ...); if (err >= 0 && err < size) err = -EINVAL;
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Would the obvious caller-side follow-up "if (retval) return retval;" then treat every successful 2-byte register write as a failure? Would it be better to normalize success to 0 in
control_write(), or to check "retval < 0" in each caller and update the callers in the same patch so the errors being returned are actually acted upon?That's what the patch I linked to does...
Please fix the issues in one series or not at all.
OK. Series against net-next, right?
Quoted 2 lines
We have too many patches in flight these days to be chasing people's linked series. Too many LLM-happy "helpers".
IMHO these 2 patches are not so heavily linked, that's why I posted
them separately... And no AI was involved, of course. :-)
Quoted 1 line
Please explain how you discovered the issue and how you tested the fix.
As I noted in the description of the patch [1], the issue was reported
by the static analyzer. For the patch [2], I saw a problem with my own eyes.
I don't have the hardware, so no testing; there was some hope that e.g.
Matthew Garret (the driver's original submitter) could be able to test but his email bounced...
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
MBR, Sergey
On 9/21/26 10:59 PM, Sergey Shtylyov wrote:
[...]
Quoted 7 lines
Quoted 1 line
Please explain how you discovered the issue and how you tested the fix.
As I noted in the description of the patch [1], the issue was reported
by the static analyzer. For the patch [2], I saw a problem with my own eyes.
I don't have the hardware, so no testing; there was some hope that e.g.
Matthew Garret (the driver's original submitter) could be able to test but his email bounced...
Sorry, it's Garrett. From searching on lore it appears he still uses that
same email, so not sure why it bounced...
[...]
MBR, Sergey
Jakub Kicinski
maintainerQuoted 5 lines · On Mon, 21 Sep 2026 22:59:10 +0300 Sergey Shtylyov wrote:
Quoted 3 lines
Quoted 1 line
That's what the patch I linked to does...
Please fix the issues in one series or not at all.
OK. Series against net-next, right?
yes