linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] usb: gadget: fix wrong endpoint desc
@ 2019-12-04  5:33 EJ Hsu
  2019-12-04  7:06 ` Peter Chen
  0 siblings, 1 reply; 4+ messages in thread
From: EJ Hsu @ 2019-12-04  5:33 UTC (permalink / raw)
  To: balbi; +Cc: linux-usb, EJ Hsu

Gadget driver should always use config_ep_by_speed() to initialize
usb_ep struct according to usb device's operating speed. Otherwise,
usb_ep struct may be wrong if usb devcie's operating speed is changed.

The key point in this patch is that we want to make sure the descpointer
in usb_ep struct will be set to NULL when gadget is disconnected.
This will force it to call config_ep_by_speed() to correctly initialize
usb_ep struct based on the new operating speed when gadget is
re-connected later.

Signed-off-by: EJ Hsu <ejh@nvidia.com>
---
v2: fix the coding style
---
 drivers/usb/gadget/function/f_ecm.c   | 6 +++++-
 drivers/usb/gadget/function/f_rndis.c | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_ecm.c b/drivers/usb/gadget/function/f_ecm.c
index 6ce044008cf6..460d5d7c984f 100644
--- a/drivers/usb/gadget/function/f_ecm.c
+++ b/drivers/usb/gadget/function/f_ecm.c
@@ -621,8 +621,12 @@ static void ecm_disable(struct usb_function *f)
 
 	DBG(cdev, "ecm deactivated\n");
 
-	if (ecm->port.in_ep->enabled)
+	if (ecm->port.in_ep->enabled) {
 		gether_disconnect(&ecm->port);
+	} else {
+		ecm->port.in_ep->desc = NULL;
+		ecm->port.out_ep->desc = NULL;
+	}
 
 	usb_ep_disable(ecm->notify);
 	ecm->notify->desc = NULL;
diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c
index d48df36622b7..0d8e4a364ca6 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -618,6 +618,7 @@ static void rndis_disable(struct usb_function *f)
 	gether_disconnect(&rndis->port);
 
 	usb_ep_disable(rndis->notify);
+	rndis->notify->desc = NULL;
 }
 
 /*-------------------------------------------------------------------------*/
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] usb: gadget: fix wrong endpoint desc
  2019-12-04  5:33 [PATCH v2] usb: gadget: fix wrong endpoint desc EJ Hsu
@ 2019-12-04  7:06 ` Peter Chen
  2019-12-06  2:24   ` EJ Hsu
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Chen @ 2019-12-04  7:06 UTC (permalink / raw)
  To: EJ Hsu; +Cc: balbi, linux-usb

On 19-12-03 21:33:22, EJ Hsu wrote:
> Gadget driver should always use config_ep_by_speed() to initialize
> usb_ep struct according to usb device's operating speed. Otherwise,
> usb_ep struct may be wrong if usb devcie's operating speed is changed.
> 
> The key point in this patch is that we want to make sure the descpointer

Typo

Otherwise:
Reviewed-by: Peter Chen <peter.chen@nxp.com>

> in usb_ep struct will be set to NULL when gadget is disconnected.
> This will force it to call config_ep_by_speed() to correctly initialize
> usb_ep struct based on the new operating speed when gadget is
> re-connected later.
> 
> Signed-off-by: EJ Hsu <ejh@nvidia.com>
> ---
> v2: fix the coding style
> ---
>  drivers/usb/gadget/function/f_ecm.c   | 6 +++++-
>  drivers/usb/gadget/function/f_rndis.c | 1 +
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/function/f_ecm.c b/drivers/usb/gadget/function/f_ecm.c
> index 6ce044008cf6..460d5d7c984f 100644
> --- a/drivers/usb/gadget/function/f_ecm.c
> +++ b/drivers/usb/gadget/function/f_ecm.c
> @@ -621,8 +621,12 @@ static void ecm_disable(struct usb_function *f)
>  
>  	DBG(cdev, "ecm deactivated\n");
>  
> -	if (ecm->port.in_ep->enabled)
> +	if (ecm->port.in_ep->enabled) {
>  		gether_disconnect(&ecm->port);
> +	} else {
> +		ecm->port.in_ep->desc = NULL;
> +		ecm->port.out_ep->desc = NULL;
> +	}
>  
>  	usb_ep_disable(ecm->notify);
>  	ecm->notify->desc = NULL;
> diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c
> index d48df36622b7..0d8e4a364ca6 100644
> --- a/drivers/usb/gadget/function/f_rndis.c
> +++ b/drivers/usb/gadget/function/f_rndis.c
> @@ -618,6 +618,7 @@ static void rndis_disable(struct usb_function *f)
>  	gether_disconnect(&rndis->port);
>  
>  	usb_ep_disable(rndis->notify);
> +	rndis->notify->desc = NULL;
>  }
>  
>  /*-------------------------------------------------------------------------*/
> -- 
> 2.17.1
> 

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH v2] usb: gadget: fix wrong endpoint desc
  2019-12-04  7:06 ` Peter Chen
@ 2019-12-06  2:24   ` EJ Hsu
  2019-12-06  2:36     ` Peter Chen
  0 siblings, 1 reply; 4+ messages in thread
From: EJ Hsu @ 2019-12-06  2:24 UTC (permalink / raw)
  To: Peter Chen; +Cc: balbi, linux-usb

Hi Peter, 

Peter Chen wrote:
> On 19-12-03 21:33:22, EJ Hsu wrote:
> > Gadget driver should always use config_ep_by_speed() to initialize
> > usb_ep struct according to usb device's operating speed. Otherwise,
> > usb_ep struct may be wrong if usb devcie's operating speed is changed.
> >
> > The key point in this patch is that we want to make sure the
> > descpointer
> 
> Typo
> 
> Otherwise:
> Reviewed-by: Peter Chen <peter.chen@nxp.com>
> 

I have uploaded a new patch following your feedback.
Could you please help to review it again?

Thanks,
EJ
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH v2] usb: gadget: fix wrong endpoint desc
  2019-12-06  2:24   ` EJ Hsu
@ 2019-12-06  2:36     ` Peter Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Chen @ 2019-12-06  2:36 UTC (permalink / raw)
  To: EJ Hsu; +Cc: balbi, linux-usb

 
> 
> Peter Chen wrote:
> > On 19-12-03 21:33:22, EJ Hsu wrote:
> > > Gadget driver should always use config_ep_by_speed() to initialize
> > > usb_ep struct according to usb device's operating speed. Otherwise,
> > > usb_ep struct may be wrong if usb devcie's operating speed is changed.
> > >
> > > The key point in this patch is that we want to make sure the
> > > descpointer
> >
> > Typo
> >
> > Otherwise:
> > Reviewed-by: Peter Chen <peter.chen@nxp.com>
> >
> 
> I have uploaded a new patch following your feedback.
> Could you please help to review it again?
> 

Feel free to add my Reviewed-by for your v3 since you only change the
typo I pointed.

Peter

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-06  2:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04  5:33 [PATCH v2] usb: gadget: fix wrong endpoint desc EJ Hsu
2019-12-04  7:06 ` Peter Chen
2019-12-06  2:24   ` EJ Hsu
2019-12-06  2:36     ` Peter Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).