diff mbox series

[v3,3/3] usb: core: hcd: use map_urb_for_dma for single step set feature urb

Message ID 1620370682-10199-3-git-send-email-jun.li@nxp.com (mailing list archive)
State Superseded
Headers show
Series [v3,1/3] usb: host: move EH SINGLE_STEP_SET_FEATURE implementation to core | expand

Commit Message

Jun Li May 7, 2021, 6:58 a.m. UTC
Use map_urb_for_dma() to improve the dma map code for single step
set feature request urb in test mode.

Signed-off-by: Li Jun <jun.li@nxp.com>
---
Change for v3:
- Correct the error handling if map_urb_for_dma() fails.

change for v2:
- Add this new patch to use map_urb_for_dma API to
  replace both of dma_map_single() calls, suggested by
  Jack Pham.

 drivers/usb/core/hcd.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

Comments

Alan Stern May 7, 2021, 3:42 p.m. UTC | #1
On Fri, May 07, 2021 at 02:58:02PM +0800, Li Jun wrote:
> Use map_urb_for_dma() to improve the dma map code for single step
> set feature request urb in test mode.
> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> ---
> Change for v3:
> - Correct the error handling if map_urb_for_dma() fails.
> 
> change for v2:
> - Add this new patch to use map_urb_for_dma API to
>   replace both of dma_map_single() calls, suggested by
>   Jack Pham.
> 
>  drivers/usb/core/hcd.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index d7eb9f179ca6..fa72697f4829 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -2159,16 +2159,11 @@ static struct urb *request_single_step_set_feature_urb(
>  	usb_get_urb(urb);
>  	atomic_inc(&urb->use_count);
>  	atomic_inc(&urb->dev->urbnum);
> -	urb->setup_dma = dma_map_single(
> -			hcd->self.sysdev,
> -			urb->setup_packet,
> -			sizeof(struct usb_ctrlrequest),
> -			DMA_TO_DEVICE);
> -	urb->transfer_dma = dma_map_single(
> -			hcd->self.sysdev,
> -			urb->transfer_buffer,
> -			urb->transfer_buffer_length,
> -			DMA_FROM_DEVICE);
> +	if (map_urb_for_dma(hcd, urb, GFP_KERNEL)) {
> +		usb_put_urb(urb);

You need to call usb_free_urb() here.

Alan Stern

> +		return NULL;
> +	}
> +
>  	urb->context = done;
>  	return urb;
>  }
> -- 
> 2.25.1
>
Jack Pham May 7, 2021, 4:52 p.m. UTC | #2
On Fri, May 07, 2021 at 11:42:29AM -0400, Alan Stern wrote:
> On Fri, May 07, 2021 at 02:58:02PM +0800, Li Jun wrote:
> > Use map_urb_for_dma() to improve the dma map code for single step
> > set feature request urb in test mode.
> > 
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> > Change for v3:
> > - Correct the error handling if map_urb_for_dma() fails.
> > 
> > change for v2:
> > - Add this new patch to use map_urb_for_dma API to
> >   replace both of dma_map_single() calls, suggested by
> >   Jack Pham.
> > 
> >  drivers/usb/core/hcd.c | 15 +++++----------
> >  1 file changed, 5 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> > index d7eb9f179ca6..fa72697f4829 100644
> > --- a/drivers/usb/core/hcd.c
> > +++ b/drivers/usb/core/hcd.c
> > @@ -2159,16 +2159,11 @@ static struct urb *request_single_step_set_feature_urb(
> >  	usb_get_urb(urb);
> >  	atomic_inc(&urb->use_count);
> >  	atomic_inc(&urb->dev->urbnum);
> > -	urb->setup_dma = dma_map_single(
> > -			hcd->self.sysdev,
> > -			urb->setup_packet,
> > -			sizeof(struct usb_ctrlrequest),
> > -			DMA_TO_DEVICE);
> > -	urb->transfer_dma = dma_map_single(
> > -			hcd->self.sysdev,
> > -			urb->transfer_buffer,
> > -			urb->transfer_buffer_length,
> > -			DMA_FROM_DEVICE);
> > +	if (map_urb_for_dma(hcd, urb, GFP_KERNEL)) {
> > +		usb_put_urb(urb);
> 
> You need to call usb_free_urb() here.

Hi Alan,

Aren't usb_put_urb() and usb_free_urb() identical? The former appears
to just be a macro subsitution of the latter.

Jack

> > +		return NULL;
> > +	}
> > +
> >  	urb->context = done;
> >  	return urb;
> >  }
> > -- 
> > 2.25.1
> >
Alan Stern May 7, 2021, 5:40 p.m. UTC | #3
On Fri, May 07, 2021 at 09:52:40AM -0700, Jack Pham wrote:
> On Fri, May 07, 2021 at 11:42:29AM -0400, Alan Stern wrote:
> > On Fri, May 07, 2021 at 02:58:02PM +0800, Li Jun wrote:
> > > Use map_urb_for_dma() to improve the dma map code for single step
> > > set feature request urb in test mode.
> > > 
> > > Signed-off-by: Li Jun <jun.li@nxp.com>
> > > ---
> > > Change for v3:
> > > - Correct the error handling if map_urb_for_dma() fails.
> > > 
> > > change for v2:
> > > - Add this new patch to use map_urb_for_dma API to
> > >   replace both of dma_map_single() calls, suggested by
> > >   Jack Pham.
> > > 
> > >  drivers/usb/core/hcd.c | 15 +++++----------
> > >  1 file changed, 5 insertions(+), 10 deletions(-)
> > > 
> > > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> > > index d7eb9f179ca6..fa72697f4829 100644
> > > --- a/drivers/usb/core/hcd.c
> > > +++ b/drivers/usb/core/hcd.c
> > > @@ -2159,16 +2159,11 @@ static struct urb *request_single_step_set_feature_urb(
> > >  	usb_get_urb(urb);
> > >  	atomic_inc(&urb->use_count);
> > >  	atomic_inc(&urb->dev->urbnum);
> > > -	urb->setup_dma = dma_map_single(
> > > -			hcd->self.sysdev,
> > > -			urb->setup_packet,
> > > -			sizeof(struct usb_ctrlrequest),
> > > -			DMA_TO_DEVICE);
> > > -	urb->transfer_dma = dma_map_single(
> > > -			hcd->self.sysdev,
> > > -			urb->transfer_buffer,
> > > -			urb->transfer_buffer_length,
> > > -			DMA_FROM_DEVICE);
> > > +	if (map_urb_for_dma(hcd, urb, GFP_KERNEL)) {
> > > +		usb_put_urb(urb);
> > 
> > You need to call usb_free_urb() here.
> 
> Hi Alan,
> 
> Aren't usb_put_urb() and usb_free_urb() identical? The former appears
> to just be a macro subsitution of the latter.

Yes, they are identical, although that's more or less an historical 
accident.  usb_free_urb was written before the refcount API came along.

The usb_put_urb() call here undoes the usb_get_urb() call at the top of 
the patch.  You still need one more call to decrease the refcount to 0.

Alan Stern
diff mbox series

Patch

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d7eb9f179ca6..fa72697f4829 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2159,16 +2159,11 @@  static struct urb *request_single_step_set_feature_urb(
 	usb_get_urb(urb);
 	atomic_inc(&urb->use_count);
 	atomic_inc(&urb->dev->urbnum);
-	urb->setup_dma = dma_map_single(
-			hcd->self.sysdev,
-			urb->setup_packet,
-			sizeof(struct usb_ctrlrequest),
-			DMA_TO_DEVICE);
-	urb->transfer_dma = dma_map_single(
-			hcd->self.sysdev,
-			urb->transfer_buffer,
-			urb->transfer_buffer_length,
-			DMA_FROM_DEVICE);
+	if (map_urb_for_dma(hcd, urb, GFP_KERNEL)) {
+		usb_put_urb(urb);
+		return NULL;
+	}
+
 	urb->context = done;
 	return urb;
 }