Skip to contentSkip to conversation

fork: Remove unnecessary size argument when calling strscpy()

PATCH In review Thorsten Blum 2 participants 3 messages Mar 11, 2025 – Mar 18, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fork: Remove unnecessary size argument when calling strscpy()

The size parameter is optional and strscpy() automatically determines the length of the destination buffer using sizeof() if the argument is omitted. This makes the explicit sizeof() unnecessary. Remove it to simplify the code.

---
 kernel/fork.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/fork.c +1 -1
index 735405a9c5f3..81eef131e23c 100644
@@ -2248,7 +2248,7 @@ __latent_entropy struct task_struct *copy_process(
 		p->flags |= PF_IO_WORKER;
 
 	if (args->name)
-		strscpy_pad(p->comm, args->name, sizeof(p->comm));
+		strscpy_pad(p->comm, args->name);
 
 	p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? args->child_tid : NULL;
 	/*
Signature · 1 line
2.48.1
#1 lore raw
Quoted 6 lines · Thorsten Blum

The size parameter is optional and strscpy() automatically determines the length of the destination buffer using sizeof() if the argument is omitted. This makes the explicit sizeof() unnecessary. Remove it to simplify the code.

Hm not sure about this one, it's not really simplifying anything all too much and seems like somewhat useless churn?

It's pretty clear what's going on here already.

Quoted 20 lines
---
 kernel/fork.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/fork.c +1 -2
index 735405a9c5f3..81eef131e23c 100644
@@ -2248,7 +2248,7 @@ __latent_entropy struct task_struct *copy_process(
 		p->flags |= PF_IO_WORKER;
 
 	if (args->name)
-		strscpy_pad(p->comm, args->name, sizeof(p->comm));
+		strscpy_pad(p->comm, args->name);
 
 	p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? args->child_tid : NULL;
 	/*
--

2.48.1

#2 lore raw
Quoted 6 lines · Lorenzo Stoakes
Quoted 5 lines · Thorsten Blum

The size parameter is optional and strscpy() automatically determines the length of the destination buffer using sizeof() if the argument is omitted. This makes the explicit sizeof() unnecessary. Remove it to simplify the code.

Quoted 6 lines
Quoted 1 line

Hm not sure about this one, it's not really simplifying anything all too much and seems like somewhat useless churn?

It's pretty clear what's going on here already.

Yes, but explicitly specifying the default value for an optional parameter is redundant, and omitting it simplifies the code.

Thanks,
Thorsten