[PATCH] s390/hypfs_sprp: Replace kzalloc() + copy_from_user() with memdup_user()

From: Thorsten Blum

Date: Thu Sep 11 2025 - 17:46:49 EST


Replace kzalloc() followed by copy_from_user() with memdup_user() to
improve and simplify __hypfs_sprp_ioctl().

Return early if an error occurs instead of trying to allocate memory for
'diag304' when memory allocation for 'data' already failed.

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>
---
arch/s390/hypfs/hypfs_sprp.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/s390/hypfs/hypfs_sprp.c b/arch/s390/hypfs/hypfs_sprp.c
index 9fc3f0dae8f0..be11634bc7db 100644
--- a/arch/s390/hypfs/hypfs_sprp.c
+++ b/arch/s390/hypfs/hypfs_sprp.c
@@ -73,15 +73,16 @@ static int __hypfs_sprp_ioctl(void __user *user_area)
void *data;
int rc;

- rc = -ENOMEM;
data = (void *)get_zeroed_page(GFP_KERNEL);
- diag304 = kzalloc(sizeof(*diag304), GFP_KERNEL);
- if (!data || !diag304)
- goto out;
+ if (!data)
+ return -ENOMEM;

- rc = -EFAULT;
- if (copy_from_user(diag304, user_area, sizeof(*diag304)))
+ diag304 = memdup_user(user_area, sizeof(*diag304));
+ if (IS_ERR(diag304)) {
+ rc = PTR_ERR(diag304);
goto out;
+ }
+
rc = -EINVAL;
if ((diag304->args[0] >> 8) != 0 || diag304->args[1] > DIAG304_CMD_MAX)
goto out;
--
2.51.0