Skip to contentSkip to conversation

cpu: microcode: replace 0 with NULL

PATCH In review Jules Irenge 3 participants 4 messages Nov 26, 2019 – Nov 27, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu: microcode: replace 0 with NULL

Replace 0 with NULL to fix sparse tool warning
warning: Using plain integer as NULL pointer

---
 arch/x86/kernel/cpu/microcode/amd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +2 -2
index a0e52bd00ecc..4934aa7c94e7 100644
@@ -418,7 +418,7 @@ static int __apply_microcode_amd(struct microcode_amd *mc)
 static bool
 apply_microcode_early_amd(u32 cpuid_1_eax, void *ucode, size_t size, bool save_patch)
 {
-	struct cont_desc desc = { 0 };
+	struct cont_desc desc = { NULL };
 	u8 (*patch)[PATCH_MAX_SIZE];
 	struct microcode_amd *mc;
 	u32 rev, dummy, *new_rev;
@@ -543,7 +543,7 @@ load_microcode_amd(bool save, u8 family, const u8 *data, size_t size);
 
 int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)
 {
-	struct cont_desc desc = { 0 };
+	struct cont_desc desc = { NULL };
 	enum ucode_state ret;
 	struct cpio_data cp;
 
Signature · 1 line
2.23.0
maintainer
#1 lore raw
Quoted 13 lines · Jules Irenge

Replace 0 with NULL to fix sparse tool warning
warning: Using plain integer as NULL pointer

---
 arch/x86/kernel/cpu/microcode/amd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +0 -0
index a0e52bd00ecc..4934aa7c94e7 100644

arch/x86/kernel/cpu/microcode/amd.c static int __apply_microcode_amd(struct microcode_amd *mc) · line 421

Quoted 5 lines
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -418,7 +418,7 @@ static int __apply_microcode_amd(struct microcode_amd *mc)
 static bool
 apply_microcode_early_amd(u32 cpuid_1_eax, void *ucode, size_t size, bool save_patch)
 {
-	struct cont_desc desc = { 0 };
+	struct cont_desc desc = { NULL };

So my gcc guy says that 0 and NULL are equivalent as designated initializers in this case. And if you look at the resulting asm, it doesn't change:

# arch/x86/kernel/cpu/microcode/amd.c:421: 	struct cont_desc desc = { 0 };
	movq	$0, 8(%rsp)	#, desc
	movq	$0, (%rsp)	#, desc
	movq	$0, 16(%rsp)	#, desc
	movq	$0, 24(%rsp)	#, desc

But what I'd prefer actually is, if you do them like this:

			... = { 0,  };

because:

1. It is clear that the memory for the struct is being cleared
2. The following ones - the ones after "," are missing too, on purpose, because they're being cleared too.

Also pls add that explanation to the commit message.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#2 lore raw
Quoted 36 lines · Borislav Petkov
Quoted 13 lines · Jules Irenge

Replace 0 with NULL to fix sparse tool warning
warning: Using plain integer as NULL pointer

---
 arch/x86/kernel/cpu/microcode/amd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +0 -0
index a0e52bd00ecc..4934aa7c94e7 100644

arch/x86/kernel/cpu/microcode/amd.c static int __apply_microcode_amd(struct microcode_amd *mc) · line 421

Quoted 5 lines
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -418,7 +418,7 @@ static int __apply_microcode_amd(struct microcode_amd *mc)
 static bool
 apply_microcode_early_amd(u32 cpuid_1_eax, void *ucode, size_t size, bool save_patch)
 {
-	struct cont_desc desc = { 0 };
+	struct cont_desc desc = { NULL };

So my gcc guy says that 0 and NULL are equivalent as designated initializers in this case. And if you look at the resulting asm, it doesn't change:

# arch/x86/kernel/cpu/microcode/amd.c:421: 	struct cont_desc desc = { 0 };
	movq	$0, 8(%rsp)	#, desc
	movq	$0, (%rsp)	#, desc
	movq	$0, 16(%rsp)	#, desc
	movq	$0, 24(%rsp)	#, desc

But what I'd prefer actually is, if you do them like this:

			... = { 0,  };

because:

Quoted 14 lines

1. It is clear that the memory for the struct is being cleared
2. The following ones - the ones after "," are missing too, on purpose, because they're being cleared too.

Also pls add that explanation to the commit message.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

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

Hi Boris,

Thanks for your reply and suggestion.

I am learning patching with sparse trying to solve some problems that the tool complains about.

Sometime the tool is not always right. If I take your suggestion that I am about to do, sparse will however still complain.

so I will suggest my change to be discarded.

I will take another challenge.

Kind regards,
Jules

#3 lore raw
Quoted 60 lines · Jules Irenge
Quoted 36 lines · Borislav Petkov
Quoted 13 lines · Jules Irenge

Replace 0 with NULL to fix sparse tool warning
warning: Using plain integer as NULL pointer

---
 arch/x86/kernel/cpu/microcode/amd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +0 -0
index a0e52bd00ecc..4934aa7c94e7 100644

arch/x86/kernel/cpu/microcode/amd.c static int __apply_microcode_amd(struct microcode_amd *mc) · line 421

Quoted 5 lines
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -418,7 +418,7 @@ static int __apply_microcode_amd(struct microcode_amd *mc)
 static bool
 apply_microcode_early_amd(u32 cpuid_1_eax, void *ucode, size_t size, bool save_patch)
 {
-	struct cont_desc desc = { 0 };
+	struct cont_desc desc = { NULL };

So my gcc guy says that 0 and NULL are equivalent as designated initializers in this case. And if you look at the resulting asm, it doesn't change:

# arch/x86/kernel/cpu/microcode/amd.c:421: 	struct cont_desc desc = { 0 };
	movq	$0, 8(%rsp)	#, desc
	movq	$0, (%rsp)	#, desc
	movq	$0, 16(%rsp)	#, desc
	movq	$0, 24(%rsp)	#, desc

But what I'd prefer actually is, if you do them like this:

			... = { 0,  };

because:

Quoted 14 lines

1. It is clear that the memory for the struct is being cleared
2. The following ones - the ones after "," are missing too, on purpose, because they're being cleared too.

Also pls add that explanation to the commit message.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

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

Hi Boris,

Thanks for your reply and suggestion.

I am learning patching with sparse trying to solve some problems that the tool complains about.

Quoted 6 lines

Sometime the tool is not always right. If I take your suggestion that I am about to do, sparse will however still complain.

so I will suggest my change to be discarded.

I will take another challenge.

This initializer should ether use named members with the appropriate zeroing type or just use a blank {} so that regardless of type and member order, the entire structure is zeroed.

	struct cont_desc desc = {};