Skip to content

Commit

Permalink
mm/mempolicy.c: use match_string() helper to simplify the code
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
xiongzhongjiang authored and torvalds committed Oct 26, 2018
1 parent c3df29d commit dedf2c7
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions mm/mempolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2711,12 +2711,11 @@ static const char * const policy_modes[] =
int mpol_parse_str(char *str, struct mempolicy **mpol)
{
struct mempolicy *new = NULL;
unsigned short mode;
unsigned short mode_flags;
nodemask_t nodes;
char *nodelist = strchr(str, ':');
char *flags = strchr(str, '=');
int err = 1;
int err = 1, mode;

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

for (mode = 0; mode < MPOL_MAX; mode++) {
if (!strcmp(str, policy_modes[mode])) {
break;
}
}
if (mode >= MPOL_MAX)
mode = match_string(policy_modes, MPOL_MAX, str);
if (mode < 0)
goto out;

switch (mode) {
Expand Down

0 comments on commit dedf2c7

Please sign in to comment.