diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2017-10-31 18:15:30 -0400 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2017-10-31 18:23:13 -0400 |
commit | 3fda0e737e906ce73220b20c27e7f792d0aac6a8 (patch) | |
tree | b6fb2ec20b3028ad70578aa3b73a1a52d3e3daf5 | |
parent | ece66133979b211324cc6aff9285889b425243d2 (diff) |
userns: Simplify insert_extent
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@xmission.com>
-rw-r--r-- | kernel/user_namespace.c | 19 |
1 files 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, | |||
758 | */ | 758 | */ |
759 | static int insert_extent(struct uid_gid_map *map, struct uid_gid_extent *extent) | 759 | static int insert_extent(struct uid_gid_map *map, struct uid_gid_extent *extent) |
760 | { | 760 | { |
761 | if (map->nr_extents < UID_GID_MAP_MAX_BASE_EXTENTS) { | 761 | struct uid_gid_extent *dest; |
762 | map->extent[map->nr_extents].first = extent->first; | ||
763 | map->extent[map->nr_extents].lower_first = extent->lower_first; | ||
764 | map->extent[map->nr_extents].count = extent->count; | ||
765 | return 0; | ||
766 | } | ||
767 | 762 | ||
768 | if (map->nr_extents == UID_GID_MAP_MAX_BASE_EXTENTS) { | 763 | if (map->nr_extents == UID_GID_MAP_MAX_BASE_EXTENTS) { |
769 | struct uid_gid_extent *forward; | 764 | struct uid_gid_extent *forward; |
@@ -784,9 +779,13 @@ static int insert_extent(struct uid_gid_map *map, struct uid_gid_extent *extent) | |||
784 | map->reverse = NULL; | 779 | map->reverse = NULL; |
785 | } | 780 | } |
786 | 781 | ||
787 | map->forward[map->nr_extents].first = extent->first; | 782 | if (map->nr_extents < UID_GID_MAP_MAX_BASE_EXTENTS) |
788 | map->forward[map->nr_extents].lower_first = extent->lower_first; | 783 | dest = &map->extent[map->nr_extents]; |
789 | map->forward[map->nr_extents].count = extent->count; | 784 | else |
785 | dest = &map->forward[map->nr_extents]; | ||
786 | |||
787 | *dest = *extent; | ||
788 | map->nr_extents++; | ||
790 | return 0; | 789 | return 0; |
791 | } | 790 | } |
792 | 791 | ||
@@ -968,8 +967,6 @@ static ssize_t map_write(struct file *file, const char __user *buf, | |||
968 | if (ret < 0) | 967 | if (ret < 0) |
969 | goto out; | 968 | goto out; |
970 | ret = -EINVAL; | 969 | ret = -EINVAL; |
971 | |||
972 | new_map.nr_extents++; | ||
973 | } | 970 | } |
974 | /* Be very certaint the new map actually exists */ | 971 | /* Be very certaint the new map actually exists */ |
975 | if (new_map.nr_extents == 0) | 972 | if (new_map.nr_extents == 0) |