From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964897AbbGZCBh (ORCPT ); Sat, 25 Jul 2015 22:01:37 -0400 Received: from mx1.polytechnique.org ([129.104.30.34]:43793 "EHLO mx1.polytechnique.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964816AbbGZCBg (ORCPT ); Sat, 25 Jul 2015 22:01:36 -0400 X-Greylist: delayed 494 seconds by postgrey-1.27 at vger.kernel.org; Sat, 25 Jul 2015 22:01:35 EDT From: Nicolas Iooss To: "Eric W. Biederman" , Andy Lutomirski , Andrew Morton Cc: linux-kernel@vger.kernel.org, Nicolas Iooss Subject: [PATCH] userns: simplify map_id_range_* functions Date: Sun, 26 Jul 2015 09:50:32 +0800 Message-Id: <1437875432-15502-1-git-send-email-nicolas.iooss_linux@m4x.org> X-Mailer: git-send-email 2.4.6 X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Sun Jul 26 03:53:19 2015 +0200 (CEST)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.000552, queueID=9DC5B140912F7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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