]> git.dujemihanovic.xyz Git - linux.git/commitdiff
proc: fold kmalloc() + strcpy() into kmemdup()
authorAlexey Dobriyan <adobriyan@gmail.com>
Sun, 8 Sep 2024 09:27:45 +0000 (12:27 +0300)
committerChristian Brauner <brauner@kernel.org>
Mon, 9 Sep 2024 08:51:20 +0000 (10:51 +0200)
strcpy() will recalculate string length second time which is
unnecessary in this case.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Link: https://lore.kernel.org/r/90af27c1-0b86-47a6-a6c8-61a58b8aa747@p183
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/proc/generic.c

index c02f1e63f82d0947cf358aa6f23e4df99ab707b8..dbe82cf23ee49c98eb12c7bd6869482a69da82d3 100644 (file)
@@ -464,9 +464,9 @@ struct proc_dir_entry *proc_symlink(const char *name,
                          (S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO),1);
 
        if (ent) {
-               ent->data = kmalloc((ent->size=strlen(dest))+1, GFP_KERNEL);
+               ent->size = strlen(dest);
+               ent->data = kmemdup(dest, ent->size + 1, GFP_KERNEL);
                if (ent->data) {
-                       strcpy((char*)ent->data,dest);
                        ent->proc_iops = &proc_link_inode_operations;
                        ent = proc_register(parent, ent);
                } else {