* [PATCH] mm/memfd: Rename error labels for clarity
@ 2025-06-09 3:18 Ye Liu
2025-06-10 0:26 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Ye Liu @ 2025-06-09 3:18 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel, Ye Liu
From: Ye Liu <liuye@kylinos.cn>
err_name --> err_fd (fd failure case)
err_fd --> err_file (file failure case)
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/memfd.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/memfd.c b/mm/memfd.c
index ab367e61553d..628bfa5fa9da 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/memfd: Rename error labels for clarity
2025-06-09 3:18 [PATCH] mm/memfd: Rename error labels for clarity Ye Liu
@ 2025-06-10 0:26 ` Andrew Morton
2025-06-10 1:51 ` Ye Liu
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2025-06-10 0:26 UTC (permalink / raw)
To: Ye Liu; +Cc: linux-mm, linux-kernel, Ye Liu
On Mon, 9 Jun 2025 11:18:58 +0800 Ye Liu <ye.liu@linux.dev> wrote:
> From: Ye Liu <liuye@kylinos.cn>
>
> err_name --> err_fd (fd failure case)
> err_fd --> err_file (file failure case)
>
> ...
>
> --- a/mm/memfd.c
> +++ b/mm/memfd.c
> @@ -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;
> }
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 ;)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/memfd: Rename error labels for clarity
2025-06-10 0:26 ` Andrew Morton
@ 2025-06-10 1:51 ` Ye Liu
0 siblings, 0 replies; 3+ messages in thread
From: Ye Liu @ 2025-06-10 1:51 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-mm, linux-kernel, Ye Liu
On 2025/6/10 08:26, Andrew Morton wrote:
> On Mon, 9 Jun 2025 11:18:58 +0800 Ye Liu <ye.liu@linux.dev> wrote:
>
>> From: Ye Liu <liuye@kylinos.cn>
>>
>> err_name --> err_fd (fd failure case)
>> err_fd --> err_file (file failure case)
>>
>> ...
>>
>> --- a/mm/memfd.c
>> +++ b/mm/memfd.c
>> @@ -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;
>> }
>
> 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 ;)
>
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-10 1:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-09 3:18 [PATCH] mm/memfd: Rename error labels for clarity Ye Liu
2025-06-10 0:26 ` Andrew Morton
2025-06-10 1:51 ` Ye Liu
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).