shithub: riscv

Download patch

ref: 9cb67a523ff08a41ff0025d117cbdd598c00e36a
parent: 330916bfa517734e93cf8799ecf3fe7dd1b53e69
author: aiju <devnull@localhost>
date: Fri Mar 31 16:20:25 EDT 2017

nusb/serial: pl2303: better error handling

--- a/sys/src/cmd/nusb/serial/prolific.c
+++ b/sys/src/cmd/nusb/serial/prolific.c
@@ -266,7 +266,7 @@
 		val, index, buf);
 	res = usbcmd(ser->dev,  Rd2h | Rvendor | Rdev, VendorReadReq,
 		val, index, buf, 1);
-	dsprint(2, "serial: vendorread res:%d\n", res);
+	if(res != 1) fprint(2, "serial: vendorread failed with res=%d\n", res);
 	return res;
 }
 
@@ -281,7 +281,7 @@
 	dsprint(2, "serial: vendorwrite val: 0x%x idx:%d\n", val, index);
 	res = usbcmd(ser->dev, Rh2d | Rvendor | Rdev, VendorWriteReq,
 		val, index, nil, 0);
-	dsprint(2, "serial: vendorwrite res:%d\n", res);
+	if(res != 8) fprint(2, "serial: vendorwrite failed with res=%d\n", res);
 	return res;
 }
 
@@ -319,6 +319,8 @@
 
 	res = usbcmd(ser->dev, Rd2h | Rclass | Riface, GetLineReq,
 		0, 0, buf, sizeof buf);
+	if(res != ParamReqSz)
+		memset(buf, 0, sizeof(buf));
 	p->baud = GET4(buf);
 
 	/*
@@ -340,8 +342,12 @@
 	dsprint(2, "serial: getparam: ");
 	if(serialdebug)
 		dumpbuf(buf, sizeof buf);
-	dsprint(2, "serial: getparam res: %d\n", res);
-	return res;
+
+	if(res == ParamReqSz)
+		return 0;
+	fprint(2, "serial: plgetparam failed with res=%d\n", res);
+	if(res >= 0) werrstr("plgetparam failed with res=%d", res);
+	return -1;
 }
 
 static int
@@ -367,11 +373,16 @@
 		dumpbuf(buf, sizeof buf);
 	res = usbcmd(ser->dev, Rh2d | Rclass | Riface, SetLineReq,
 		0, 0, buf, sizeof buf);
+	if(res != 8+ParamReqSz){
+		fprint(2, "serial: plsetparam failed with res=%d\n", res);
+		if(res >= 0) werrstr("plsetparam failed with res=%d", res);
+		return -1;
+	}
 	plmodemctl(p, p->mctl);
-	plgetparam(p);		/* make sure our state corresponds */
+	if(plgetparam(p) < 0)		/* make sure our state corresponds */
+		return -1;
 
-	dsprint(2, "serial: setparam res: %d\n", res);
-	return res;
+	return 0;
 }
 
 static int