From 3890a7b5fdd56006c08e3de656a9e15d9a4e7b6c Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Mon, 17 Jun 2019 15:16:47 -0700 Subject: [PATCH] mm: swap: Add null pointer check Address an unlikely null pointer dereference. Fixes commit 7b5df13bc4b3 ("mm: swap: free up swap on mm reap"). The expected usage of free_swap_slot is that the caller has already checked that the swap_entry_t is valid. Change-Id: I85331f817458df7f6cb0c0b387ca34c345f8c513 Signed-off-by: Patrick Daly Signed-off-by: Isaac J. Manjarres --- mm/swap_slots.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/swap_slots.c b/mm/swap_slots.c index 5d7f9a624ae5..c8828c3757ff 100644 --- a/mm/swap_slots.c +++ b/mm/swap_slots.c @@ -282,7 +282,7 @@ int free_swap_slot(swp_entry_t entry) si = swp_swap_info(entry); cache = raw_cpu_ptr(&swp_slots); - if (!(si->flags & SWP_SYNCHRONOUS_IO) && + if ((si && !(si->flags & SWP_SYNCHRONOUS_IO)) && use_swap_slot_cache && cache->slots_ret) { spin_lock_irq(&cache->free_lock); /* Swap slots cache may be deactivated before acquiring lock */