[PATCH v2] net: usb: net1080: add error handling to nc_vendor_write()

Ashwin Gundarapu <[email protected]>
Newsgroups org.kernel.vger.linux-usb,org.kernel.vger.linux-kernel,org.kernel.vger.netdev
Message-ID <[email protected]>
From 8c6ffd0b1a5ac33fb6a81cfd4d7d2c54462233bc Mon Sep 17 00:00:00 2001
From: Ashwin Gundarapu <[email protected]>
Date: Mon, 27 Jul 2026 19:34:16 +0530
Subject: [PATCH] net: usb: net1080: add error handling to nc_vendor_write()

The nc_vendor_write() function currently ignores the return value of
usbnet_write_cmd(). This can lead to silent failures when USB
communication fails.

Change nc_vendor_write() and nc_register_write() to return int
instead of void, and propagate the error from usbnet_write_cmd()
back to the caller.

Also fix the callers in net1080_reset() to check the return value
and handle errors appropriately. Remove an unused #if 0 block while
at it.

Signed-off-by: Ashwin Gundarapu <[email protected]>
---
 drivers/net/usb/net1080.c | 55 +++++++++++++--------------------------
 1 file changed, 18 insertions(+), 37 deletions(-)

diff --git a/drivers/net/usb/net1080.c b/drivers/net/usb/net1080.c
index 19f6e1222d93..87848f6e8e01 100644
--- a/drivers/net/usb/net1080.c
+++ b/drivers/net/usb/net1080.c
@@ -113,49 +113,22 @@ nc_register_read(struct usbnet *dev, u8 regnum, u16 *retval_ptr)
 	return nc_vendor_read(dev, REQUEST_REGISTER, regnum, retval_ptr);
 }
 
-static void
+static int
 nc_vendor_write(struct usbnet *dev, u8 req, u8 regnum, u16 value)
 {
-	usbnet_write_cmd(dev, req,
-			 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
-			 value, regnum, NULL, 0);
+	return usbnet_write_cmd(dev, req,
+				USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+				value, regnum, NULL, 0);
 }
 
-static inline void
+static inline int
 nc_register_write(struct usbnet *dev, u8 regnum, u16 value)
 {
-	nc_vendor_write(dev, REQUEST_REGISTER, regnum, value);
+	return nc_vendor_write(dev, REQUEST_REGISTER, regnum, value);
 }
 
 
-#if 0
-static void nc_dump_registers(struct usbnet *dev)
-{
-	u8	reg;
-	u16	*vp = kmalloc(sizeof (u16));
-
-	if (!vp)
-		return;
 
-	netdev_dbg(dev->net, "registers:\n");
-	for (reg = 0; reg < 0x20; reg++) {
-		int retval;
-
-		// reading some registers is trouble
-		if (reg >= 0x08 && reg <= 0xf)
-			continue;
-		if (reg >= 0x12 && reg <= 0x1e)
-			continue;
-
-		retval = nc_register_read(dev, reg, vp);
-		if (retval < 0)
-			netdev_dbg(dev->net, "reg [0x%x] ==> error %d\n",
-				   reg, retval);
-		else
-			netdev_dbg(dev->net, "reg [0x%x] = 0x%x\n", reg, *vp);
-	}
-	kfree(vp);
-}
 #endif
 
 
@@ -279,8 +252,12 @@ static int net1080_reset(struct usbnet *dev)
 	usbctl = vp;
 	nc_dump_usbctl(dev, usbctl);
 
-	nc_register_write(dev, REG_USBCTL,
-			USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
+	retval = nc_register_write(dev, REG_USBCTL,
+				   USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
+	if (retval < 0) {
+		netdev_dbg(dev->net, "can't write USBCTL: %d\n", retval);
+		goto done;
+	}
 
 	if ((retval = nc_register_read(dev, REG_TTL, &vp)) < 0) {
 		netdev_dbg(dev->net, "can't read TTL, %d\n", retval);
@@ -288,8 +265,12 @@ static int net1080_reset(struct usbnet *dev)
 	}
 	ttl = vp;
 
-	nc_register_write(dev, REG_TTL,
-			MK_TTL(NC_READ_TTL_MS, TTL_OTHER(ttl)) );
+	retval = nc_register_write(dev, REG_TTL,
+				   MK_TTL(NC_READ_TTL_MS, TTL_OTHER(ttl)));
+	if (retval < 0) {
+		netdev_dbg(dev->net, "can't write TTL: %d\n", retval);
+		goto done;
+	}
 	netdev_dbg(dev->net, "assigned TTL, %d ms\n", NC_READ_TTL_MS);
 
 	netif_info(dev, link, dev->net, "port %c, peer %sconnected\n",
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.