All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/numa: Use cpumask_available instead of hardcoded NULL check
@ 2022-07-31 16:09 ` Siddh Raman Pant
  0 siblings, 0 replies; 19+ messages in thread
From: Siddh Raman Pant via Linux-kernel-mentees @ 2022-07-31 16:09 UTC (permalink / raw)
  To: x86, Dave Hansen, Andy Lutomirski, Peter Zijlstra,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin
  Cc: linux-kernel-mentees, linux-kernel

node_to_cpumask_map is of type cpumask_var_t[].

When CONFIG_CPUMASK_OFFSTACK is set, cpumask_var_t is typedef'd to a
pointer for dynamic allocation, else to an array of one element. The
"wicked game" can be checked on line 700 of include/linux/cpumask.h.

The lines changed in this commit were probably written by the original
authors with CONFIG_CPUMASK_OFFSTACK=y (i.e. dynamic allocation) in mind,
checking if the cpumask was available via a direct NULL check.

When CONFIG_CPUMASK_OFFSTACK is not set, GCC gives the below given warning
while compiling the kernel.

Fix that by using cpumask_available(), which does the NULL check when
CONFIG_CPUMASK_OFFSTACK is set, otherwise returns true. Use it wherever
such checks are made.

Conditional definitions of cpumask_available() can be found along with
the definition of cpumask_var_t. Check the cpumask.h reference mentioned
above.

GCC warning log:
===========================================================================

arch/x86/mm/numa.c: In function ‘cpumask_of_node’:
arch/x86/mm/numa.c:916:39: warning: the comparison will always evaluate as ‘false’ for the address of ‘node_to_cpumask_map’ will never be NULL [-Waddress]
  916 |         if (node_to_cpumask_map[node] == NULL) {
      |                                       ^~
In file included from ./include/linux/linkage.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./arch/x86/include/asm/percpu.h:27,
                 from ./arch/x86/include/asm/current.h:6,
                 from ./include/linux/mutex.h:14,
                 from ./include/linux/kernfs.h:11,
                 from ./include/linux/sysfs.h:16,
                 from ./include/linux/kobject.h:20,
                 from ./include/linux/of.h:17,
                 from ./include/linux/irqdomain.h:35,
                 from ./include/linux/acpi.h:13,
                 from arch/x86/mm/numa.c:3:
arch/x86/mm/numa.c:67:15: note: ‘node_to_cpumask_map’ declared here
   67 | EXPORT_SYMBOL(node_to_cpumask_map);
      |               ^~~~~~~~~~~~~~~~~~~
./include/linux/export.h:87:28: note: in definition of macro ‘___EXPORT_SYMBOL’
   87 |         extern typeof(sym) sym;                                                 \
      |                            ^~~
./include/linux/export.h:147:41: note: in expansion of macro ‘__EXPORT_SYMBOL’
  147 | #define _EXPORT_SYMBOL(sym, sec)        __EXPORT_SYMBOL(sym, sec, "")
      |                                         ^~~~~~~~~~~~~~~
./include/linux/export.h:150:41: note: in expansion of macro ‘_EXPORT_SYMBOL’
  150 | #define EXPORT_SYMBOL(sym)              _EXPORT_SYMBOL(sym, "")
      |                                         ^~~~~~~~~~~~~~
arch/x86/mm/numa.c:67:1: note: in expansion of macro ‘EXPORT_SYMBOL’
   67 | EXPORT_SYMBOL(node_to_cpumask_map);
      | ^~~~~~~~~~~~~

===========================================================================

Fixes: c032ef60d1aa ("cpumask: convert node_to_cpumask_map[] to cpumask_var_t")
Fixes: de2d9445f162 ("x86: Unify node_to_cpumask_map handling between 32 and 64bit")

Signed-off-by: Siddh Raman Pant <code@siddh.me>
---
 arch/x86/mm/numa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index e8b061557887..2aadb2019b4f 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -867,7 +867,7 @@ void debug_cpumask_set_cpu(int cpu, int node, bool enable)
 		return;
 	}
 	mask = node_to_cpumask_map[node];
-	if (!mask) {
+	if (!cpumask_available(mask)) {
 		pr_err("node_to_cpumask_map[%i] NULL\n", node);
 		dump_stack();
 		return;
@@ -913,7 +913,7 @@ const struct cpumask *cpumask_of_node(int node)
 		dump_stack();
 		return cpu_none_mask;
 	}
-	if (node_to_cpumask_map[node] == NULL) {
+	if (!cpumask_available(node_to_cpumask_map[node])) {
 		printk(KERN_WARNING
 			"cpumask_of_node(%d): no node_to_cpumask_map!\n",
 			node);
-- 
2.35.1


_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-08-03 15:42 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-31 16:09 [PATCH] x86/numa: Use cpumask_available instead of hardcoded NULL check Siddh Raman Pant via Linux-kernel-mentees
2022-07-31 16:09 ` Siddh Raman Pant
2022-08-02 11:07 ` Ingo Molnar
2022-08-02 11:07   ` Ingo Molnar
2022-08-02 16:29   ` Siddh Raman Pant via Linux-kernel-mentees
2022-08-02 16:29     ` Siddh Raman Pant
2022-08-03  8:48     ` Ingo Molnar
2022-08-03  8:48       ` Ingo Molnar
2022-08-03  8:58       ` Siddh Raman Pant via Linux-kernel-mentees
2022-08-03  8:58         ` Siddh Raman Pant
2022-08-03  9:08         ` Ingo Molnar
2022-08-03  9:08           ` Ingo Molnar
2022-08-03  9:21           ` Siddh Raman Pant
2022-08-03  9:21             ` Siddh Raman Pant via Linux-kernel-mentees
2022-08-03  9:42             ` Ingo Molnar
2022-08-03  9:42               ` Ingo Molnar
2022-08-03  9:46               ` Siddh Raman Pant via Linux-kernel-mentees
2022-08-03  9:46                 ` Siddh Raman Pant
2022-08-03 15:41 ` [tip: x86/urgent] " tip-bot2 for Siddh Raman Pant

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.