Skip to content

Commit

Permalink
mm/vmpressure.c: fix a signedness bug in vmpressure_register_event()
Browse files Browse the repository at this point in the history
The "mode" and "level" variables are enums and in this context GCC will
treat them as unsigned ints so the error handling is never triggered.

I also removed the bogus initializer because it isn't required any more
and it's sort of confusing.

[[email protected]: reduce implicit and explicit typecasting]
[[email protected]: fix return value, add comment, per Matthew]
Link: http://lkml.kernel.org/r/20190925110449.GO3264@mwanda
Fixes: 3cadfa2 ("mm/vmpressure.c: convert to use match_string() helper")
Signed-off-by: Dan Carpenter <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Acked-by: David Rientjes <[email protected]>
Reviewed-by: Matthew Wilcox <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Enrico Weigelt <[email protected]>
Cc: Kate Stewart <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Dan Carpenter authored and torvalds committed Oct 7, 2019
1 parent 234fdce commit 518a867
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions mm/vmpressure.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,17 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
* "hierarchy" or "local").
*
* To be used as memcg event method.
*
* Return: 0 on success, -ENOMEM on memory failure or -EINVAL if @args could
* not be parsed.
*/
int vmpressure_register_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd, const char *args)
{
struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
struct vmpressure_event *ev;
enum vmpressure_modes mode = VMPRESSURE_NO_PASSTHROUGH;
enum vmpressure_levels level = -1;
enum vmpressure_levels level;
char *spec, *spec_orig;
char *token;
int ret = 0;
Expand All @@ -375,20 +378,18 @@ int vmpressure_register_event(struct mem_cgroup *memcg,

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

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

ev = kzalloc(sizeof(*ev), GFP_KERNEL);
Expand All @@ -404,6 +405,7 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
mutex_lock(&vmpr->events_lock);
list_add(&ev->node, &vmpr->events);
mutex_unlock(&vmpr->events_lock);
ret = 0;
out:
kfree(spec_orig);
return ret;
Expand Down

0 comments on commit 518a867

Please sign in to comment.