ch9200: return error on failed register writes in ch9200_bind()
Subsystems (4)
PATCH 1/1 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.
--- drivers/net/usb/ch9200.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/net/usb/ch9200.c +12 -0
@@ -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) +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) +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) +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) +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) +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) +return retval; retval =get_mac_address (dev, addr);eth_hw_addr_set (dev->net, addr);
Signature · 1 line
2.55.0
Quoted 9 lines · Sergey Shtylyov
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'sbind()method ignores error codes returned fromcontrol_write(). Do bail out ofch9200_bind()on failed writes...Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.
Signed-off-by Sergey Shtylyov <[email protected]>
Scratch this patch, I was sloppy... :-)
[...]
drivers/net/usb/ch9200.c static int ch9200_bind(struct usbnet *dev, struct usb_interface *intf) · line 363
Quoted 9 lines
drivers/net/usb/ch9200.c +1
-0@@ -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)
Should be (retval < 0) here an below, as Sashiko pointed out.
[...]
MBR, Sergey