[PATCH] USB: g_mass_storage: superfluous and missing packets fixed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The mass storage function responded needlessly to a set
configuration packet.  This was a leftover from converting
gadget (file storage gadget) into a composite function.

Moreover, it has failed to respond to get max LUN request.
Adding request queueing made the function work better.

Signed-off-by: Michal Nazarewicz <m.nazarewicz@xxxxxxxxxxx>
Signed-off-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
---
 drivers/usb/gadget/f_mass_storage.c |   15 ++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

>>>> +		/* Respond with data/status */
>>>> +		req->length = 1;
>>>> +		req->zero = 1 < w_length;

>>> Regardless, setting req->length to 1 is probably wrong if w_length is
>>> 0.  And setting req->zero at all is unnecessary.

> On Tue, 26 Jan 2010, Michal‚ Nazarewicz wrote:
>> That's the thing done in original fsg_setup() (in file storage gadget):
>>
>> 	if (rc >= 0 && rc != DELAYED_STATUS) {
>> 		rc = min(rc, w_length);
>> 		fsg->ep0req->length = rc;

On Tue, 26 Jan 2010 18:49:43 +0100, Alan Stern wrote:
> As I said, if w_length is 0 then req->length isn't set to 1.

I feel so stupid now... ;)

Still I wonder why composite does that though.


>> 		fsg->ep0req->zero = rc < w_length;

> This isn't necessary if you know that the length isn't a multiple of
> the maxpacket size.  In the original fsg_setup() that wasn't known, but
> here it is.  Setting req->zero isn't _wrong_; it's just unnecessary.

Anyhow, thank you fro all the comments.  I attach updated patch with
length set to min(1, w_length) and setting of zero removed.

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index a37640e..84f6491 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -614,7 +614,12 @@ static int fsg_setup(struct usb_function *f,
 			return -EDOM;
 		VDBG(fsg, "get max LUN\n");
 		*(u8 *) req->buf = fsg->common->nluns - 1;
-		return 1;
+
+		/* Respond with data/status */
+		req->length = min(1, w_length);
+		fsg->common->ep0req_name =
+			ctrl->bRequestType & USB_DIR_IN ? "ep0-in" : "ep0-out";
+		return ep0_queue(fsg->common);
 	}
 
 	VDBG(fsg,
@@ -2524,14 +2530,6 @@ static void handle_exception(struct fsg_common *common)
 
 	case FSG_STATE_CONFIG_CHANGE:
 		rc = do_set_config(common, new_config);
-		if (common->ep0_req_tag != exception_req_tag)
-			break;
-		if (rc != 0) {			/* STALL on errors */
-			DBG(common, "ep0 set halt\n");
-			usb_ep_set_halt(common->ep0);
-		} else {			/* Complete the status stage */
-			ep0_queue(common);
-		}
 		break;
 
 	case FSG_STATE_EXIT:
-- 
1.6.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux