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/1536988365-50310-1-git-send-email-zhongjiang@huawei.com Signed-off-by: zhong jiang <zhongjiang@huawei.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
c3df29d130
commit
dedf2c73b8
|
@ -2711,12 +2711,11 @@ static const char * const policy_modes[] =
|
||||||
int mpol_parse_str(char *str, struct mempolicy **mpol)
|
int mpol_parse_str(char *str, struct mempolicy **mpol)
|
||||||
{
|
{
|
||||||
struct mempolicy *new = NULL;
|
struct mempolicy *new = NULL;
|
||||||
unsigned short mode;
|
|
||||||
unsigned short mode_flags;
|
unsigned short mode_flags;
|
||||||
nodemask_t nodes;
|
nodemask_t nodes;
|
||||||
char *nodelist = strchr(str, ':');
|
char *nodelist = strchr(str, ':');
|
||||||
char *flags = strchr(str, '=');
|
char *flags = strchr(str, '=');
|
||||||
int err = 1;
|
int err = 1, mode;
|
||||||
|
|
||||||
if (nodelist) {
|
if (nodelist) {
|
||||||
/* NUL-terminate mode or flags string */
|
/* NUL-terminate mode or flags string */
|
||||||
|
@ -2731,12 +2730,8 @@ int mpol_parse_str(char *str, struct mempolicy **mpol)
|
||||||
if (flags)
|
if (flags)
|
||||||
*flags++ = '\0'; /* terminate mode string */
|
*flags++ = '\0'; /* terminate mode string */
|
||||||
|
|
||||||
for (mode = 0; mode < MPOL_MAX; mode++) {
|
mode = match_string(policy_modes, MPOL_MAX, str);
|
||||||
if (!strcmp(str, policy_modes[mode])) {
|
if (mode < 0)
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mode >= MPOL_MAX)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
Loading…
Reference in New Issue