]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ibmasm: Replace kzalloc() + copy_from_user() with memdup_user_nul()
authorThorsten Blum <thorsten.blum@linux.dev>
Fri, 5 Sep 2025 10:32:44 +0000 (12:32 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 6 Sep 2025 14:00:54 +0000 (16:00 +0200)
Replace kzalloc() followed by copy_from_user() with memdup_user_nul() to
improve and simplify remote_settings_file_write().

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://lore.kernel.org/r/20250905103247.423840-2-thorsten.blum@linux.dev
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/ibmasm/ibmasmfs.c

index c44de892a61ec474ba0d642201b73cc045ff5d65..2d5c1df827324d83ada554ecee98a03aadf0c0d0 100644 (file)
@@ -525,15 +525,9 @@ static ssize_t remote_settings_file_write(struct file *file, const char __user *
        if (*offset != 0)
                return 0;
 
-       buff = kzalloc (count + 1, GFP_KERNEL);
-       if (!buff)
-               return -ENOMEM;
-
-
-       if (copy_from_user(buff, ubuff, count)) {
-               kfree(buff);
-               return -EFAULT;
-       }
+       buff = memdup_user_nul(ubuff, count);
+       if (IS_ERR(buff))
+               return PTR_ERR(buff);
 
        value = simple_strtoul(buff, NULL, 10);
        writel(value, address);