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 1/4] char: xilinx_hwicap: replace page allocator calls with k[mz]alloc()
Date: Sun, 30 Aug 2026 10:47:58 +0300 [thread overview]
Message-ID: <20260830-char-misc-v1-1-05e2ce44f291@kernel.org> (raw)
In-Reply-To: <20260830-char-misc-v1-0-05e2ce44f291@kernel.org>
hwicap_read() and hwicap_write() allocate temporary buffers used to pass
the FPGA configuration data to and from userspace.
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_free_page() and get_zeroed_page() with kmalloc() and
kzalloc() and free_page() 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/xilinx_hwicap/xilinx_hwicap.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index 9bb5fa642fd8..bbeb9b6060dc 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -382,7 +382,7 @@ hwicap_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
4 - bytes_to_read);
} else {
/* Get new data from the ICAP, and return what was requested. */
- kbuf = (u32 *) get_zeroed_page(GFP_KERNEL);
+ kbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!kbuf) {
status = -ENOMEM;
goto error;
@@ -412,13 +412,13 @@ hwicap_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
/* If we didn't read correctly, then bail out. */
if (status) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
goto error;
}
/* If we fail to return the data to the user, then bail out. */
if (copy_to_user(buf, kbuf, bytes_to_read)) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = -EFAULT;
goto error;
}
@@ -426,7 +426,7 @@ hwicap_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
kbuf,
bytes_remaining);
drvdata->read_buffer_in_use = bytes_remaining;
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
}
status = bytes_to_read;
error:
@@ -457,7 +457,7 @@ hwicap_write(struct file *file, const char __user *buf,
goto error;
}
- kbuf = (u32 *) __get_free_page(GFP_KERNEL);
+ kbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!kbuf) {
status = -ENOMEM;
goto error;
@@ -479,13 +479,13 @@ hwicap_write(struct file *file, const char __user *buf,
(((char *)kbuf) + drvdata->write_buffer_in_use),
buf + written,
len - (drvdata->write_buffer_in_use))) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = -EFAULT;
goto error;
}
} else {
if (copy_from_user(kbuf, buf + written, len)) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = -EFAULT;
goto error;
}
@@ -495,7 +495,7 @@ hwicap_write(struct file *file, const char __user *buf,
kbuf, len >> 2);
if (status) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = -EFAULT;
goto error;
}
@@ -516,7 +516,7 @@ hwicap_write(struct file *file, const char __user *buf,
}
}
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = written;
error:
mutex_unlock(&drvdata->sem);
--
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: " Mike Rapoport (Microsoft)
2026-08-30 7:47 ` Mike Rapoport (Microsoft) [this message]
2026-08-30 7:47 ` [PATCH 2/4] char: xillybus: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
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-1-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®