mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mike Rapoport <rpppt@kernel.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH 2/2] usb: core: devices: use kmalloc() to allocate dump buffer
Date: Tue, 30 Jun 2026 12:03:48 -0400	[thread overview]
Message-ID: <fb38dac8-7832-49df-a4d7-5488f210f83d@rowland.harvard.edu> (raw)
In-Reply-To: <20260630-b4-usb-v1-2-8d547235c374@kernel.org>

On Tue, Jun 30, 2026 at 01:27:09PM +0300, Mike Rapoport (Microsoft) wrote:
> usb_device_dump() allocates a buffer for formatting
> /proc/bus/usb/devices output text.

You mean /sys/kernel/debug/usb/devices.  There is no /proc/bus/usb/ 
directory.

Aside from that mistake:

Reviewed-by: Alan Stern <stern@rowland.harvard.edu>

Alan Stern

> 
> This buffer can be allocated with kmalloc() as there's nothing special
> about it to go directly to the page allocator.
> 
> kmalloc() provides a better API that does not require ugly casts and
> kfree() does not need to know the size of the freed object.
> 
> Performance difference between kmalloc() and __get_free_pages() is not
> measurable as both allocators take an object/page from a per-CPU list for
> fast path allocations.
> 
> For the slow path the performance is anyway determined by the amount of
> reclaim involved rather than by what allocator is used.
> 
> Replace use of __get_free_pages() with kmalloc() and free_pages() with
> kfree().
> 
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
>  drivers/usb/core/devices.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
> index a247da73f34d..6f0354aba38b 100644
> --- a/drivers/usb/core/devices.c
> +++ b/drivers/usb/core/devices.c
> @@ -37,6 +37,7 @@
>   */
>  
>  #include <linux/fs.h>
> +#include <linux/slab.h>
>  #include <linux/mm.h>
>  #include <linux/gfp.h>
>  #include <linux/usb.h>
> @@ -408,7 +409,7 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
>  		return 0;
>  	/* allocate 2^1 pages = 8K (on i386);
>  	 * should be more than enough for one device */
> -	pages_start = (char *)__get_free_pages(GFP_NOIO, 1);
> +	pages_start = kmalloc(PAGE_SIZE << 1, GFP_NOIO);
>  	if (!pages_start)
>  		return -ENOMEM;
>  
> @@ -479,7 +480,7 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
>  		if (length > *nbytes)
>  			length = *nbytes;
>  		if (copy_to_user(*buffer, pages_start + *skip_bytes, length)) {
> -			free_pages((unsigned long)pages_start, 1);
> +			kfree(pages_start);
>  			return -EFAULT;
>  		}
>  		*nbytes -= length;
> @@ -490,7 +491,7 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
>  	} else
>  		*skip_bytes -= length;
>  
> -	free_pages((unsigned long)pages_start, 1);
> +	kfree(pages_start);
>  
>  	/* Now look at all of this device's children. */
>  	usb_hub_for_each_child(usbdev, chix, childdev) {
> 
> -- 
> 2.53.0
> 

      reply	other threads:[~2026-06-30 16:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 10:27 [PATCH 0/2] USB: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
2026-06-30 10:27 ` [PATCH 1/2] usb: host: ohci-dbg: use kmalloc() for print buffer Mike Rapoport (Microsoft)
2026-06-30 15:56   ` Alan Stern
2026-06-30 10:27 ` [PATCH 2/2] usb: core: devices: use kmalloc() to allocate dump buffer Mike Rapoport (Microsoft)
2026-06-30 16:03   ` Alan Stern [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb38dac8-7832-49df-a4d7-5488f210f83d@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rpppt@kernel.org \
    --cc=rppt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®