Skip to contentSkip to conversation

ibmasm: Replace kzalloc() + copy_from_user() with memdup_user_nul()

PATCH New Thorsten Blum 1 participant 1 message Sep 5, 2025 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ibmasm: Replace kzalloc() + copy_from_user() with memdup_user_nul()

Replace kzalloc() followed by copy_from_user() with memdup_user_nul() to improve and simplify remote_settings_file_write().

No functional changes intended.

---
 drivers/misc/ibmasm/ibmasmfs.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/misc/ibmasm/ibmasmfs.c +3 -9
index c44de892a61e..2d5c1df82732 100644
@@ -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);
Signature · 1 line
2.51.0