Skip to content

Commit 7e4da3f

Browse files
kopasiakFelipe Balbi
authored andcommitted
usb: gadget: composite: Test get_alt() presence instead of set_alt()
By convention (according to doc) if function does not provide get_alt() callback composite framework should assume that it has only altsetting 0 and should respond with error if host tries to set other one. After commit dd4dff8 ("USB: composite: Fix bug: should test set_alt function pointer before use it") we started checking set_alt() callback instead of get_alt(). This check is useless as we check if set_alt() is set inside usb_add_function() and fail if it's NULL. Let's fix this check and move comment about why we check the get method instead of set a little bit closer to prevent future false fixes. Fixes: dd4dff8 ("USB: composite: Fix bug: should test set_alt function pointer before use it") Cc: stable <[email protected]> Signed-off-by: Krzysztof Opasiak <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 51c1685 commit 7e4da3f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/usb/gadget/composite.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,9 +1694,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
16941694
value = min(w_length, (u16) 1);
16951695
break;
16961696

1697-
/* function drivers must handle get/set altsetting; if there's
1698-
* no get() method, we know only altsetting zero works.
1699-
*/
1697+
/* function drivers must handle get/set altsetting */
17001698
case USB_REQ_SET_INTERFACE:
17011699
if (ctrl->bRequestType != USB_RECIP_INTERFACE)
17021700
goto unknown;
@@ -1705,7 +1703,13 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
17051703
f = cdev->config->interface[intf];
17061704
if (!f)
17071705
break;
1708-
if (w_value && !f->set_alt)
1706+
1707+
/*
1708+
* If there's no get_alt() method, we know only altsetting zero
1709+
* works. There is no need to check if set_alt() is not NULL
1710+
* as we check this in usb_add_function().
1711+
*/
1712+
if (w_value && !f->get_alt)
17091713
break;
17101714
value = f->set_alt(f, w_index, w_value);
17111715
if (value == USB_GADGET_DELAYED_STATUS) {

0 commit comments

Comments
 (0)