[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-id: <55F83B37.20408@samsung.com>
Date: Tue, 15 Sep 2015 17:37:27 +0200
From: Krzysztof Opasiak <k.opasiak@...sung.com>
To: Robert Baldyga <r.baldyga@...sung.com>, balbi@...com
Cc: gregkh@...uxfoundation.org, linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org, b.zolnierkie@...sung.com,
m.szyprowski@...sung.com, andrzej.p@...sung.com
Subject: Re: [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct
usb_ep
Hello,
On 09/15/2015 04:26 PM, Robert Baldyga wrote:
> 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@...sung.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;
> }
>
Personally I don't like this convention. In my opinion usb_ep_disable()
& usb_ep_enable() should fail if ep is already disabled/enabled. Then in
function code we should check if endpoint is enabled (maybe even we
should have usb_ep_is_enabled()) and call disable only when it is really
enabled.
Best Regards,
--
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists