mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
To: "Eric W. Biederman" <ebiederm@xmission.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
	Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Subject: [PATCH] userns: simplify map_id_range_* functions
Date: Sun, 26 Jul 2015 09:50:32 +0800	[thread overview]
Message-ID: <1437875432-15502-1-git-send-email-nicolas.iooss_linux@m4x.org> (raw)

Functions map_id_range_down, map_id_down and map_id_up all used the
construction:

    if (...)
        id = ...
    else
        id = ...
    return id;

which can be simplified by directly returning the result of the
computations in each branch.

Moreover as the condition tested whether the "break;" in the previous
for loop was hit, it is simpler to directly compute the result and
return it.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
---

As I could not find any relevant entry for kernel/user_namespace.c in
MAINTAINERS, I have built the list of recipients from the git history.
Please let me know if I was expected to proceed differently to submit
this patch.

 kernel/user_namespace.c | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 4109f8320684..bf063dc6b8d4 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -165,15 +165,10 @@ static u32 map_id_range_down(struct uid_gid_map *map, u32 id, u32 count)
 		last = first + map->extent[idx].count - 1;
 		if (id >= first && id <= last &&
 		    (id2 >= first && id2 <= last))
-			break;
+			return (id - first) + map->extent[idx].lower_first;
 	}
-	/* Map the id or note failure */
-	if (idx < extents)
-		id = (id - first) + map->extent[idx].lower_first;
-	else
-		id = (u32) -1;
-
-	return id;
+	/* Note failure */
+	return (u32) -1;
 }
 
 static u32 map_id_down(struct uid_gid_map *map, u32 id)
@@ -188,15 +183,9 @@ static u32 map_id_down(struct uid_gid_map *map, u32 id)
 		first = map->extent[idx].first;
 		last = first + map->extent[idx].count - 1;
 		if (id >= first && id <= last)
-			break;
+			return (id - first) + map->extent[idx].lower_first;
 	}
-	/* Map the id or note failure */
-	if (idx < extents)
-		id = (id - first) + map->extent[idx].lower_first;
-	else
-		id = (u32) -1;
-
-	return id;
+	return (u32) -1;
 }
 
 static u32 map_id_up(struct uid_gid_map *map, u32 id)
@@ -211,15 +200,9 @@ static u32 map_id_up(struct uid_gid_map *map, u32 id)
 		first = map->extent[idx].lower_first;
 		last = first + map->extent[idx].count - 1;
 		if (id >= first && id <= last)
-			break;
+			return (id - first) + map->extent[idx].first;
 	}
-	/* Map the id or note failure */
-	if (idx < extents)
-		id = (id - first) + map->extent[idx].first;
-	else
-		id = (u32) -1;
-
-	return id;
+	return (u32) -1;
 }
 
 /**
-- 
2.4.6


             reply	other threads:[~2015-07-26  2:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-26  1:50 Nicolas Iooss [this message]
2015-07-27  4:29 ` Eric W. Biederman
2015-07-27 12:59   ` Nicolas Iooss
2015-07-27 18:04     ` 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=1437875432-15502-1-git-send-email-nicolas.iooss_linux@m4x.org \
    --to=nicolas.iooss_linux@m4x.org \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®