Skip to content

Commit d421f5a

Browse files
npz7yykUlrich Hecht
authored andcommitted
fs/hpfs: Fix error code for new_inode() failure in mkdir/create/mknod/symlink
[ Upstream commit 32058c38d3b79a28963a59ac0353644dc24775cd ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Ulrich Hecht <uli@kernel.org>
1 parent e611f45 commit d421f5a

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

fs/hpfs/namei.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
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;
@@ -154,9 +156,10 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, b
154156
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
155157

156158
result = new_inode(dir->i_sb);
157-
if (!result)
159+
if (!result) {
160+
err = -ENOMEM;
158161
goto bail1;
159-
162+
}
160163
hpfs_init_inode(result);
161164
result->i_ino = fno;
162165
result->i_mode |= S_IFREG;
@@ -241,9 +244,10 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, de
241244
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
242245

243246
result = new_inode(dir->i_sb);
244-
if (!result)
247+
if (!result) {
248+
err = -ENOMEM;
245249
goto bail1;
246-
250+
}
247251
hpfs_init_inode(result);
248252
result->i_ino = fno;
249253
hpfs_i(result)->i_parent_dir = dir->i_ino;
@@ -317,8 +321,10 @@ static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *sy
317321
dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb));
318322

319323
result = new_inode(dir->i_sb);
320-
if (!result)
324+
if (!result) {
325+
err = -ENOMEM;
321326
goto bail1;
327+
}
322328
result->i_ino = fno;
323329
hpfs_init_inode(result);
324330
hpfs_i(result)->i_parent_dir = dir->i_ino;

0 commit comments

Comments
 (0)