History

x86/mm/numa: Remove uninitialized_var() usage

Using uninitialized_var() is dangerous as it papers over real bugs[1] (or can in the future), and suppresses unrelated compiler warnings (e.g. "unused variable"). If the compiler thinks it is uninitialized, either simply initialize the variable or make compiler changes. As a precursor to removing[2] this[3] macro[4], refactor code to avoid its need. The original reason for its use here was to work around the #ifdef being the only place the variable was used. This is better expressed using IS_ENABLED() and a new code block where the variable can be used unconditionally. [1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/ [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/ [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/ [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/

Kees Cook committed 6 years ago

Commit aecfd221 parent 4b19bec2 files · +12 −10Browse files

Unified · Split

2 files
  1. arch/x86/mm/numa.c +9 −9
  2. include/linux/page-flags-layout.h +3 −1
arch/x86/mm/numa.c+9−9
@@ -543,7 +543,6 @@ static void __init numa_clear_kernel_node_hotplug(void) · 542 unmodified lines
543543
544544 static int __init numa_register_memblks(struct numa_meminfo *mi)
545545 {
546− unsigned long uninitialized_var(pfn_align);
547546 int i, nid;
548547
549548 /* Account for nodes with cpus and no memory */
@@ -571,15 +570,16 @@ static int __init numa_register_memblks(struct numa_meminfo *mi) · 21 unmodified lines
571570 * If sections array is gonna be used for pfn -> nid mapping, check
572571 * whether its granularity is fine enough.
573572 */
574−#ifdef NODE_NOT_IN_PAGE_FLAGS
575− pfn_align = node_map_pfn_alignment();
576− if (pfn_align && pfn_align < PAGES_PER_SECTION) {
577− printk(KERN_WARNING "Node alignment %LuMB < min %LuMB, rejecting NUMA config\n",
578− PFN_PHYS(pfn_align) >> 20,
579− PFN_PHYS(PAGES_PER_SECTION) >> 20);
580− return -EINVAL;
573+ if (IS_ENABLED(NODE_NOT_IN_PAGE_FLAGS)) {
574+ unsigned long pfn_align = node_map_pfn_alignment();
575+
576+ if (pfn_align && pfn_align < PAGES_PER_SECTION) {
577+ pr_warn("Node alignment %LuMB < min %LuMB, rejecting NUMA config\n",
578+ PFN_PHYS(pfn_align) >> 20,
579+ PFN_PHYS(PAGES_PER_SECTION) >> 20);
580+ return -EINVAL;
581+ }
581582 }
582−#endif
583583 if (!numa_meminfo_cover_memory(mi))
584584 return -EINVAL;
585585
include/linux/page-flags-layout.h+3−1
@@ -98,9 +98,11 @@ · 97 unmodified lines
9898 /*
9999 * We are going to use the flags for the page to node mapping if its in
100100 * there. This includes the case where there is no node, so it is implicit.
101+ * Note that this #define MUST have a value so that it can be tested with
102+ * the IS_ENABLED() macro.
101103 */
102104 #if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
103−#define NODE_NOT_IN_PAGE_FLAGS
105+#define NODE_NOT_IN_PAGE_FLAGS 1
104106 #endif
105107
106108 #if defined(CONFIG_NUMA_BALANCING) && LAST_CPUPID_WIDTH == 0