[PATCH 13/13] s390/scm: Use kmalloc() for SCM information

From: Mike Rapoport (Microsoft)

Date: Mon Sep 07 2026 - 06:28:31 EST


scm_update_information() allocates the response buffer for the CHSC
Store SCM Information command.

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().

While on it, use __free(kfree) for the local response buffer.

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@xxxxxxxxxx
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
drivers/s390/cio/scm.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/s390/cio/scm.c b/drivers/s390/cio/scm.c
index 171212a6d2d9c..b79fe023ab8d1 100644
--- a/drivers/s390/cio/scm.c
+++ b/drivers/s390/cio/scm.c
@@ -13,6 +13,7 @@
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/err.h>
+#include <linux/cleanup.h>
#include <asm/eadm.h>
#include "chsc.h"

@@ -224,12 +225,12 @@ static int scm_add(struct chsc_scm_info *scm_info, size_t num)

int scm_update_information(void)
{
- struct chsc_scm_info *scm_info;
+ struct chsc_scm_info *scm_info __free(kfree) = NULL;
u64 token = 0;
size_t num;
int ret;

- scm_info = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
+ scm_info = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
if (!scm_info)
return -ENOMEM;

@@ -250,8 +251,6 @@ int scm_update_information(void)
token = scm_info->restok;
} while (token);

- free_page((unsigned long)scm_info);
-
return ret;
}


--
2.53.0