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 <pdaly@codeaurora.org>
Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
This commit is contained in:
Patrick Daly 2019-06-17 15:16:47 -07:00 • committed by Isaac J. Manjarres
commit 3890a7b5fd

View file

@ -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 */