Linux USB
 help / color / mirror / Atom feed
From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
To: Alan Stern <stern@rowland.harvard.edu>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mike Rapoport <rpppt@kernel.org>,
	linux-kernel@vger.kernel.org,  linux-mm@kvack.org,
	linux-usb@vger.kernel.org,
	 "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Subject: [PATCH 1/2] usb: host: ohci-dbg: use kmalloc() for print buffer
Date: Tue, 30 Jun 2026 13:27:08 +0300	[thread overview]
Message-ID: <20260630-b4-usb-v1-1-8d547235c374@kernel.org> (raw)
In-Reply-To: <20260630-b4-usb-v1-0-8d547235c374@kernel.org>

ochi-dbg allocates buffers for formatting of various dump outputs.

These buffers can be allocated with kmalloc() as there's nothing special
about them 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_zeroed_page() with kzalloc() and free_page() with
kfree().

While on it, make kfree() calls unconditional since kfree() can be passed a
NULL pointer.

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 drivers/usb/host/ohci-dbg.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 9e0e06bbc570..0a648a7d9136 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-1.0+
+#include <linux/slab.h>
 /*
  * OHCI HCD (Host Controller Driver) for USB.
  *
@@ -683,7 +684,7 @@ static int fill_buffer(struct debug_buffer *buf)
 	int ret;
 
 	if (!buf->page)
-		buf->page = (char *)get_zeroed_page(GFP_KERNEL);
+		buf->page = kzalloc(PAGE_SIZE, GFP_KERNEL);
 
 	if (!buf->page) {
 		ret = -ENOMEM;
@@ -729,11 +730,8 @@ static int debug_close(struct inode *inode, struct file *file)
 {
 	struct debug_buffer *buf = file->private_data;
 
-	if (buf) {
-		if (buf->page)
-			free_page((unsigned long)buf->page);
-		kfree(buf);
-	}
+	kfree(buf->page);
+	kfree(buf);
 
 	return 0;
 }
@@ -782,4 +780,3 @@ static inline void remove_debug_files (struct ohci_hcd *ohci)
 }
 
 /*-------------------------------------------------------------------------*/
-

-- 
2.53.0


  reply	other threads:[~2026-06-30 10:27 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 ` Mike Rapoport (Microsoft) [this message]
2026-06-30 15:56   ` [PATCH 1/2] usb: host: ohci-dbg: use kmalloc() for print buffer 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

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=20260630-b4-usb-v1-1-8d547235c374@kernel.org \
    --to=rppt@kernel.org \
    --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=stern@rowland.harvard.edu \
    /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