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

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 dd4dff8b035f ("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: dd4dff8b035f ("USB: composite: Fix bug: should test set_alt function pointer before use it")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>

authored by

Krzysztof Opasiak and committed by
Felipe Balbi
7e4da3fc 51c1685d

+8 -4
+8 -4
drivers/usb/gadget/composite.c
··· 1694 1694 value = min(w_length, (u16) 1); 1695 1695 break; 1696 1696 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 */ 1700 1698 case USB_REQ_SET_INTERFACE: 1701 1699 if (ctrl->bRequestType != USB_RECIP_INTERFACE) 1702 1700 goto unknown; ··· 1703 1705 f = cdev->config->interface[intf]; 1704 1706 if (!f) 1705 1707 break; 1706 - if (w_value && !f->set_alt) 1708 + 1709 + /* 1710 + * If there's no get_alt() method, we know only altsetting zero 1711 + * works. There is no need to check if set_alt() is not NULL 1712 + * as we check this in usb_add_function(). 1713 + */ 1714 + if (w_value && !f->get_alt) 1707 1715 break; 1708 1716 value = f->set_alt(f, w_index, w_value); 1709 1717 if (value == USB_GADGET_DELAYED_STATUS) {