From 3e49dbc48e5917463c1617b987c7abc091609e6a Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Tue, 10 Aug 2021 20:30:58 -0700 Subject: [PATCH] simple_lmk: Be extra paranoid if tasks can have no pages If it's possible for a task to have no pages, then there could be a case where `pages_found` is zero while `nr_found` isn't, which would cause the found tasks' locks to never be unlocked, and thus mayhem. We can change the `pages_found` check to use `nr_found` instead in order to naturally defend against this scenario, in case it is indeed possible. Signed-off-by: Sultan Alsawaf --- drivers/android/simple_lmk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/android/simple_lmk.c b/drivers/android/simple_lmk.c index 0013f4d37b7d..3ed9182c1d42 100644 --- a/drivers/android/simple_lmk.c +++ b/drivers/android/simple_lmk.c @@ -191,7 +191,7 @@ static void scan_and_kill(void) /* Populate the victims array with tasks sorted by adj and then size */ pages_found = find_victims(&nr_found); - if (unlikely(!pages_found)) { + if (unlikely(!nr_found)) { pr_err("No processes available to kill!\n"); return; }