Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: usb_storage: do not align length of request for CBW to maxp size

Mass-storage and file-storage gadgets align the length to maximum-packet-size
when preparing the request to receive CBW. This is unnecessary and prevents the
controller driver from knowing that a short-packet is expected.

It is incorrect to set short_not_ok when preparing the request to receive CBW.
CBW will be a short-packet so short_not_ok must not be set.

This makes bh->bulk_out_intended_length unnecessary so it is also removed.

Signed-off-by: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Mian Yousaf Kaukab and committed by
Greg Kroah-Hartman
806e8f8f 088c64f8

+10 -49
+4 -20
drivers/usb/gadget/f_mass_storage.c
··· 474 474 return common->state > FSG_STATE_IDLE; 475 475 } 476 476 477 - /* Make bulk-out requests be divisible by the maxpacket size */ 478 - static void set_bulk_out_req_length(struct fsg_common *common, 479 - struct fsg_buffhd *bh, unsigned int length) 480 - { 481 - unsigned int rem; 482 - 483 - bh->bulk_out_intended_length = length; 484 - rem = length % common->bulk_out_maxpacket; 485 - if (rem > 0) 486 - length += common->bulk_out_maxpacket - rem; 487 - bh->outreq->length = length; 488 - } 489 - 490 - 491 477 /*-------------------------------------------------------------------------*/ 492 478 493 479 static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep) ··· 572 586 struct fsg_buffhd *bh = req->context; 573 587 574 588 dump_msg(common, "bulk-out", req->buf, req->actual); 575 - if (req->status || req->actual != bh->bulk_out_intended_length) 589 + if (req->status || req->actual != req->length) 576 590 DBG(common, "%s --> %d, %u/%u\n", __func__, 577 - req->status, req->actual, bh->bulk_out_intended_length); 591 + req->status, req->actual, req->length); 578 592 if (req->status == -ECONNRESET) /* Request was cancelled */ 579 593 usb_ep_fifo_flush(ep); 580 594 ··· 961 975 * the bulk-out maxpacket size 962 976 */ 963 977 bh->outreq->length = amount; 964 - bh->bulk_out_intended_length = amount; 965 978 bh->outreq->short_not_ok = 1; 966 979 if (!start_out_transfer(common, bh)) 967 980 /* Dunno what to do if common->fsg is NULL */ ··· 1637 1652 * the bulk-out maxpacket size. 1638 1653 */ 1639 1654 bh->outreq->length = amount; 1640 - bh->bulk_out_intended_length = amount; 1641 1655 bh->outreq->short_not_ok = 1; 1642 1656 if (!start_out_transfer(common, bh)) 1643 1657 /* Dunno what to do if common->fsg is NULL */ ··· 2306 2322 } 2307 2323 2308 2324 /* Queue a request to read a Bulk-only CBW */ 2309 - set_bulk_out_req_length(common, bh, USB_BULK_CB_WRAP_LEN); 2310 - bh->outreq->short_not_ok = 1; 2325 + bh->outreq->length = USB_BULK_CB_WRAP_LEN; 2326 + bh->outreq->short_not_ok = 0; 2311 2327 if (!start_out_transfer(common, bh)) 2312 2328 /* Don't know what to do if common->fsg is NULL */ 2313 2329 return -EIO;
+6 -22
drivers/usb/gadget/file_storage.c
··· 497 497 return (fsg->state > FSG_STATE_IDLE); 498 498 } 499 499 500 - /* Make bulk-out requests be divisible by the maxpacket size */ 501 - static void set_bulk_out_req_length(struct fsg_dev *fsg, 502 - struct fsg_buffhd *bh, unsigned int length) 503 - { 504 - unsigned int rem; 505 - 506 - bh->bulk_out_intended_length = length; 507 - rem = length % fsg->bulk_out_maxpacket; 508 - if (rem > 0) 509 - length += fsg->bulk_out_maxpacket - rem; 510 - bh->outreq->length = length; 511 - } 512 - 513 500 static struct fsg_dev *the_fsg; 514 501 static struct usb_gadget_driver fsg_driver; 515 502 ··· 717 730 struct fsg_buffhd *bh = req->context; 718 731 719 732 dump_msg(fsg, "bulk-out", req->buf, req->actual); 720 - if (req->status || req->actual != bh->bulk_out_intended_length) 733 + if (req->status || req->actual != req->length) 721 734 DBG(fsg, "%s --> %d, %u/%u\n", __func__, 722 - req->status, req->actual, 723 - bh->bulk_out_intended_length); 735 + req->status, req->actual, req->length); 724 736 if (req->status == -ECONNRESET) // Request was cancelled 725 737 usb_ep_fifo_flush(ep); 726 738 ··· 1335 1349 1336 1350 /* amount is always divisible by 512, hence by 1337 1351 * the bulk-out maxpacket size */ 1338 - bh->outreq->length = bh->bulk_out_intended_length = 1339 - amount; 1352 + bh->outreq->length = amount; 1340 1353 bh->outreq->short_not_ok = 1; 1341 1354 start_transfer(fsg, fsg->bulk_out, bh->outreq, 1342 1355 &bh->outreq_busy, &bh->state); ··· 1995 2010 1996 2011 /* amount is always divisible by 512, hence by 1997 2012 * the bulk-out maxpacket size */ 1998 - bh->outreq->length = bh->bulk_out_intended_length = 1999 - amount; 2013 + bh->outreq->length = amount; 2000 2014 bh->outreq->short_not_ok = 1; 2001 2015 start_transfer(fsg, fsg->bulk_out, bh->outreq, 2002 2016 &bh->outreq_busy, &bh->state); ··· 2672 2688 } 2673 2689 2674 2690 /* Queue a request to read a Bulk-only CBW */ 2675 - set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN); 2676 - bh->outreq->short_not_ok = 1; 2691 + bh->outreq->length = USB_BULK_CB_WRAP_LEN; 2692 + bh->outreq->short_not_ok = 0; 2677 2693 start_transfer(fsg, fsg->bulk_out, bh->outreq, 2678 2694 &bh->outreq_busy, &bh->state); 2679 2695
-7
drivers/usb/gadget/storage_common.c
··· 286 286 enum fsg_buffer_state state; 287 287 struct fsg_buffhd *next; 288 288 289 - /* 290 - * The NetChip 2280 is faster, and handles some protocol faults 291 - * better, if we don't submit any short bulk-out read requests. 292 - * So we will record the intended request length here. 293 - */ 294 - unsigned int bulk_out_intended_length; 295 - 296 289 struct usb_request *inreq; 297 290 int inreq_busy; 298 291 struct usb_request *outreq;