Skip to content

Commit 11f6bce

Browse files
tobluxhubcapsc
authored andcommitted
fs/orangefs: Replace kzalloc + copy_from_user with memdup_user_nul
Replace kzalloc() followed by copy_from_user() with memdup_user_nul() to simplify and improve orangefs_debug_write(). Allocate only 'count' bytes instead of the maximum size ORANGEFS_MAX_DEBUG_STRING_LEN, and set 'buf' to NULL to ensure kfree(buf) still works. No functional changes intended. Signed-off-by: Thorsten Blum <[email protected]> Signed-off-by: Mike Marshall <[email protected]>
1 parent 025e880 commit 11f6bce

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

fs/orangefs/orangefs-debugfs.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,13 @@ static ssize_t orangefs_debug_write(struct file *file,
440440
count = ORANGEFS_MAX_DEBUG_STRING_LEN;
441441
}
442442

443-
buf = kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
444-
if (!buf)
445-
goto out;
446-
447-
if (copy_from_user(buf, ubuf, count - 1)) {
443+
buf = memdup_user_nul(ubuf, count - 1);
444+
if (IS_ERR(buf)) {
448445
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
449-
"%s: copy_from_user failed!\n",
446+
"%s: memdup_user_nul failed!\n",
450447
__func__);
448+
rc = PTR_ERR(buf);
449+
buf = NULL;
451450
goto out;
452451
}
453452

0 commit comments

Comments
 (0)