From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>,
Brad Warrum <bwarrum@linux.ibm.com>,
Eli Billauer <eli.billauer@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Michal Simek <michal.simek@amd.com>,
Ritu Agarwal <rituagar@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Matthew Wilcox <willy@infradead.org>,
Mike Rapoport <rppt@kernel.org>,
Vlastimil Babka <vbabka@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linuxppc-dev@lists.ozlabs.org
Subject: [PATCH 2/4] char: xillybus: replace __get_free_pages() with kmalloc()
Date: Sun, 30 Aug 2026 10:47:59 +0300 [thread overview]
Message-ID: <20260830-char-misc-v1-2-05e2ce44f291@kernel.org> (raw)
In-Reply-To: <20260830-char-misc-v1-0-05e2ce44f291@kernel.org>
fifo_init() allocates the buffers backing the software FIFO and
endpoint_alloc() allocates the transfer buffers of a USB endpoint.
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.
Since kmalloc() does not need the allocation order, ask it for the buffer
sizes the driver already tracks and drop the now unused order fields. For
a FIFO smaller than a page this also stops rounding the allocation up to
PAGE_SIZE.
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
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/char/xillybus/xillyusb.c | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
index 34e7ad3bcab3..193e2a5b599e 100644
--- a/drivers/char/xillybus/xillyusb.c
+++ b/drivers/char/xillybus/xillyusb.c
@@ -71,7 +71,6 @@ struct xillyfifo {
unsigned int bufsize; /* In bytes, always a power of 2 */
unsigned int bufnum;
unsigned int size; /* Lazy: Equals bufsize * bufnum */
- unsigned int buf_order;
int fill; /* Number of bytes in the FIFO */
spinlock_t lock;
@@ -95,7 +94,6 @@ struct xillyusb_endpoint {
struct list_head filled_buffers;
spinlock_t buffers_lock; /* protect these two lists */
- unsigned int order;
unsigned int buffer_size;
unsigned int fill_mask;
@@ -370,7 +368,6 @@ static int fifo_init(struct xillyfifo *fifo,
unsigned int log2_size)
{
unsigned int log2_bufnum;
- unsigned int buf_order;
int i;
unsigned int log2_fifo_buf_size;
@@ -380,18 +377,14 @@ static int fifo_init(struct xillyfifo *fifo,
if (log2_size > log2_fifo_buf_size) {
log2_bufnum = log2_size - log2_fifo_buf_size;
- buf_order = fifo_buf_order;
fifo->bufsize = 1 << log2_fifo_buf_size;
} else {
log2_bufnum = 0;
- buf_order = (log2_size > PAGE_SHIFT) ?
- log2_size - PAGE_SHIFT : 0;
fifo->bufsize = 1 << log2_size;
}
fifo->bufnum = 1 << log2_bufnum;
fifo->size = fifo->bufnum * fifo->bufsize;
- fifo->buf_order = buf_order;
fifo->mem = kmalloc_array(fifo->bufnum, sizeof(void *), GFP_KERNEL);
@@ -399,8 +392,7 @@ static int fifo_init(struct xillyfifo *fifo,
return -ENOMEM;
for (i = 0; i < fifo->bufnum; i++) {
- fifo->mem[i] = (void *)
- __get_free_pages(GFP_KERNEL, buf_order);
+ fifo->mem[i] = kmalloc(fifo->bufsize, GFP_KERNEL);
if (!fifo->mem[i])
goto memfail;
@@ -417,7 +409,7 @@ static int fifo_init(struct xillyfifo *fifo,
memfail:
for (i--; i >= 0; i--)
- free_pages((unsigned long)fifo->mem[i], buf_order);
+ kfree(fifo->mem[i]);
kfree(fifo->mem);
fifo->mem = NULL;
@@ -438,7 +430,7 @@ static void fifo_mem_release(struct xillyfifo *fifo)
return;
for (i = 0; i < fifo->bufnum; i++)
- free_pages((unsigned long)fifo->mem[i], fifo->buf_order);
+ kfree(fifo->mem[i]);
kfree(fifo->mem);
}
@@ -477,7 +469,7 @@ static void endpoint_dealloc(struct xillyusb_endpoint *ep)
struct xillybuffer *xb =
list_entry(this, struct xillybuffer, entry);
- free_pages((unsigned long)xb->buf, ep->order);
+ kfree(xb->buf);
kfree(xb);
}
@@ -509,8 +501,7 @@ static struct xillyusb_endpoint
init_usb_anchor(&ep->anchor);
INIT_WORK(&ep->workitem, work);
- ep->order = order;
- ep->buffer_size = 1 << (PAGE_SHIFT + order);
+ ep->buffer_size = 1 << (PAGE_SHIFT + order);
ep->outstanding_urbs = 0;
ep->drained = true;
ep->wake_on_drain = false;
@@ -520,7 +511,6 @@ static struct xillyusb_endpoint
for (i = 0; i < bufnum; i++) {
struct xillybuffer *xb;
- unsigned long addr;
xb = kzalloc_obj(*xb);
@@ -529,15 +519,14 @@ static struct xillyusb_endpoint
return NULL;
}
- addr = __get_free_pages(GFP_KERNEL, order);
+ xb->buf = kmalloc(ep->buffer_size, GFP_KERNEL);
- if (!addr) {
+ if (!xb->buf) {
kfree(xb);
endpoint_dealloc(ep);
return NULL;
}
- xb->buf = (void *)addr;
xb->ep = ep;
list_add_tail(&xb->entry, &ep->buffers);
}
--
2.53.0
next prev parent reply other threads:[~2026-08-30 7:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 7:47 [PATCH 0/4] char/misc: replace page allocator calls with k[mz]alloc() Mike Rapoport (Microsoft)
2026-08-30 7:47 ` [PATCH 1/4] char: xilinx_hwicap: " Mike Rapoport (Microsoft)
2026-08-30 7:47 ` Mike Rapoport (Microsoft) [this message]
2026-08-30 7:48 ` [PATCH 3/4] misc: ibmvmc: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
2026-08-30 7:48 ` [PATCH 4/4] platform: goldfish: pipe: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
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=20260830-char-misc-v1-2-05e2ce44f291@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bwarrum@linux.ibm.com \
--cc=david@kernel.org \
--cc=eli.billauer@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=michal.simek@amd.com \
--cc=rituagar@linux.ibm.com \
--cc=vbabka@kernel.org \
--cc=willy@infradead.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®