Commit 3cadfa2b authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Linus Torvalds

mm/vmpressure.c: convert to use match_string() helper

The new helper returns index of the matching string in an array.  We are
going to use it here.

Link: http://lkml.kernel.org/r/20180503203206.44046-1-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d62ff365
...@@ -342,26 +342,6 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio) ...@@ -342,26 +342,6 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
vmpressure(gfp, memcg, true, vmpressure_win, 0); vmpressure(gfp, memcg, true, vmpressure_win, 0);
} }
static enum vmpressure_levels str_to_level(const char *arg)
{
enum vmpressure_levels level;
for (level = 0; level < VMPRESSURE_NUM_LEVELS; level++)
if (!strcmp(vmpressure_str_levels[level], arg))
return level;
return -1;
}
static enum vmpressure_modes str_to_mode(const char *arg)
{
enum vmpressure_modes mode;
for (mode = 0; mode < VMPRESSURE_NUM_MODES; mode++)
if (!strcmp(vmpressure_str_modes[mode], arg))
return mode;
return -1;
}
#define MAX_VMPRESSURE_ARGS_LEN (strlen("critical") + strlen("hierarchy") + 2) #define MAX_VMPRESSURE_ARGS_LEN (strlen("critical") + strlen("hierarchy") + 2)
/** /**
...@@ -398,18 +378,18 @@ int vmpressure_register_event(struct mem_cgroup *memcg, ...@@ -398,18 +378,18 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
/* Find required level */ /* Find required level */
token = strsep(&spec, ","); token = strsep(&spec, ",");
level = str_to_level(token); level = match_string(vmpressure_str_levels, VMPRESSURE_NUM_LEVELS, token);
if (level == -1) { if (level < 0) {
ret = -EINVAL; ret = level;
goto out; goto out;
} }
/* Find optional mode */ /* Find optional mode */
token = strsep(&spec, ","); token = strsep(&spec, ",");
if (token) { if (token) {
mode = str_to_mode(token); mode = match_string(vmpressure_str_modes, VMPRESSURE_NUM_MODES, token);
if (mode == -1) { if (mode < 0) {
ret = -EINVAL; ret = mode;
goto out; goto out;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment