History

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.

Krzysztof Opasiak committed 9 years ago

Commit 7e4da3f1 parent 51c16851 file · +8 −4Browse files

Unified · Split

drivers/usb/gadget/composite.c+8−4
@@ -1694,9 +1694,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) · 1693 unmodified lines
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) · 2 unmodified lines
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) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t