ANDROID: usb: gadget: f_accessory: fix CTS test stuck

f_accessory: fix CTS test stuck since CTS 9.0.
 - Refine acc_read() process.

The data length that user (test program) wants to read is different
from they really requested. This will cause the test flow stuck on the
2nd or the 3rd transfers in accessory test.
(By connecting 2 phones with CtsVerifier.apk and
CtsVerifierUSBCompanion.apk installed.)

Bug: 174729307

Change-Id: I5367c8075ed37534e8bed94b60cc79135ae5aebc
Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
This commit is contained in:
Macpaul Lin
2020-12-18 17:43:10 +08:00
parent e4f4470962
commit db9f954eed

View File

@@ -643,6 +643,7 @@ static ssize_t acc_read(struct file *fp, char __user *buf,
struct acc_dev *dev = fp->private_data;
struct usb_request *req;
ssize_t r = count;
ssize_t data_length;
unsigned xfer;
int ret = 0;
@@ -664,6 +665,15 @@ static ssize_t acc_read(struct file *fp, char __user *buf,
goto done;
}
/*
* Calculate the data length by considering termination character.
* Then compansite the difference of rounding up to
* integer multiple of maxpacket size.
*/
data_length = count;
data_length += dev->ep_out->maxpacket - 1;
data_length -= data_length % dev->ep_out->maxpacket;
if (dev->rx_done) {
// last req cancelled. try to get it.
req = dev->rx_req[0];
@@ -673,7 +683,7 @@ static ssize_t acc_read(struct file *fp, char __user *buf,
requeue_req:
/* queue a request */
req = dev->rx_req[0];
req->length = count;
req->length = data_length;
dev->rx_done = 0;
ret = usb_ep_queue(dev->ep_out, req, GFP_KERNEL);
if (ret < 0) {