ALSA: hda: Initialize power_state field properly
[platform/kernel/linux-rpi.git] / kernel / user_namespace.c
index c3d7583..923414a 100644 (file)
@@ -859,7 +859,16 @@ static ssize_t map_write(struct file *file, const char __user *buf,
        unsigned idx;
        struct uid_gid_extent extent;
        char *kbuf = NULL, *pos, *next_line;
-       ssize_t ret = -EINVAL;
+       ssize_t ret;
+
+       /* Only allow < page size writes at the beginning of the file */
+       if ((*ppos != 0) || (count >= PAGE_SIZE))
+               return -EINVAL;
+
+       /* Slurp in the user data */
+       kbuf = memdup_user_nul(buf, count);
+       if (IS_ERR(kbuf))
+               return PTR_ERR(kbuf);
 
        /*
         * The userns_state_mutex serializes all writes to any given map.
@@ -895,19 +904,6 @@ static ssize_t map_write(struct file *file, const char __user *buf,
        if (cap_valid(cap_setid) && !file_ns_capable(file, ns, CAP_SYS_ADMIN))
                goto out;
 
-       /* Only allow < page size writes at the beginning of the file */
-       ret = -EINVAL;
-       if ((*ppos != 0) || (count >= PAGE_SIZE))
-               goto out;
-
-       /* Slurp in the user data */
-       kbuf = memdup_user_nul(buf, count);
-       if (IS_ERR(kbuf)) {
-               ret = PTR_ERR(kbuf);
-               kbuf = NULL;
-               goto out;
-       }
-
        /* Parse the user data */
        ret = -EINVAL;
        pos = kbuf;
@@ -978,10 +974,6 @@ static ssize_t map_write(struct file *file, const char __user *buf,
        if (!new_idmap_permitted(file, ns, cap_setid, &new_map))
                goto out;
 
-       ret = sort_idmaps(&new_map);
-       if (ret < 0)
-               goto out;
-
        ret = -EPERM;
        /* Map the lower ids from the parent user namespace to the
         * kernel global id space.
@@ -1008,6 +1000,14 @@ static ssize_t map_write(struct file *file, const char __user *buf,
                e->lower_first = lower_first;
        }
 
+       /*
+        * If we want to use binary search for lookup, this clones the extent
+        * array and sorts both copies.
+        */
+       ret = sort_idmaps(&new_map);
+       if (ret < 0)
+               goto out;
+
        /* Install the map */
        if (new_map.nr_extents <= UID_GID_MAP_MAX_BASE_EXTENTS) {
                memcpy(map->extent, new_map.extent,