From 05f839d6ab857561bb78e82d57a36e0021bbb2e6 Mon Sep 17 00:00:00 2001 From: yangkai Date: Wed, 9 May 2012 20:01:04 +0800 Subject: [PATCH] fix some mtp bug --- drivers/usb/gadget/f_mtp.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/usb/gadget/f_mtp.c b/drivers/usb/gadget/f_mtp.c index 091687139c3b..4ac7c8394983 100755 --- a/drivers/usb/gadget/f_mtp.c +++ b/drivers/usb/gadget/f_mtp.c @@ -94,7 +94,6 @@ struct mtp_dev { wait_queue_head_t intr_wq; struct usb_request *rx_req[RX_REQ_MAX]; int rx_done; - int tx_done; /* for processing MTP_SEND_FILE, MTP_RECEIVE_FILE and * MTP_SEND_FILE_WITH_HEADER ioctls on a work queue @@ -350,7 +349,6 @@ static struct usb_request static void mtp_complete_in(struct usb_ep *ep, struct usb_request *req) { struct mtp_dev *dev = _mtp_dev; - dev->tx_done = 1; if ((req->status != 0) && (dev->state != STATE_CANCELED)) dev->state = STATE_ERROR; @@ -597,7 +595,6 @@ static ssize_t mtp_write(struct file *fp, const char __user *buf, r = -EFAULT; break; } - dev->tx_done = 0; req->length = xfer; ret = usb_ep_queue(dev->ep_in, req, GFP_KERNEL); @@ -606,14 +603,6 @@ static ssize_t mtp_write(struct file *fp, const char __user *buf, r = -EIO; break; } - ret = wait_event_interruptible(dev->write_wq, - dev->tx_done|| (dev->state != STATE_BUSY)); - if (dev->state == STATE_CANCELED) { - r = -ECANCELED; - if (!dev->rx_done) - usb_ep_dequeue(dev->ep_out, req); - goto done; - } buf += xfer; count -= xfer; @@ -631,7 +620,7 @@ static ssize_t mtp_write(struct file *fp, const char __user *buf, else if (dev->state != STATE_OFFLINE) dev->state = STATE_READY; spin_unlock_irq(&dev->lock); -done: + DBG(cdev, "mtp_write returning %d\n", r); return r; } @@ -753,7 +742,9 @@ static void receive_file_work(struct work_struct *data) filp = dev->xfer_file; offset = dev->xfer_file_offset; count = dev->xfer_file_length; - + /* yk@20120509 read zero length packet */ + if(( count&0x1ff) == 0) + count ++; DBG(cdev, "receive_file_work(%lld)\n", count); while (count > 0 || write_req) { @@ -804,8 +795,11 @@ static void receive_file_work(struct work_struct *data) if (read_req->actual < read_req->length) { /* short packet is used to signal EOF for sizes > 4 gig */ DBG(cdev, "got short packet\n"); - if (count == 0xFFFFFFFF) - count = 0; + count = 0; + /* yk@20120509 usb disconnect will couse short packet, + * and dev state change to STATE_OFFLINE */ + if(dev->state != STATE_BUSY) + r = -EIO; } write_req = read_req; -- 2.34.1