]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - fs/ext2/ioctl.c
ext2: return error when fail to allocating memory in ioctl
[linux.git] / fs / ext2 / ioctl.c
index 0367c0039e68fd7ef25e102d3e0b2ab85f198132..32a8d10b579df71a75ee13b645ece202e167d908 100644 (file)
@@ -60,18 +60,10 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                }
                oldflags = ei->i_flags;
 
-               /*
-                * The IMMUTABLE and APPEND_ONLY flags can only be changed by
-                * the relevant capability.
-                *
-                * This test looks nicer. Thanks to Pauline Middelink
-                */
-               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
-                       if (!capable(CAP_LINUX_IMMUTABLE)) {
-                               inode_unlock(inode);
-                               ret = -EPERM;
-                               goto setflags_out;
-                       }
+               ret = vfs_ioc_setflags_prepare(inode, oldflags, flags);
+               if (ret) {
+                       inode_unlock(inode);
+                       goto setflags_out;
                }
 
                flags = flags & EXT2_FL_USER_MODIFIABLE;
@@ -153,10 +145,13 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                if (ei->i_block_alloc_info){
                        struct ext2_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node;
                        rsv->rsv_goal_size = rsv_window_size;
+               } else {
+                       ret = -ENOMEM;
                }
+
                mutex_unlock(&ei->truncate_mutex);
                mnt_drop_write_file(filp);
-               return 0;
+               return ret;
        }
        default:
                return -ENOTTY;