Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

autofs: replace manual symlink buffer allocation in autofs_dir_symlink

The symlink name was previously duplicated using an explicit kmalloc()
followed by strcpy(), which is deprecated [1]. Replace this open-coded
string duplication with kstrdup(), which allocates and copies the
symlink name with a single helper function.

Remove the local variable 'size' and set 'i_size' directly using
strlen(cp), which is equivalent to the previous value of 'size'.

This simplifies the code, uses common string-handling helpers, and
removes the deprecated use of strcpy().

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Acked-by: Ian Kent <raven@themaw.net>
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20260318001219.2354-3-thorsten.blum@linux.dev
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Thorsten Blum and committed by
Christian Brauner
f8909447 d227786a

+3 -5
+3 -5
fs/autofs/root.c
··· 7 7 8 8 #include <linux/capability.h> 9 9 #include <linux/compat.h> 10 + #include <linux/string.h> 10 11 11 12 #include "autofs_i.h" 12 13 ··· 579 578 struct autofs_info *ino = autofs_dentry_ino(dentry); 580 579 struct autofs_info *p_ino; 581 580 struct inode *inode; 582 - size_t size = strlen(symname); 583 581 char *cp; 584 582 585 583 pr_debug("%s <- %pd\n", symname, dentry); ··· 589 589 590 590 autofs_del_active(dentry); 591 591 592 - cp = kmalloc(size + 1, GFP_KERNEL); 592 + cp = kstrdup(symname, GFP_KERNEL); 593 593 if (!cp) 594 594 return -ENOMEM; 595 - 596 - strcpy(cp, symname); 597 595 598 596 inode = autofs_get_inode(dir->i_sb, S_IFLNK | 0555); 599 597 if (!inode) { ··· 599 601 return -ENOMEM; 600 602 } 601 603 inode->i_private = cp; 602 - inode->i_size = size; 604 + inode->i_size = strlen(cp); 603 605 604 606 d_make_persistent(dentry, inode); 605 607 p_ino = autofs_dentry_ino(dentry->d_parent);