All of lore.kernel.org
 help / color / mirror / Atom feed
From: ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org (Eric W. Biederman)
To: Christian Brauner
	<christian.brauner-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
Cc: Linux Containers
	<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
	tycho-E0fblnxP3wo@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 5/5] userns: Simplify insert_extent
Date: Tue, 31 Oct 2017 18:49:22 -0500	[thread overview]
Message-ID: <878tfqswsd.fsf_-___90.7362126328692$1509493789$gmane$org@xmission.com> (raw)
In-Reply-To: <871sliubhj.fsf_-_-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org> (Eric W. Biederman's message of "Tue, 31 Oct 2017 18:46:32 -0500")


Consolidate the code to write to the new mapping at the end of the
function to remove the duplication.  Move the increase in the number
of mappings into insert_extent, keeping the logic together.

Just a small increase in readability and maintainability.

Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 kernel/user_namespace.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 1d0298870ee3..899c31060ff3 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -758,12 +758,7 @@ static bool mappings_overlap(struct uid_gid_map *new_map,
  */
 static int insert_extent(struct uid_gid_map *map, struct uid_gid_extent *extent)
 {
-	if (map->nr_extents < UID_GID_MAP_MAX_BASE_EXTENTS) {
-		map->extent[map->nr_extents].first = extent->first;
-		map->extent[map->nr_extents].lower_first = extent->lower_first;
-		map->extent[map->nr_extents].count = extent->count;
-		return 0;
-	}
+	struct uid_gid_extent *dest;
 
 	if (map->nr_extents == UID_GID_MAP_MAX_BASE_EXTENTS) {
 		struct uid_gid_extent *forward;
@@ -784,9 +779,13 @@ static int insert_extent(struct uid_gid_map *map, struct uid_gid_extent *extent)
 		map->reverse = NULL;
 	}
 
-	map->forward[map->nr_extents].first = extent->first;
-	map->forward[map->nr_extents].lower_first = extent->lower_first;
-	map->forward[map->nr_extents].count = extent->count;
+	if (map->nr_extents < UID_GID_MAP_MAX_BASE_EXTENTS)
+		dest = &map->extent[map->nr_extents];
+	else
+		dest = &map->forward[map->nr_extents];
+
+	*dest = *extent;
+	map->nr_extents++;
 	return 0;
 }
 
@@ -968,8 +967,6 @@ static ssize_t map_write(struct file *file, const char __user *buf,
 		if (ret < 0)
 			goto out;
 		ret = -EINVAL;
-
-		new_map.nr_extents++;
 	}
 	/* Be very certaint the new map actually exists */
 	if (new_map.nr_extents == 0)
-- 
2.14.1

  parent reply	other threads:[~2017-10-31 23:49 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-24 22:04 [PATCH 1/2 v6] user namespace: use union in {g,u}idmap struct Christian Brauner
2017-10-24 22:04 ` [PATCH 2/2 v6] user namespaces: bump idmap limits to 340 Christian Brauner
     [not found]   ` <20171024220441.10235-2-christian.brauner-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2017-10-31 23:46     ` [PATCH 0/5] userns: bump idmap limits, fixes & tweaks Eric W. Biederman
2017-10-31 23:46   ` Eric W. Biederman
2017-10-31 23:47     ` [PATCH 1/5] userns: Don't special case a count of 0 Eric W. Biederman
2017-10-31 23:47     ` [PATCH 2/5] userns: Simplify the user and group mapping functions Eric W. Biederman
2017-10-31 23:48     ` [PATCH 3/5] userns: Don't read extents twice in m_start Eric W. Biederman
2017-11-01  8:31       ` Nikolay Borisov
2017-11-01 11:08         ` Eric W. Biederman
     [not found]           ` <87a806ntn0.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-11-01 13:05             ` Nikolay Borisov
2017-11-01 13:05             ` Peter Zijlstra
2017-11-01 17:00             ` Joe Perches
2017-11-01 13:05           ` Nikolay Borisov
2017-11-01 13:05           ` Peter Zijlstra
2017-11-01 16:31             ` Christian Brauner
     [not found]             ` <20171101130539.j5bxmhs2trqurrr2-Nxj+rRp3nVydTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2017-11-01 14:01               ` Christian Brauner
2017-11-01 14:01                 ` Christian Brauner
     [not found]                 ` <20171101140144.zwe7cq7iv2xudwp4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-11-01 14:16                   ` Peter Zijlstra
2017-11-01 14:16                     ` Peter Zijlstra
     [not found]                     ` <20171101141654.fr4rs2m5cygouktb-Nxj+rRp3nVydTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2017-11-01 16:29                       ` Christian Brauner
2017-11-01 16:29                         ` Christian Brauner
2017-11-01 16:31               ` Christian Brauner
2017-11-01 17:00           ` Joe Perches
     [not found]             ` <1509555601.31043.44.camel-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
2017-11-01 17:20               ` Eric W. Biederman
2017-11-01 17:20             ` Eric W. Biederman
     [not found]               ` <87h8udj4p7.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-11-01 18:15                 ` Peter Zijlstra
2017-11-01 18:15                   ` Peter Zijlstra
     [not found]         ` <143adb61-fb8e-fc1b-396b-b18836e68766-IBi9RG/b67k@public.gmane.org>
2017-11-01 11:08           ` Eric W. Biederman
     [not found]       ` <87k1zaswu6.fsf_-_-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-11-01  8:31         ` Nikolay Borisov
2017-10-31 23:48     ` [PATCH 4/5] userns: Make map_id_down a wrapper for map_id_range_down Eric W. Biederman
     [not found]     ` <871sliubhj.fsf_-_-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-10-31 23:47       ` [PATCH 1/5] userns: Don't special case a count of 0 Eric W. Biederman
2017-10-31 23:47       ` [PATCH 2/5] userns: Simplify the user and group mapping functions Eric W. Biederman
2017-10-31 23:48       ` [PATCH 3/5] userns: Don't read extents twice in m_start Eric W. Biederman
2017-10-31 23:48       ` [PATCH 4/5] userns: Make map_id_down a wrapper for map_id_range_down Eric W. Biederman
2017-10-31 23:49       ` Eric W. Biederman [this message]
2017-11-01 10:51       ` [PATCH 0/5] userns: bump idmap limits, fixes & tweaks Christian Brauner
2017-10-31 23:49     ` [PATCH 5/5] userns: Simplify insert_extent Eric W. Biederman
2017-11-01 10:51     ` [PATCH 0/5] userns: bump idmap limits, fixes & tweaks Christian Brauner
2017-11-01 11:15       ` Eric W. Biederman
     [not found]         ` <87tvyemeqe.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-11-01 13:31           ` Christian Brauner
2017-11-01 13:31             ` Christian Brauner
     [not found]       ` <CAPP7u0WDVv0pAAFEuzL2c9Y-wVg0xG36jyH-eok=GV-r6UewZg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-11-01 11:15         ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='878tfqswsd.fsf_-___90.7362126328692$1509493789$gmane$org@xmission.com' \
    --to=ebiederm-as9lmozglivwk0htik3j/w@public.gmane.org \
    --cc=christian.brauner-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=tycho-E0fblnxP3wo@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.