mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-28 22:54:05 +08:00
mm/vmpressure.c: fix a signedness bug in vmpressure_register_event()
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.
[akpm@linux-foundation.org: reduce implicit and explicit typecasting]
[akpm@linux-foundation.org: fix return value, add comment, per Matthew]
Link: http://lkml.kernel.org/r/20190925110449.GO3264@mwanda
Fixes: 3cadfa2b94
("mm/vmpressure.c: convert to use match_string() helper")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: David Rientjes <rientjes@google.com>
Reviewed-by: Matthew Wilcox <willy@infradead.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Enrico Weigelt <info@metux.net>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
234fdce892
commit
518a867130
@ -355,6 +355,9 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
|
|||||||
* "hierarchy" or "local").
|
* "hierarchy" or "local").
|
||||||
*
|
*
|
||||||
* To be used as memcg event method.
|
* 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,
|
int vmpressure_register_event(struct mem_cgroup *memcg,
|
||||||
struct eventfd_ctx *eventfd, const char *args)
|
struct eventfd_ctx *eventfd, const char *args)
|
||||||
@ -362,7 +365,7 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
|
|||||||
struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
|
struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
|
||||||
struct vmpressure_event *ev;
|
struct vmpressure_event *ev;
|
||||||
enum vmpressure_modes mode = VMPRESSURE_NO_PASSTHROUGH;
|
enum vmpressure_modes mode = VMPRESSURE_NO_PASSTHROUGH;
|
||||||
enum vmpressure_levels level = -1;
|
enum vmpressure_levels level;
|
||||||
char *spec, *spec_orig;
|
char *spec, *spec_orig;
|
||||||
char *token;
|
char *token;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -375,20 +378,18 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
|
|||||||
|
|
||||||
/* Find required level */
|
/* Find required level */
|
||||||
token = strsep(&spec, ",");
|
token = strsep(&spec, ",");
|
||||||
level = match_string(vmpressure_str_levels, VMPRESSURE_NUM_LEVELS, token);
|
ret = match_string(vmpressure_str_levels, VMPRESSURE_NUM_LEVELS, token);
|
||||||
if (level < 0) {
|
if (ret < 0)
|
||||||
ret = level;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
level = ret;
|
||||||
|
|
||||||
/* Find optional mode */
|
/* Find optional mode */
|
||||||
token = strsep(&spec, ",");
|
token = strsep(&spec, ",");
|
||||||
if (token) {
|
if (token) {
|
||||||
mode = match_string(vmpressure_str_modes, VMPRESSURE_NUM_MODES, token);
|
ret = match_string(vmpressure_str_modes, VMPRESSURE_NUM_MODES, token);
|
||||||
if (mode < 0) {
|
if (ret < 0)
|
||||||
ret = mode;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
mode = ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ev = kzalloc(sizeof(*ev), GFP_KERNEL);
|
ev = kzalloc(sizeof(*ev), GFP_KERNEL);
|
||||||
@ -404,6 +405,7 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
|
|||||||
mutex_lock(&vmpr->events_lock);
|
mutex_lock(&vmpr->events_lock);
|
||||||
list_add(&ev->node, &vmpr->events);
|
list_add(&ev->node, &vmpr->events);
|
||||||
mutex_unlock(&vmpr->events_lock);
|
mutex_unlock(&vmpr->events_lock);
|
||||||
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
kfree(spec_orig);
|
kfree(spec_orig);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user