Commit cc476b42 authored by Robert Baldyga's avatar Robert Baldyga Committed by Felipe Balbi

usb: gadget: encapsulate endpoint claiming mechanism

So far it was necessary for usb functions to set ep->driver_data in
endpoint obtained from autoconfig to non-null value, to indicate that
endpoint is claimed by function (in autoconfig it was checked if endpoint
has set this field to non-null value, and if it has, it was assumed that
it is claimed). It could cause bugs because if some function doesn't
set this field autoconfig could return the same endpoint more than one
time.

To help to avoid such bugs this patch adds claimed flag to struct usb_ep,
and  encapsulates endpoint claiming mechanism inside usb_ep_autoconfig_ss()
and usb_ep_autoconfig_reset(), so now usb functions don't need to perform
any additional actions to mark endpoint obtained from autoconfig as claimed.
Signed-off-by: default avatarRobert Baldyga <r.baldyga@samsung.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 0f4315a8
...@@ -53,7 +53,7 @@ ep_matches ( ...@@ -53,7 +53,7 @@ ep_matches (
int num_req_streams = 0; int num_req_streams = 0;
/* endpoint already claimed? */ /* endpoint already claimed? */
if (NULL != ep->driver_data) if (ep->claimed)
return 0; return 0;
/* only support ep0 for portable CONTROL traffic */ /* only support ep0 for portable CONTROL traffic */
...@@ -240,7 +240,7 @@ find_ep (struct usb_gadget *gadget, const char *name) ...@@ -240,7 +240,7 @@ find_ep (struct usb_gadget *gadget, const char *name)
* updated with the assigned number of streams if it is * updated with the assigned number of streams if it is
* different from the original value. To prevent the endpoint * different from the original value. To prevent the endpoint
* from being returned by a later autoconfig call, claim it by * from being returned by a later autoconfig call, claim it by
* assigning ep->driver_data to some non-null value. * assigning ep->claimed to true.
* *
* On failure, this returns a null endpoint descriptor. * On failure, this returns a null endpoint descriptor.
*/ */
...@@ -323,6 +323,7 @@ struct usb_ep *usb_ep_autoconfig_ss( ...@@ -323,6 +323,7 @@ struct usb_ep *usb_ep_autoconfig_ss(
found_ep: found_ep:
ep->desc = NULL; ep->desc = NULL;
ep->comp_desc = NULL; ep->comp_desc = NULL;
ep->claimed = true;
return ep; return ep;
} }
EXPORT_SYMBOL_GPL(usb_ep_autoconfig_ss); EXPORT_SYMBOL_GPL(usb_ep_autoconfig_ss);
...@@ -354,7 +355,7 @@ EXPORT_SYMBOL_GPL(usb_ep_autoconfig_ss); ...@@ -354,7 +355,7 @@ EXPORT_SYMBOL_GPL(usb_ep_autoconfig_ss);
* descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value
* is initialized as if the endpoint were used at full speed. To prevent * is initialized as if the endpoint were used at full speed. To prevent
* the endpoint from being returned by a later autoconfig call, claim it * the endpoint from being returned by a later autoconfig call, claim it
* by assigning ep->driver_data to some non-null value. * by assigning ep->claimed to true.
* *
* On failure, this returns a null endpoint descriptor. * On failure, this returns a null endpoint descriptor.
*/ */
...@@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(usb_ep_autoconfig); ...@@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(usb_ep_autoconfig);
* *
* Use this for devices where one configuration may need to assign * Use this for devices where one configuration may need to assign
* endpoint resources very differently from the next one. It clears * endpoint resources very differently from the next one. It clears
* state such as ep->driver_data and the record of assigned endpoints * state such as ep->claimed and the record of assigned endpoints
* used by usb_ep_autoconfig(). * used by usb_ep_autoconfig().
*/ */
void usb_ep_autoconfig_reset (struct usb_gadget *gadget) void usb_ep_autoconfig_reset (struct usb_gadget *gadget)
...@@ -381,7 +382,7 @@ void usb_ep_autoconfig_reset (struct usb_gadget *gadget) ...@@ -381,7 +382,7 @@ void usb_ep_autoconfig_reset (struct usb_gadget *gadget)
struct usb_ep *ep; struct usb_ep *ep;
list_for_each_entry (ep, &gadget->ep_list, ep_list) { list_for_each_entry (ep, &gadget->ep_list, ep_list) {
ep->driver_data = NULL; ep->claimed = false;
} }
gadget->in_epnum = 0; gadget->in_epnum = 0;
gadget->out_epnum = 0; gadget->out_epnum = 0;
......
...@@ -173,6 +173,7 @@ struct usb_ep { ...@@ -173,6 +173,7 @@ struct usb_ep {
const char *name; const char *name;
const struct usb_ep_ops *ops; const struct usb_ep_ops *ops;
struct list_head ep_list; struct list_head ep_list;
bool claimed;
unsigned maxpacket:16; unsigned maxpacket:16;
unsigned maxpacket_limit:16; unsigned maxpacket_limit:16;
unsigned max_streams:16; unsigned max_streams:16;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment