Skip to content

Commit dedf2c7

Browse files
xiongzhongjiangtorvalds
authored andcommitted
mm/mempolicy.c: use match_string() helper to simplify the code
match_string() returns the index of an array for a matching string, which can be used intead of open coded implementation. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: zhong jiang <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Andrea Arcangeli <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent c3df29d commit dedf2c7

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

mm/mempolicy.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,12 +2711,11 @@ static const char * const policy_modes[] =
27112711
int mpol_parse_str(char *str, struct mempolicy **mpol)
27122712
{
27132713
struct mempolicy *new = NULL;
2714-
unsigned short mode;
27152714
unsigned short mode_flags;
27162715
nodemask_t nodes;
27172716
char *nodelist = strchr(str, ':');
27182717
char *flags = strchr(str, '=');
2719-
int err = 1;
2718+
int err = 1, mode;
27202719

27212720
if (nodelist) {
27222721
/* NUL-terminate mode or flags string */
@@ -2731,12 +2730,8 @@ int mpol_parse_str(char *str, struct mempolicy **mpol)
27312730
if (flags)
27322731
*flags++ = '\0'; /* terminate mode string */
27332732

2734-
for (mode = 0; mode < MPOL_MAX; mode++) {
2735-
if (!strcmp(str, policy_modes[mode])) {
2736-
break;
2737-
}
2738-
}
2739-
if (mode >= MPOL_MAX)
2733+
mode = match_string(policy_modes, MPOL_MAX, str);
2734+
if (mode < 0)
27402735
goto out;
27412736

27422737
switch (mode) {

0 commit comments

Comments
 (0)