linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] proc: fold kmalloc() + strcpy() into kmemdup()
@ 2024-09-08  9:27 Alexey Dobriyan
  2024-09-08 11:24 ` Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alexey Dobriyan @ 2024-09-08  9:27 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, linux-fsdevel

strcpy() will recalculate string length second time which is
unnecessary in this case.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 fs/proc/generic.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -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 {

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-09-11 10:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-08  9:27 [PATCH] proc: fold kmalloc() + strcpy() into kmemdup() Alexey Dobriyan
2024-09-08 11:24 ` Markus Elfring
2024-09-09  8:52 ` Christian Brauner
2024-09-09 15:13 ` David Laight
2024-09-11 10:42   ` Alexey Dobriyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).