* [PATCH] fs/hpfs: Fix error code for new_inode() failure in mkdir/create/mknod/symlink
@ 2025-05-04 1:44 yikangy2
2025-05-04 3:23 ` Al Viro
0 siblings, 1 reply; 3+ messages in thread
From: yikangy2 @ 2025-05-04 1:44 UTC (permalink / raw)
To: mikulas; +Cc: linux-kernel, yikangy2, shaobol2, yiruiz2, jianh
From: Yikang Yue <yikangy2@illinois.edu>
The function call new_inode() is a primitive for allocating an inode in memory,
rather than planning disk space for it. Therefore, -ENOMEM should be returned
as the error code rather than -ENOSPC.
To be specific, new_inode()'s call path looks like this:
new_inode
new_inode_pseudo
alloc_inode
ops->alloc_inode (hpfs_alloc_inode)
alloc_inode_sb
kmem_cache_alloc_lru
Therefore, the failure of new_inode() indicates a memory presure issue (-ENOMEM),
not a lack of disk space. However, the current implementation of
hpfs_mkdir/create/mknod/symlink incorrectly returns -ENOSPC when new_inode() fails.
This patch fix this by set err to -ENOMEM before the goto statement.
BTW, we also noticed that other nested calls within these four functions,
like hpfs_alloc_f/dnode and hpfs_add_dirent, might also fail due to memory presure.
But similarly, only -ENOSPC is returned. Addressing these will involve code
modifications in other functions, and we plan to submit dedicated patches for these
issues in the future. For this patch, we focus on new_inode().
Signed-off-by: Yikang Yue <yikangy2@illinois.edu>
---
fs/hpfs/namei.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/fs/hpfs/namei.c b/fs/hpfs/namei.c
index e3cdc421dfba..353e13a615f5 100644
--- a/fs/hpfs/namei.c
+++ b/fs/hpfs/namei.c
@@ -52,8 +52,10 @@ static struct dentry *hpfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
dee.fnode = cpu_to_le32(fno);
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
result = new_inode(dir->i_sb);
- if (!result)
+ if (!result) {
+ err = -ENOMEM;
goto bail2;
+ }
hpfs_init_inode(result);
result->i_ino = fno;
hpfs_i(result)->i_parent_dir = dir->i_ino;
@@ -153,9 +155,10 @@ static int hpfs_create(struct mnt_idmap *idmap, struct inode *dir,
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
result = new_inode(dir->i_sb);
- if (!result)
+ if (!result) {
+ err = -ENOMEM;
goto bail1;
-
+ }
hpfs_init_inode(result);
result->i_ino = fno;
result->i_mode |= S_IFREG;
@@ -239,9 +242,10 @@ static int hpfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
result = new_inode(dir->i_sb);
- if (!result)
+ if (!result) {
+ err = -ENOMEM;
goto bail1;
-
+ }
hpfs_init_inode(result);
result->i_ino = fno;
hpfs_i(result)->i_parent_dir = dir->i_ino;
@@ -314,8 +318,10 @@ static int hpfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
result = new_inode(dir->i_sb);
- if (!result)
+ if (!result) {
+ err = -ENOMEM;
goto bail1;
+ }
result->i_ino = fno;
hpfs_init_inode(result);
hpfs_i(result)->i_parent_dir = dir->i_ino;
--
2.46.0.windows.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] fs/hpfs: Fix error code for new_inode() failure in mkdir/create/mknod/symlink
2025-05-04 1:44 [PATCH] fs/hpfs: Fix error code for new_inode() failure in mkdir/create/mknod/symlink yikangy2
@ 2025-05-04 3:23 ` Al Viro
2025-05-28 21:36 ` Yikang Yue
0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2025-05-04 3:23 UTC (permalink / raw)
To: yikangy2; +Cc: mikulas, linux-kernel, shaobol2, yiruiz2, jianh
On Sat, May 03, 2025 at 08:44:34PM -0500, yikangy2@illinois.edu wrote:
> From: Yikang Yue <yikangy2@illinois.edu>
>
> The function call new_inode() is a primitive for allocating an inode in memory,
> rather than planning disk space for it. Therefore, -ENOMEM should be returned
> as the error code rather than -ENOSPC.
>
> To be specific, new_inode()'s call path looks like this:
> new_inode
> new_inode_pseudo
> alloc_inode
> ops->alloc_inode (hpfs_alloc_inode)
> alloc_inode_sb
> kmem_cache_alloc_lru
>
> Therefore, the failure of new_inode() indicates a memory presure issue (-ENOMEM),
> not a lack of disk space. However, the current implementation of
> hpfs_mkdir/create/mknod/symlink incorrectly returns -ENOSPC when new_inode() fails.
> This patch fix this by set err to -ENOMEM before the goto statement.
>
> BTW, we also noticed that other nested calls within these four functions,
> like hpfs_alloc_f/dnode and hpfs_add_dirent, might also fail due to memory presure.
> But similarly, only -ENOSPC is returned. Addressing these will involve code
> modifications in other functions, and we plan to submit dedicated patches for these
> issues in the future. For this patch, we focus on new_inode().
Frankly, that amount of boilerplate is begging for a helper function...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fs/hpfs: Fix error code for new_inode() failure in mkdir/create/mknod/symlink
2025-05-04 3:23 ` Al Viro
@ 2025-05-28 21:36 ` Yikang Yue
0 siblings, 0 replies; 3+ messages in thread
From: Yikang Yue @ 2025-05-28 21:36 UTC (permalink / raw)
To: viro; +Cc: mikulas, linux-kernel, yikangy2, shaobol2, yiruiz2, jianh
Sorry for the late reply.
On Sun, May 04, 2025 at 03:23:00AM +0000, Al Viro wrote:
> Frankly, that amount of boilerplate is begging for a helper function...
Could you clarify whether you meant:
(1) Simplify the patch we already submitted by introducing
a helper function, or
(2) Simplify the implementations of mkdir/create/mknod/symlink
by extracting a common helper?
For option 1, the current -ENOMEM fix is intentionally minimal,
but we can certainly wrap the logic in something like:
hpfs_new_inode(dir->i_sb, &err);
to conduct the error code assignment within the helper function.
If you had option 2 in mind, our plan would be to
first correct the other similar error-code inconsistencies and
then consider extracting a helper function to reduce duplication.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-28 22:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-04 1:44 [PATCH] fs/hpfs: Fix error code for new_inode() failure in mkdir/create/mknod/symlink yikangy2
2025-05-04 3:23 ` Al Viro
2025-05-28 21:36 ` Yikang Yue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox