提交 b0bac258 编写于 作者: R Robert Baldyga 提交者: Felipe Balbi

usb: gadget: introduce 'enabled' flag in struct usb_ep

This patch introduces 'enabled' flag in struct usb_ep, and modifies
usb_ep_enable() and usb_ep_disable() functions to encapsulate endpoint
enabled/disabled state. It helps to avoid enabling endpoints which are
already enabled, and disabling endpoints which are already disables.

From now USB functions don't have to remember current endpoint
enable/disable state, as this state is now handled automatically which
makes this API less bug-prone.
Signed-off-by: NRobert Baldyga <r.baldyga@samsung.com>
Signed-off-by: NFelipe Balbi <balbi@ti.com>
上级 b67f628c
......@@ -215,6 +215,7 @@ struct usb_ep {
struct list_head ep_list;
struct usb_ep_caps caps;
bool claimed;
bool enabled;
unsigned maxpacket:16;
unsigned maxpacket_limit:16;
unsigned max_streams:16;
......@@ -264,7 +265,18 @@ static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep,
*/
static inline int usb_ep_enable(struct usb_ep *ep)
{
return ep->ops->enable(ep, ep->desc);
int ret;
if (ep->enabled)
return 0;
ret = ep->ops->enable(ep, ep->desc);
if (ret)
return ret;
ep->enabled = true;
return 0;
}
/**
......@@ -281,7 +293,18 @@ static inline int usb_ep_enable(struct usb_ep *ep)
*/
static inline int usb_ep_disable(struct usb_ep *ep)
{
return ep->ops->disable(ep);
int ret;
if (!ep->enabled)
return 0;
ret = ep->ops->disable(ep);
if (ret)
return ret;
ep->enabled = false;
return 0;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册