affs: kstrdup() memory handling
authorSanidhya Kashyap <sanidhya.gatech@gmail.com>
Thu, 16 Apr 2015 19:48:26 +0000 (12:48 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 17 Apr 2015 13:04:09 +0000 (09:04 -0400)
There is a possibility of kstrdup() failure upon memory pressure.
Therefore, returning ENOMEM even for new_opts.

[akpm@linux-foundation.org: cleanup]
Signed-off-by: Sanidhya Kashyap <sanidhya.gatech@gmail.com>
Cc: Taesoo kim <taesoo@gatech.edu>
Cc: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/affs/super.c

index 6819d0426af58565b86ea8b729f2f2e2f79acc7d..3f89c9e05b4077b5db9b728435713d04d5ed05ae 100644 (file)
@@ -521,10 +521,14 @@ affs_remount(struct super_block *sb, int *flags, char *data)
        int                      root_block;
        unsigned long            mount_flags;
        int                      res = 0;
-       char                    *new_opts = kstrdup(data, GFP_KERNEL);
+       char                    *new_opts;
        char                     volume[32];
        char                    *prefix = NULL;
 
+       new_opts = kstrdup(data, GFP_KERNEL);
+       if (!new_opts)
+               return -ENOMEM;
+
        pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data);
 
        sync_filesystem(sb);