2020-01-10 09:45:33

by Zhenzhong Duan

[permalink] [raw]
Subject: [PATCH] x86/boot/KASLR: Fix unused variable warning

Local variable 'i' is referenced only when CONFIG_MEMORY_HOTREMOVE and
CONFIG_ACPI are defined, but definition of variable 'i' is out of guard.
If any of the two macros is undefined, below warning triggers during
build with 'make EXTRA_CFLAGS=-Wall binrpm-pkg', fix it by moving 'i'
in the guard.

arch/x86/boot/compressed/kaslr.c:698:6: warning: unused variable ā€˜iā€™ [-Wunused-variable]

Fixes: 690eaa532057 ("x86/boot/KASLR: Limit KASLR to extract the kernel in immovable memory only")
Signed-off-by: Zhenzhong Duan <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
---
v3: remove changes from 0/1 to false/true per Tglx
add the command details about triggering build warning per Boris

v2: update description per Boris.

arch/x86/boot/compressed/kaslr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index d7408af55738..62bc46684581 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -695,7 +695,6 @@ static bool process_mem_region(struct mem_vector *region,
unsigned long long minimum,
unsigned long long image_size)
{
- int i;
/*
* If no immovable memory found, or MEMORY_HOTREMOVE disabled,
* use @region directly.
@@ -711,6 +710,7 @@ static bool process_mem_region(struct mem_vector *region,
}

#if defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
+ int i;
/*
* If immovable memory found, filter the intersection between
* immovable memory and @region.
--
2.17.1


2020-01-10 09:49:35

by Zhenzhong Duan

[permalink] [raw]
Subject: Re: [PATCH v3] x86/boot/KASLR: Fix unused variable warning

I mean [PATCH v3]

On Fri, Jan 10, 2020 at 5:43 PM Zhenzhong Duan <[email protected]> wrote:
>
> Local variable 'i' is referenced only when CONFIG_MEMORY_HOTREMOVE and
> CONFIG_ACPI are defined, but definition of variable 'i' is out of guard.
> If any of the two macros is undefined, below warning triggers during
> build with 'make EXTRA_CFLAGS=-Wall binrpm-pkg', fix it by moving 'i'
> in the guard.
>
> arch/x86/boot/compressed/kaslr.c:698:6: warning: unused variable ā€˜iā€™ [-Wunused-variable]
>
> Fixes: 690eaa532057 ("x86/boot/KASLR: Limit KASLR to extract the kernel in immovable memory only")
> Signed-off-by: Zhenzhong Duan <[email protected]>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: Borislav Petkov <[email protected]>
> Cc: "H. Peter Anvin" <[email protected]>
> Cc: Dave Hansen <[email protected]>
> Cc: "Rafael J. Wysocki" <[email protected]>
> ---
> v3: remove changes from 0/1 to false/true per Tglx
> add the command details about triggering build warning per Boris
>
> v2: update description per Boris.
>
> arch/x86/boot/compressed/kaslr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> index d7408af55738..62bc46684581 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -695,7 +695,6 @@ static bool process_mem_region(struct mem_vector *region,
> unsigned long long minimum,
> unsigned long long image_size)
> {
> - int i;
> /*
> * If no immovable memory found, or MEMORY_HOTREMOVE disabled,
> * use @region directly.
> @@ -711,6 +710,7 @@ static bool process_mem_region(struct mem_vector *region,
> }
>
> #if defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
> + int i;
> /*
> * If immovable memory found, filter the intersection between
> * immovable memory and @region.
> --
> 2.17.1
>

2020-01-10 09:54:30

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] x86/boot/KASLR: Fix unused variable warning

On Fri, Jan 10, 2020 at 05:43:04PM +0800, Zhenzhong Duan wrote:
> Local variable 'i' is referenced only when CONFIG_MEMORY_HOTREMOVE and
> CONFIG_ACPI are defined, but definition of variable 'i' is out of guard.
> If any of the two macros is undefined, below warning triggers during
> build with 'make EXTRA_CFLAGS=-Wall binrpm-pkg', fix it by moving 'i'
> in the guard.

Maybe I wasn't clear: save this patch for when it triggers in the normal
build, without additional build flags.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette