mm/memfd: Rename error labels for clarity
Subsystems (2)
PATCH 1/1 mm/memfd: Rename error labels for clarity
From: Ye Liu <[email protected]>
err_name --> err_fd (fd failure case)err_fd --> err_file (file failure case)
--- mm/memfd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/memfd.c +4 -4
@@ -475,22 +475,22 @@ SYSCALL_DEFINE2(memfd_create, fd =get_unused_fd_flags ((flags &MFD_CLOEXEC ) ?O_CLOEXEC :0 );if (fd <0 ) { error = fd; - goto err_name; + goto err_fd; } file =alloc_file (name, flags);if (IS_ERR (file)) { error =PTR_ERR (file); - goto err_fd; + goto err_file; }fd_install (fd, file);kfree (name);return fd; -err_fd: +err_file:put_unused_fd (fd); -err_name: +err_fd:kfree (name);return error; }
Signature · 1 line
2.25.1
Andrew Morton
maintainerQuoted 26 lines · On Mon, 9 Jun 2025 11:18:58 +0800 Ye Liu <[email protected]> wrote:
From: Ye Liu <[email protected]>
err_name-->err_fd(fd failure case)err_fd-->err_file(file failure case)...
mm/memfd.c +2
-2@@ -475,22 +475,22 @@ SYSCALL_DEFINE2(memfd_create, fd =get_unused_fd_flags ((flags &MFD_CLOEXEC ) ?O_CLOEXEC :0 );if (fd <0 ) { error = fd; - goto err_name; + goto err_fd; } file =alloc_file (name, flags);if (IS_ERR (file)) { error =PTR_ERR (file); - goto err_fd; + goto err_file; }fd_install (fd, file);kfree (name);
mm/memfd.c SYSCALL_DEFINE2(memfd_create, · line 496
Quoted 10 lines
mm/memfd.c +2
-2return fd; -err_fd: +err_file:put_unused_fd (fd); -err_name: +err_fd:kfree (name);return error; }
Not really, but I see what you mean.
"err_name" means "there was an error, so free the name".
"err_fd" means "there was a problem with the fd".
We tend to use the former convention. See
grep err_free mm/*.c
The memfd_create() code would be better if it used "err_free_name" and "err_free_fd" to remove this ambiguity.
Someone who was feeling bored could go through
grep "goto err_" mm/*.c
and check that we use this convention uniformly ;)
Quoted 50 lines · Andrew Morton
Quoted 26 lines · On Mon, 9 Jun 2025 11:18:58 +0800 Ye Liu <[email protected]> wrote:
From: Ye Liu <[email protected]>
err_name-->err_fd(fd failure case)err_fd-->err_file(file failure case)...
mm/memfd.c +2
-2@@ -475,22 +475,22 @@ SYSCALL_DEFINE2(memfd_create, fd =get_unused_fd_flags ((flags &MFD_CLOEXEC ) ?O_CLOEXEC :0 );if (fd <0 ) { error = fd; - goto err_name; + goto err_fd; } file =alloc_file (name, flags);if (IS_ERR (file)) { error =PTR_ERR (file); - goto err_fd; + goto err_file; }fd_install (fd, file);kfree (name);mm/memfd.c SYSCALL_DEFINE2(memfd_create, · line 496
Quoted 10 lines
mm/memfd.c +2
-2return fd; -err_fd: +err_file:put_unused_fd (fd); -err_name: +err_fd:kfree (name);return error; }Not really, but I see what you mean.
"
err_name" means "there was an error, so free the name"."
err_fd" means "there was a problem with the fd".We tend to use the former convention. See
grep
err_freemm/*.c
Quoted 9 lines
The
memfd_create()code would be better if it used "err_free_name" and "err_free_fd" to remove this ambiguity.Someone who was feeling bored could go through
grep "goto err_" mm/*.cand check that we use this convention uniformly ;)
As suggested, I've reviewed error handling labels in mm/*.c. "err_free_name" and "err_free_fd" would be better.
I will send patch v2 later using Subject: [PATCH v2] mm/memfd:
Clarify error handling labels in memfd_create ()
Thanks,
Ye