remove better-error-handling-for-kstrdup-failures
[ext4-patch-queue.git] / better-error-handling-for-kstrdup-failures
blob75cb3af00793d44d251d80d93131f2b6bd771e90
1 ext4: better error handling for kstrdup() failures
3 From: Taesoo Kim <tsgatesv@gmail.com>
5 Upon memory pressure, kstrdup() might fail and correctly
6 handle memory error, although current implementation do not
7 refer orig_data.
9 NOTE: fortunately the correct impl works, other than a corner case
10 where kstrdup() fails and kzalloc() succeeds; it might record 'NULL'
11 in the log.
13 Signed-off-by: Taesoo Kim <tsgatesv@gmail.com>
14 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
15 ---
16  fs/ext4/super.c | 8 +++++++-
17  1 file changed, 7 insertions(+), 1 deletion(-)
19 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
20 index e061e66..e2a609c 100644
21 --- a/fs/ext4/super.c
22 +++ b/fs/ext4/super.c
23 @@ -3408,7 +3408,7 @@ static int ext4_reserve_clusters(struct ext4_sb_info *sbi, ext4_fsblk_t count)
25  static int ext4_fill_super(struct super_block *sb, void *data, int silent)
26  {
27 -       char *orig_data = kstrdup(data, GFP_KERNEL);
28 +       char *orig_data;
29         struct buffer_head *bh;
30         struct ext4_super_block *es = NULL;
31         struct ext4_sb_info *sbi;
32 @@ -3431,6 +3431,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
33         unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
34         ext4_group_t first_not_zeroed;
36 +       orig_data = kstrdup(data, GFP_KERNEL);
37 +       if (!orig_data)
38 +               return -ENOMEM;
40         sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
41         if (!sbi)
42                 goto out_free_orig;
43 @@ -4843,6 +4847,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
44         int i, j;
45  #endif
46         char *orig_data = kstrdup(data, GFP_KERNEL);
47 +       if (!orig_data)
48 +               return -ENOMEM;
50         /* Store the original options */
51         old_sb_flags = sb->s_flags;
53 2.3.3