Skip to content

Commit

Permalink
mm/vmpressure.c: convert to use match_string() helper
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: Andy Shevchenko <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: David Rientjes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
andy-shev authored and torvalds committed Jun 8, 2018
1 parent d62ff36 commit 3cadfa2
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions mm/vmpressure.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,26 +342,6 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
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)

/**
Expand Down Expand Up @@ -398,18 +378,18 @@ int vmpressure_register_event(struct mem_cgroup *memcg,

/* Find required level */
token = strsep(&spec, ",");
level = str_to_level(token);
if (level == -1) {
ret = -EINVAL;
level = match_string(vmpressure_str_levels, VMPRESSURE_NUM_LEVELS, token);
if (level < 0) {
ret = level;
goto out;
}

/* Find optional mode */
token = strsep(&spec, ",");
if (token) {
mode = str_to_mode(token);
if (mode == -1) {
ret = -EINVAL;
mode = match_string(vmpressure_str_modes, VMPRESSURE_NUM_MODES, token);
if (mode < 0) {
ret = mode;
goto out;
}
}
Expand Down

0 comments on commit 3cadfa2

Please sign in to comment.