Skip to contentSkip to conversation

ch9200: return error on failed register writes in ch9200_bind()

PATCH In review Sergey Shtylyov 1 participant 2 messages Sep 3 – Sep 8

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

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
index a206ffa76f1b..ce2e62f85c3d 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)
+		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
#1 lore raw
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'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.

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
index a206ffa76f1b..ce2e62f85c3d 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)

Should be (retval < 0) here an below, as Sashiko pointed out.

[...]

MBR, Sergey