Messages in this thread Patch in this message | | | From | Fanjun Kong <> | Subject | [PATCH] x86/mm: declare static variable inside a function instead of global | Date | Sat, 18 Jun 2022 18:11:34 +0800 |
| |
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@linux.dev> --- 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
| |