From 8e3a1a07e3bd18b17ac29de14823ee56a7d4bf03 Mon Sep 17 00:00:00 2001 From: Susheel Khiani Date: Thu, 12 Feb 2015 19:00:15 +0530 Subject: [PATCH] lowmemorykiller: Do proper NULL checks Pointer other_free is getting dereferenced without performing proper NULL checks which may cause issue. Do proper NULL checks at all points before dereferencing it. Change-Id: I88515703d64730e42598ab16136dcce4c18b099c Signed-off-by: Susheel Khiani --- drivers/staging/android/lowmemorykiller.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c index 752aba43fd7f..11535e3065ac 100644 --- a/drivers/staging/android/lowmemorykiller.c +++ b/drivers/staging/android/lowmemorykiller.c @@ -145,7 +145,7 @@ void tune_lmk_zone_param(struct zonelist *zonelist, int classzone_idx, for_each_zone_zonelist(zone, zoneref, zonelist, MAX_NR_ZONES) { zone_idx = zonelist_zone_idx(zoneref); if (zone_idx == ZONE_MOVABLE) { - if (!use_cma_pages) + if (!use_cma_pages && other_free) *other_free -= zone_page_state(zone, NR_FREE_CMA_PAGES); continue; @@ -160,7 +160,8 @@ void tune_lmk_zone_param(struct zonelist *zonelist, int classzone_idx, NR_FILE_PAGES) - zone_page_state(zone, NR_SHMEM); } else if (zone_idx < classzone_idx) { - if (zone_watermark_ok(zone, 0, 0, classzone_idx, 0)) { + if (zone_watermark_ok(zone, 0, 0, classzone_idx, 0) && + other_free) { if (!use_cma_pages) { *other_free -= min( zone->lowmem_reserve[classzone_idx] + @@ -173,8 +174,9 @@ void tune_lmk_zone_param(struct zonelist *zonelist, int classzone_idx, zone->lowmem_reserve[classzone_idx]; } } else { - *other_free -= - zone_page_state(zone, NR_FREE_PAGES); + if (other_free) + *other_free -= + zone_page_state(zone, NR_FREE_PAGES); } } }