nusb/lib: make usbcmd() return value symmetic; returning size of data phase (if any) (thanks aiju)
usbcmd() with Rh2d used to return the command size (8+ndata) wile returning only ndata for Rd2h. this changes it to always return ndata for Rh2d. it mostly doesnt matter as Rh2d callers only check r < 0 for error, but this makes the interface symmetic.
This commit is contained in:
parent
25725eb0ad
commit
e0087b2a78
2 changed files with 6 additions and 7 deletions
|
@ -396,14 +396,13 @@ cmdreq(Dev *d, int type, int req, int value, int index, uchar *data, int count)
|
|||
}else{
|
||||
ndata = count;
|
||||
wp = emallocz(8+ndata, 0);
|
||||
memmove(wp+8, data, ndata);
|
||||
}
|
||||
wp[0] = type;
|
||||
wp[1] = req;
|
||||
PUT2(wp+2, value);
|
||||
PUT2(wp+4, index);
|
||||
PUT2(wp+6, count);
|
||||
if(data != nil)
|
||||
memmove(wp+8, data, ndata);
|
||||
if(usbdebug>2){
|
||||
hd = hexstr(wp, ndata+8);
|
||||
rs = reqstr(type, req);
|
||||
|
@ -421,7 +420,7 @@ cmdreq(Dev *d, int type, int req, int value, int index, uchar *data, int count)
|
|||
dprint(2, "%s: cmd: short write: %d\n", argv0, n);
|
||||
return -1;
|
||||
}
|
||||
return n;
|
||||
return ndata;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -455,7 +454,7 @@ usbcmd(Dev *d, int type, int req, int value, int index, uchar *data, int count)
|
|||
r = cmdreq(d, type, req, value, index, nil, count);
|
||||
else
|
||||
r = cmdreq(d, type, req, value, index, data, count);
|
||||
if(r > 0){
|
||||
if(r >= 0){
|
||||
if((type & Rd2h) == 0)
|
||||
break;
|
||||
r = cmdrep(d, data, count);
|
||||
|
@ -469,7 +468,7 @@ usbcmd(Dev *d, int type, int req, int value, int index, uchar *data, int count)
|
|||
rerrstr(err, sizeof(err));
|
||||
sleep(Ucdelay);
|
||||
}
|
||||
if(r > 0 && i >= 2)
|
||||
if(r >= 0 && i >= 2)
|
||||
/* let the user know the device is not in good shape */
|
||||
fprint(2, "%s: usbcmd: %s: required %d attempts (%s)\n",
|
||||
argv0, d->dir, i, err);
|
||||
|
|
Loading…
Reference in a new issue