* [PATCH] ext4: Fix ERR_PTR(0) in ext4_mkdir()
@ 2026-05-20 7:46 Hongling Zeng
2026-05-20 8:42 ` Jan Kara
2026-05-20 9:19 ` Zhang Yi
0 siblings, 2 replies; 4+ messages in thread
From: Hongling Zeng @ 2026-05-20 7:46 UTC (permalink / raw)
To: tytso, adilger.kernel, libaokun, jack, ojaswin, ritesh.list,
yi.zhang, neil, brauner, jlayton
Cc: linux-ext4, linux-kernel, zhongling0719, Hongling Zeng
When mkdir succeeds, ext4_mkdir() returns ERR_PTR(0) which is incorrect.
It should return NULL instead for success and ERR_PTR() only with
negative error codes for failure.
Fixes: 88d5baf69082 ("Change inode_operations.mkdir to return struct dentry *")
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
fs/ext4/namei.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 4a47fbd8dd30..8cadaeb15b2b 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -3054,7 +3054,7 @@ static struct dentry *ext4_mkdir(struct mnt_idmap *idmap, struct inode *dir,
out_retry:
if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
goto retry;
- return ERR_PTR(err);
+ return err ? ERR_PTR(err) : NULL;
}
/*
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] ext4: Fix ERR_PTR(0) in ext4_mkdir()
2026-05-20 7:46 [PATCH] ext4: Fix ERR_PTR(0) in ext4_mkdir() Hongling Zeng
@ 2026-05-20 8:42 ` Jan Kara
2026-05-20 9:19 ` Zhang Yi
1 sibling, 0 replies; 4+ messages in thread
From: Jan Kara @ 2026-05-20 8:42 UTC (permalink / raw)
To: Hongling Zeng
Cc: tytso, adilger.kernel, libaokun, jack, ojaswin, ritesh.list,
yi.zhang, neil, brauner, jlayton, linux-ext4, linux-kernel,
zhongling0719
On Wed 20-05-26 15:46:34, Hongling Zeng wrote:
> When mkdir succeeds, ext4_mkdir() returns ERR_PTR(0) which is incorrect.
> It should return NULL instead for success and ERR_PTR() only with
> negative error codes for failure.
>
> Fixes: 88d5baf69082 ("Change inode_operations.mkdir to return struct dentry *")
> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
You're right this is a bit sloppy programming although there's no actual
functional difference at this point. So feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/ext4/namei.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 4a47fbd8dd30..8cadaeb15b2b 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -3054,7 +3054,7 @@ static struct dentry *ext4_mkdir(struct mnt_idmap *idmap, struct inode *dir,
> out_retry:
> if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
> goto retry;
> - return ERR_PTR(err);
> + return err ? ERR_PTR(err) : NULL;
> }
>
> /*
> --
> 2.25.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ext4: Fix ERR_PTR(0) in ext4_mkdir()
2026-05-20 7:46 [PATCH] ext4: Fix ERR_PTR(0) in ext4_mkdir() Hongling Zeng
2026-05-20 8:42 ` Jan Kara
@ 2026-05-20 9:19 ` Zhang Yi
2026-05-20 9:33 ` Hongling Zeng
1 sibling, 1 reply; 4+ messages in thread
From: Zhang Yi @ 2026-05-20 9:19 UTC (permalink / raw)
To: Hongling Zeng, tytso, adilger.kernel, libaokun, jack, ojaswin,
ritesh.list, neil, brauner, jlayton
Cc: linux-ext4, linux-kernel, zhongling0719
On 5/20/2026 3:46 PM, Hongling Zeng wrote:
> When mkdir succeeds, ext4_mkdir() returns ERR_PTR(0) which is incorrect.
> It should return NULL instead for success and ERR_PTR() only with
> negative error codes for failure.
This point is indeed very easy to overlook. However, why not modify
other file systems as well? Commit 88d5baf69082 made changes not only
to ext4.
Thanks,
Yi.
>
> Fixes: 88d5baf69082 ("Change inode_operations.mkdir to return struct dentry *")
> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
> ---
> fs/ext4/namei.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 4a47fbd8dd30..8cadaeb15b2b 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -3054,7 +3054,7 @@ static struct dentry *ext4_mkdir(struct mnt_idmap *idmap, struct inode *dir,
> out_retry:
> if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
> goto retry;
> - return ERR_PTR(err);
> + return err ? ERR_PTR(err) : NULL;
> }
>
> /*
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ext4: Fix ERR_PTR(0) in ext4_mkdir()
2026-05-20 9:19 ` Zhang Yi
@ 2026-05-20 9:33 ` Hongling Zeng
0 siblings, 0 replies; 4+ messages in thread
From: Hongling Zeng @ 2026-05-20 9:33 UTC (permalink / raw)
To: Zhang Yi, Hongling Zeng, tytso, adilger.kernel, libaokun, jack,
ojaswin, ritesh.list, neil, brauner, jlayton
Cc: linux-ext4, linux-kernel
Hi ,
Good point! I've been systematically fixing this across filesystems.
Several fixes have already been merged (9p, jfs, orangefs,cachefiles....)
Still working on a few more filesystems.
Thanks for the suggestion!
Best regards,
Hongling
在 2026年05月20日 17:19, Zhang Yi 写道:
> On 5/20/2026 3:46 PM, Hongling Zeng wrote:
>> When mkdir succeeds, ext4_mkdir() returns ERR_PTR(0) which is incorrect.
>> It should return NULL instead for success and ERR_PTR() only with
>> negative error codes for failure.
> This point is indeed very easy to overlook. However, why not modify
> other file systems as well? Commit 88d5baf69082 made changes not only
> to ext4.
>
> Thanks,
> Yi.
>
>> Fixes: 88d5baf69082 ("Change inode_operations.mkdir to return struct dentry *")
>> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
>> ---
>> fs/ext4/namei.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
>> index 4a47fbd8dd30..8cadaeb15b2b 100644
>> --- a/fs/ext4/namei.c
>> +++ b/fs/ext4/namei.c
>> @@ -3054,7 +3054,7 @@ static struct dentry *ext4_mkdir(struct mnt_idmap *idmap, struct inode *dir,
>> out_retry:
>> if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
>> goto retry;
>> - return ERR_PTR(err);
>> + return err ? ERR_PTR(err) : NULL;
>> }
>>
>> /*
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-20 9:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-20 7:46 [PATCH] ext4: Fix ERR_PTR(0) in ext4_mkdir() Hongling Zeng
2026-05-20 8:42 ` Jan Kara
2026-05-20 9:19 ` Zhang Yi
2026-05-20 9:33 ` Hongling Zeng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox