mm: compaction: avoid possible NULL pointer dereference in kcompactd_cpu_online
authorMiaohe Lin <linmiaohe@huawei.com>
Fri, 29 Apr 2022 06:16:18 +0000 (23:16 -0700)
committerakpm <akpm@linux-foundation.org>
Fri, 29 Apr 2022 06:16:18 +0000 (23:16 -0700)
It's possible that kcompactd_run could fail to run kcompactd for a hot
added node and leave pgdat->kcompactd as NULL.  So pgdat->kcompactd should
be checked here to avoid possible NULL pointer dereference.

Link: https://lkml.kernel.org/r/20220418141253.24298-10-linmiaohe@huawei.com
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Charan Teja Kalla <charante@codeaurora.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Pintu Kumar <pintu@codeaurora.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/compaction.c

index 562f274..82c54d7 100644 (file)
@@ -3052,7 +3052,8 @@ static int kcompactd_cpu_online(unsigned int cpu)
 
                if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids)
                        /* One of our CPUs online: restore mask */
-                       set_cpus_allowed_ptr(pgdat->kcompactd, mask);
+                       if (pgdat->kcompactd)
+                               set_cpus_allowed_ptr(pgdat->kcompactd, mask);
        }
        return 0;
 }