linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Add -Wunused to x86 boot module and fix build warning
@ 2020-03-03  6:52 Zhenzhong Duan
  2020-03-03  6:52 ` [PATCH 1/2] x86/boot: Add -Wunused to KBUILD_CFLAGS Zhenzhong Duan
  2020-03-03  6:52 ` [PATCH 2/2] x86/boot/KASLR: Fix unused variable warning Zhenzhong Duan
  0 siblings, 2 replies; 5+ messages in thread
From: Zhenzhong Duan @ 2020-03-03  6:52 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, tglx, mingo, bp, zhenzhong.duan

[PATCH 1/2] is based on previous discuss in link below
https://lore.kernel.org/patchwork/patch/1175001/#1379873

[PATCH 2/2] drop true/false change per Thomas suggestion.

This two patches is a series, the warning in patch2 will not trigger
without patch1 by default.

Zhenzhong Duan (2):
  x86/boot: Add -Wunused to KBUILD_CFLAGS
  x86/boot/KASLR: Fix unused variable warning

 arch/x86/boot/compressed/Makefile | 2 +-
 arch/x86/boot/compressed/kaslr.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.17.1


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

* [PATCH 1/2] x86/boot: Add -Wunused to KBUILD_CFLAGS
  2020-03-03  6:52 [PATCH 0/2] Add -Wunused to x86 boot module and fix build warning Zhenzhong Duan
@ 2020-03-03  6:52 ` Zhenzhong Duan
  2020-03-03  6:52 ` [PATCH 2/2] x86/boot/KASLR: Fix unused variable warning Zhenzhong Duan
  1 sibling, 0 replies; 5+ messages in thread
From: Zhenzhong Duan @ 2020-03-03  6:52 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, tglx, mingo, bp, zhenzhong.duan, H. Peter Anvin

Compile warning option in arch/x86/boot/compressed is different from
other part of the kernel for some history reason. But "-Wunused" is
safe to be added to point out unused variable issue.

Link: https://lore.kernel.org/patchwork/patch/1175001/#1379873
Suggested-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
 arch/x86/boot/compressed/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 26050ae0b27e..cb9743ec453a 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -37,7 +37,7 @@ KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
 KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
-KBUILD_CFLAGS += -Wno-pointer-sign
+KBUILD_CFLAGS += -Wno-pointer-sign -Wunused
 KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
 
 KBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__ASSEMBLY__
-- 
2.17.1


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

* [PATCH 2/2] x86/boot/KASLR: Fix unused variable warning
  2020-03-03  6:52 [PATCH 0/2] Add -Wunused to x86 boot module and fix build warning Zhenzhong Duan
  2020-03-03  6:52 ` [PATCH 1/2] x86/boot: Add -Wunused to KBUILD_CFLAGS Zhenzhong Duan
@ 2020-03-03  6:52 ` Zhenzhong Duan
  2020-03-03 22:56   ` Dave Hansen
  1 sibling, 1 reply; 5+ messages in thread
From: Zhenzhong Duan @ 2020-03-03  6:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: x86, tglx, mingo, bp, zhenzhong.duan, Borislav Petkov,
	H. Peter Anvin, Dave Hansen, Rafael J. Wysocki

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, 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 <zhenzhong.duan@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
---
 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


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

* Re: [PATCH 2/2] x86/boot/KASLR: Fix unused variable warning
  2020-03-03  6:52 ` [PATCH 2/2] x86/boot/KASLR: Fix unused variable warning Zhenzhong Duan
@ 2020-03-03 22:56   ` Dave Hansen
  2020-03-05  4:03     ` Zhenzhong Duan
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Hansen @ 2020-03-03 22:56 UTC (permalink / raw)
  To: Zhenzhong Duan, linux-kernel
  Cc: x86, tglx, mingo, bp, Borislav Petkov, H. Peter Anvin,
	Dave Hansen, Rafael J. Wysocki

On 3/2/20 10:52 PM, 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, fix it by moving 'i' in the guard.
> 
> arch/x86/boot/compressed/kaslr.c:698:6: warning: unused variable ‘i’ [-Wunused-variable]
...
> 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;

Won't this just result in a different warning since it now it will
declare 'i' in the middle of the function once CONFIG_MEMORY_HOTREMOVE
and ACPI are enabled?

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

* Re: [PATCH 2/2] x86/boot/KASLR: Fix unused variable warning
  2020-03-03 22:56   ` Dave Hansen
@ 2020-03-05  4:03     ` Zhenzhong Duan
  0 siblings, 0 replies; 5+ messages in thread
From: Zhenzhong Duan @ 2020-03-05  4:03 UTC (permalink / raw)
  To: Dave Hansen
  Cc: linux-kernel, x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Borislav Petkov, H. Peter Anvin, Dave Hansen, Rafael J. Wysocki

On Wed, Mar 4, 2020 at 6:56 AM Dave Hansen <dave.hansen@intel.com> wrote:
>
> On 3/2/20 10:52 PM, 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, fix it by moving 'i' in the guard.
> >
> > arch/x86/boot/compressed/kaslr.c:698:6: warning: unused variable ‘i’ [-Wunused-variable]
> ...
> > 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;
>
> Won't this just result in a different warning since it now it will
> declare 'i' in the middle of the function once CONFIG_MEMORY_HOTREMOVE
> and ACPI are enabled?

I didn't see a different warning with both configs enabled, because
-std=gnu89 isn't
enforced in arch/x86/boot/compressed but it does in other part of kernel.
C99 and above allows declaration in middule of the function.

Zhenzhong

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

end of thread, other threads:[~2020-03-05  4:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03  6:52 [PATCH 0/2] Add -Wunused to x86 boot module and fix build warning Zhenzhong Duan
2020-03-03  6:52 ` [PATCH 1/2] x86/boot: Add -Wunused to KBUILD_CFLAGS Zhenzhong Duan
2020-03-03  6:52 ` [PATCH 2/2] x86/boot/KASLR: Fix unused variable warning Zhenzhong Duan
2020-03-03 22:56   ` Dave Hansen
2020-03-05  4:03     ` Zhenzhong Duan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).