ext2: set proper return code

This change “ext2: set proper return code” in Linux kernel is authored by Chengguang Xu <cgxu519 [at] gmx.com> on Tue Jan 1 21:30:28 2019 +0800.

ext2: set proper return code

Set proper return code when failing from allocating
memory in ext2_fill_super().

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
Signed-off-by: Jan Kara <jack@suse.cz>

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit 6a03e6a.

There are 3 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/ext2/super.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 73b2d52..b6d8402 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -1087,12 +1087,14 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 					   sizeof(struct buffer_head *),
 					   GFP_KERNEL);
 	if (sbi->s_group_desc == NULL) {
+		ret = -ENOMEM;
 		ext2_msg(sb, KERN_ERR, "error: not enough memory");
 		goto failed_mount;
 	}
 	bgl_lock_init(sbi->s_blockgroup_lock);
 	sbi->s_debts = kcalloc(sbi->s_groups_count, sizeof(*sbi->s_debts), GFP_KERNEL);
 	if (!sbi->s_debts) {
+		ret = -ENOMEM;
 		ext2_msg(sb, KERN_ERR, "error: not enough memory");
 		goto failed_mount_group_desc;
 	}
@@ -1148,6 +1150,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 #ifdef CONFIG_EXT2_FS_XATTR
 	sbi->s_ea_block_cache = ext2_xattr_create_cache();
 	if (!sbi->s_ea_block_cache) {
+		ret = -ENOMEM;
 		ext2_msg(sb, KERN_ERR, "Failed to create ea_block_cache");
 		goto failed_mount3;
 	}

The commit for this change in Linux stable tree is 6a03e6a (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *