summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Rapoport (Microsoft) <rppt@kernel.org>2026-05-31 17:08:26 +0300
committerAlexander Gordeev <agordeev@linux.ibm.com>2026-06-03 15:32:45 +0200
commitb8bce5f1180fe6d9226b6f25af902f905ca015ae (patch)
tree1fd858416b0d96d4df46fa8495ab52bb788871b6
parentcccb81940ac2c454f3003dd945b7f354958e3576 (diff)
downloadlinux-b8bce5f1180fe6d9226b6f25af902f905ca015ae.tar.gz
linux-b8bce5f1180fe6d9226b6f25af902f905ca015ae.zip
s390/trng: Replace __get_free_page() with kmalloc()
trng_read() allocates a temporary staging buffer for CPACF TRNG random data before copying it to userspace. 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_page() with kmalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com Reviewed-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
-rw-r--r--drivers/char/hw_random/s390-trng.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/char/hw_random/s390-trng.c b/drivers/char/hw_random/s390-trng.c
index 3024d5e9fd61..5520f66274b3 100644
--- a/drivers/char/hw_random/s390-trng.c
+++ b/drivers/char/hw_random/s390-trng.c
@@ -20,6 +20,7 @@
#include <linux/atomic.h>
#include <linux/random.h>
#include <linux/sched/signal.h>
+#include <linux/slab.h>
#include <asm/debug.h>
#include <asm/cpacf.h>
#include <asm/archrandom.h>
@@ -67,7 +68,7 @@ static ssize_t trng_read(struct file *file, char __user *ubuf,
*/
if (nbytes > sizeof(buf)) {
- p = (u8 *) __get_free_page(GFP_KERNEL);
+ p = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!p)
return -ENOMEM;
}
@@ -94,7 +95,7 @@ static ssize_t trng_read(struct file *file, char __user *ubuf,
}
if (p != buf)
- free_page((unsigned long) p);
+ kfree(p);
DEBUG_DBG("trng_read()=%zd\n", ret);
return ret;