diff mbox series

usb: usbfs: only account once for mmap()'ed usb memory usage

Message ID 20190814212924.10381-1-gavinli@thegavinli.com (mailing list archive)
State Mainlined
Commit b08a6259a141baba98c57524ee4283fd91445bb8
Headers show
Series usb: usbfs: only account once for mmap()'ed usb memory usage | expand

Commit Message

Gavin Li Aug. 14, 2019, 9:29 p.m. UTC
From: Gavin Li <git@thegavinli.com>

Memory usage for USB memory allocated via mmap() is already accounted
for at mmap() time; no need to account for it again at submiturb time.

Signed-off-by: Gavin Li <git@thegavinli.com>
---
 drivers/usb/core/devio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Greg Kroah-Hartman Aug. 15, 2019, 12:53 p.m. UTC | #1
On Wed, Aug 14, 2019 at 02:29:24PM -0700, gavinli@thegavinli.com wrote:
> From: Gavin Li <git@thegavinli.com>
> 
> Memory usage for USB memory allocated via mmap() is already accounted
> for at mmap() time; no need to account for it again at submiturb time.
> 
> Signed-off-by: Gavin Li <git@thegavinli.com>
> ---
>  drivers/usb/core/devio.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

What commit does this fix?  What issue does this fix, is it something
that is user-visable?

> 
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index bbe9c2edd3e7..9681dd55473b 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1603,7 +1603,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
>  	if (as->usbm)
>  		num_sgs = 0;
>  
> -	u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
> +	u += sizeof(struct async) + sizeof(struct urb) +
> +	     (as->usbm ? 0 : uurb->buffer_length) +
>  	     num_sgs * sizeof(struct scatterlist);

Are you sure?  Where is the buffer_length being added to the size here?
What am I missing?

thanks,

greg k-h
Alan Stern Aug. 15, 2019, 7:16 p.m. UTC | #2
On Wed, 14 Aug 2019 gavinli@thegavinli.com wrote:

> From: Gavin Li <git@thegavinli.com>
> 
> Memory usage for USB memory allocated via mmap() is already accounted
> for at mmap() time; no need to account for it again at submiturb time.
> 
> Signed-off-by: Gavin Li <git@thegavinli.com>
> ---
>  drivers/usb/core/devio.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index bbe9c2edd3e7..9681dd55473b 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1603,7 +1603,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
>  	if (as->usbm)
>  		num_sgs = 0;
>  
> -	u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
> +	u += sizeof(struct async) + sizeof(struct urb) +
> +	     (as->usbm ? 0 : uurb->buffer_length) +
>  	     num_sgs * sizeof(struct scatterlist);
>  	ret = usbfs_increase_memory_usage(u);
>  	if (ret)
> 

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Gavin Li Aug. 16, 2019, 5:51 a.m. UTC | #3
It is done in usbdev_mmap(); it calls usbfs_increase_memory_usage() to
account for the buffer it allocates. No additional memory (other than
for the control structures) is needed when actually submitting the
URB.

On Thu, Aug 15, 2019 at 5:53 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, Aug 14, 2019 at 02:29:24PM -0700, gavinli@thegavinli.com wrote:
> > From: Gavin Li <git@thegavinli.com>
> >
> > Memory usage for USB memory allocated via mmap() is already accounted
> > for at mmap() time; no need to account for it again at submiturb time.
> >
> > Signed-off-by: Gavin Li <git@thegavinli.com>
> > ---
> >  drivers/usb/core/devio.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
>
> What commit does this fix?  What issue does this fix, is it something
> that is user-visable?
>
> >
> > diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> > index bbe9c2edd3e7..9681dd55473b 100644
> > --- a/drivers/usb/core/devio.c
> > +++ b/drivers/usb/core/devio.c
> > @@ -1603,7 +1603,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
> >       if (as->usbm)
> >               num_sgs = 0;
> >
> > -     u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
> > +     u += sizeof(struct async) + sizeof(struct urb) +
> > +          (as->usbm ? 0 : uurb->buffer_length) +
> >            num_sgs * sizeof(struct scatterlist);
>
> Are you sure?  Where is the buffer_length being added to the size here?
> What am I missing?
>
> thanks,
>
> greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index bbe9c2edd3e7..9681dd55473b 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1603,7 +1603,8 @@  static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
 	if (as->usbm)
 		num_sgs = 0;
 
-	u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
+	u += sizeof(struct async) + sizeof(struct urb) +
+	     (as->usbm ? 0 : uurb->buffer_length) +
 	     num_sgs * sizeof(struct scatterlist);
 	ret = usbfs_increase_memory_usage(u);
 	if (ret)