Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1225237

[PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct usb_ep

From Robert Baldyga <r.baldyga@samsung.com>
Newsgroups linux.kernel
Subject [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct usb_ep
Date 2015-09-15 16:50 +0200
Message-ID <q8ZIu-7Nu-1@gated-at.bofh.it> (permalink)
References <q8Zp8-7qt-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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: Robert Baldyga <r.baldyga@samsung.com>
---
 include/linux/usb/gadget.h | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 3f299e2..63375cd 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -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,15 @@ 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 = 0;
+
+	if (!ep->enabled) {
+		ret = ep->ops->enable(ep, ep->desc);
+		if (!ret)
+			ep->enabled = true;
+	}
+
+	return ret;
 }
 
 /**
@@ -281,7 +290,15 @@ 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 = 0;
+
+	if (ep->enabled) {
+		ret = ep->ops->disable(ep);
+		if (!ret)
+			ep->enabled = false;
+	}
+
+	return ret;
 }
 
 /**
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/26] usb: gadget: encapsulate ep enable/disable Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:30 +0200
  [PATCH 20/26] usb: gadget: f_uac1: eliminate abuse of ep->driver data Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:40 +0200
  [PATCH 21/26] usb: gadget: f_uac2: eliminate abuse of ep->driver data Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:40 +0200
  [PATCH 13/26] usb: gadget: f_obex: eliminate abuse of ep->driver data Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:40 +0200
  [PATCH 23/26] usb: gadget: u_ether: eliminate abuse of ep->driver data Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:40 +0200
  [PATCH 25/26] usb: gadget: legacy: dbgp: eliminate abuse of ep->driver  data Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:40 +0200
  [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct usb_ep Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:50 +0200
    Re: [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct  usb_ep Krzysztof Opasiak <k.opasiak@samsung.com> - 2015-09-15 17:40 +0200
      Re: [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct  usb_ep Felipe Balbi <balbi@ti.com> - 2015-09-15 17:50 +0200
        Re: [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct  usb_ep Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 18:00 +0200
          Re: [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct  usb_ep Felipe Balbi <balbi@ti.com> - 2015-09-15 18:10 +0200
        Re: [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct  usb_ep Krzysztof Opasiak <k.opasiak@samsung.com> - 2015-09-15 18:20 +0200
          Re: [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct  usb_ep Felipe Balbi <balbi@ti.com> - 2015-09-15 18:40 +0200
  [PATCH 02/26] usb: gadget: f_ncm: obtain cdev from function instead of  driver_data Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:50 +0200
  [PATCH 01/26] usb: gadget: fix few outdated comments Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:50 +0200
  [PATCH 07/26] usb: gadget: f_eem: eliminate abuse of ep->driver data Robert Baldyga <r.baldyga@samsung.com> - 2015-09-15 16:50 +0200

csiph-web