[PATCH] x86/mm: declare static variable inside a function instead of global

From: Fanjun Kong
Date: Sat Jun 18 2022 - 06:12:33 EST


Global variables are global capacity variables, unless they are
shadowed, they are available to the entire program.
To reduce the scope of a variable as much as possible is always good
practice.

Signed-off-by: Fanjun Kong <fanjun.kong@xxxxxxxxx>
---
arch/x86/mm/init_64.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 39c5246964a9..582eab896480 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1515,9 +1515,10 @@ static unsigned long probe_memory_block_size(void)
return bz;
}

-static unsigned long memory_block_size_probed;
unsigned long memory_block_size_bytes(void)
{
+ static unsigned long memory_block_size_probed;
+
if (!memory_block_size_probed)
memory_block_size_probed = probe_memory_block_size();

--
2.36.0