Skip to content

Commit 32058c3

Browse files
npz7yykMikulas Patocka
authored andcommitted
fs/hpfs: Fix error code for new_inode() failure in mkdir/create/mknod/symlink
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> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent fd8a620 commit 32058c3

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

fs/hpfs/namei.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ static struct dentry *hpfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
5252
dee.fnode = cpu_to_le32(fno);
5353
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
5454
result = new_inode(dir->i_sb);
55-
if (!result)
55+
if (!result) {
56+
err = -ENOMEM;
5657
goto bail2;
58+
}
5759
hpfs_init_inode(result);
5860
result->i_ino = fno;
5961
hpfs_i(result)->i_parent_dir = dir->i_ino;
@@ -153,9 +155,10 @@ static int hpfs_create(struct mnt_idmap *idmap, struct inode *dir,
153155
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
154156

155157
result = new_inode(dir->i_sb);
156-
if (!result)
158+
if (!result) {
159+
err = -ENOMEM;
157160
goto bail1;
158-
161+
}
159162
hpfs_init_inode(result);
160163
result->i_ino = fno;
161164
result->i_mode |= S_IFREG;
@@ -239,9 +242,10 @@ static int hpfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
239242
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
240243

241244
result = new_inode(dir->i_sb);
242-
if (!result)
245+
if (!result) {
246+
err = -ENOMEM;
243247
goto bail1;
244-
248+
}
245249
hpfs_init_inode(result);
246250
result->i_ino = fno;
247251
hpfs_i(result)->i_parent_dir = dir->i_ino;
@@ -314,8 +318,10 @@ static int hpfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
314318
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
315319

316320
result = new_inode(dir->i_sb);
317-
if (!result)
321+
if (!result) {
322+
err = -ENOMEM;
318323
goto bail1;
324+
}
319325
result->i_ino = fno;
320326
hpfs_init_inode(result);
321327
hpfs_i(result)->i_parent_dir = dir->i_ino;

0 commit comments

Comments
 (0)