From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754005AbbIOPnc (ORCPT ); Tue, 15 Sep 2015 11:43:32 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:56480 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751810AbbIOPn3 (ORCPT ); Tue, 15 Sep 2015 11:43:29 -0400 Date: Tue, 15 Sep 2015 10:43:24 -0500 From: Felipe Balbi To: Krzysztof Opasiak CC: Robert Baldyga , , , , , , , Subject: Re: [PATCH 04/26] usb: gadget: introduce 'enabled' flag in struct usb_ep Message-ID: <20150915154324.GI19948@saruman.tx.rr.com> Reply-To: References: <1442327229-28320-1-git-send-email-r.baldyga@samsung.com> <1442327229-28320-5-git-send-email-r.baldyga@samsung.com> <55F83B37.20408@samsung.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="aznLbwQ42o7LEaqN" Content-Disposition: inline In-Reply-To: <55F83B37.20408@samsung.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --aznLbwQ42o7LEaqN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 15, 2015 at 05:37:27PM +0200, Krzysztof Opasiak wrote: > Hello, >=20 > 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 > >--- > > 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(struc= t usb_ep *ep, > > */ > > static inline int usb_ep_enable(struct usb_ep *ep) > > { > >- return ep->ops->enable(ep, ep->desc); > >+ int ret =3D 0; > >+ > >+ if (!ep->enabled) { > >+ ret =3D ep->ops->enable(ep, ep->desc); > >+ if (!ret) > >+ ep->enabled =3D 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 =3D 0; > >+ > >+ if (ep->enabled) { > >+ ret =3D ep->ops->disable(ep); > >+ if (!ret) > >+ ep->enabled =3D false; > >+ } > >+ > >+ return ret; > > } > > >=20 > 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. usb_ep_is_enabled() should be a good addition but I don't see an issue ignoring usb_ep_enabled() for something that's already enabled. Imagine if you got an error when you tried to push the light switch to the 'on' position while the light was already on :-p I do think, though, that this can be simplified by returning early if already enabled: usb_ep_enable() { if (ep->enabled) return 0; return ep->ops->enable(ep, ep->desc); } and likewise for usb_ep_disable() --=20 balbi --aznLbwQ42o7LEaqN Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJV+DycAAoJEIaOsuA1yqRElmEQAIMRGV0L5xlmCF5448cG3drU rUKl4vqgxKiUW4FwKzxClb7+w1afT61iVLEq/PKNm9GK0fAJdQajZBU2ZQGjlVzp sl3tgLKY1OcKJLAzmFX32xKm8TWy2mw01ikY4MGuxh8wOgdGVqgb/ML4MdsArHmG tGG9e1sat4OyJEnaBgE3RAmTVl0Ishgdn8U8WrKUdFlg7UbW+xgWDs4NuUT5G5LV qAq0MOZpb5tiRmxu5m9rC36FVrMaUt0XK4md4Gdl8V6v1sz7JwXZCd7cfA+zmokd P/whmGla6imW+VOd2CLt+OosTzBAEJPEF753muV4kGP0f/RdfVPTLP+kP/aCwIWS /b4G6SC8UN40lECppbbCzWO9MbNCXbSUl05GEpOlZvmpbixeZCA9kxRu8O9AbGAu isrM6EQBjgSaiqo+Q/Te6Ro20DJjN0Gj/ELXJ8UiPauQsyFYBR9ABZARnwtd0cO/ m0GFmBvxep33bEDhYpiOzLePMCShsIVu9US+Ax4XxOcQniGwtRGKE/DOMM5UTWu2 MGnC2JZ5YSfOg+Y+A8UY/H+otx7zJrssuWmm1q9/A2+D5vvSeLu8z1AM6haMaTbN o5dhaUorzk1q+zrNWmvA/62lZ0cBsn2p7qw4KSHgzpbvLdAJTmQdyE89xWtVoKCU mFlafTrbA8i+TffXEBpr =+GR8 -----END PGP SIGNATURE----- --aznLbwQ42o7LEaqN--