]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
autofs: replace manual symlink buffer allocation in autofs_dir_symlink
authorThorsten Blum <thorsten.blum@linux.dev>
Wed, 18 Mar 2026 00:12:21 +0000 (01:12 +0100)
committerChristian Brauner <brauner@kernel.org>
Wed, 18 Mar 2026 09:55:43 +0000 (10:55 +0100)
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
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>
fs/autofs/root.c

index 2c31002b314a8272899bf6ed147518d11d0f8572..186e960f1e2352a91f5d96a09ca6ee37f2ed3bab 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <linux/capability.h>
 #include <linux/compat.h>
+#include <linux/string.h>
 
 #include "autofs_i.h"
 
@@ -578,7 +579,6 @@ static int autofs_dir_symlink(struct mnt_idmap *idmap,
        struct autofs_info *ino = autofs_dentry_ino(dentry);
        struct autofs_info *p_ino;
        struct inode *inode;
-       size_t size = strlen(symname);
        char *cp;
 
        pr_debug("%s <- %pd\n", symname, dentry);
@@ -589,19 +589,17 @@ static int autofs_dir_symlink(struct mnt_idmap *idmap,
 
        autofs_del_active(dentry);
 
-       cp = kmalloc(size + 1, GFP_KERNEL);
+       cp = kstrdup(symname, GFP_KERNEL);
        if (!cp)
                return -ENOMEM;
 
-       strcpy(cp, symname);
-
        inode = autofs_get_inode(dir->i_sb, S_IFLNK | 0555);
        if (!inode) {
                kfree(cp);
                return -ENOMEM;
        }
        inode->i_private = cp;
-       inode->i_size = size;
+       inode->i_size = strlen(cp);
 
        d_make_persistent(dentry, inode);
        p_ino = autofs_dentry_ino(dentry->d_parent);