* [PATCH v1] mm, vmpressure: Convert to use match_string() helper
@ 2018-05-03 20:32 Andy Shevchenko
2018-05-04 14:30 ` Michal Hocko
0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2018-05-03 20:32 UTC (permalink / raw)
To: David Rientjes, linux-mm, Andrew Morton; +Cc: Andy Shevchenko
The new helper returns index of the matching string in an array.
We are going to use it here.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
mm/vmpressure.c | 32 ++++++--------------------------
1 file changed, 6 insertions(+), 26 deletions(-)
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 7142207224d3..4854584ec436 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -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)
/**
@@ -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;
}
}
--
2.17.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] mm, vmpressure: Convert to use match_string() helper
2018-05-03 20:32 [PATCH v1] mm, vmpressure: Convert to use match_string() helper Andy Shevchenko
@ 2018-05-04 14:30 ` Michal Hocko
0 siblings, 0 replies; 2+ messages in thread
From: Michal Hocko @ 2018-05-04 14:30 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: David Rientjes, linux-mm, Andrew Morton
On Thu 03-05-18 23:32:06, Andy Shevchenko wrote:
> The new helper returns index of the matching string in an array.
> We are going to use it here.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> mm/vmpressure.c | 32 ++++++--------------------------
> 1 file changed, 6 insertions(+), 26 deletions(-)
>
> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> index 7142207224d3..4854584ec436 100644
> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -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)
>
> /**
> @@ -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;
> }
> }
> --
> 2.17.0
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-04 14:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-03 20:32 [PATCH v1] mm, vmpressure: Convert to use match_string() helper Andy Shevchenko
2018-05-04 14:30 ` Michal Hocko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.