Skip to contentSkip to conversation

arch/x86: Fix sparse warning

PATCH Superseded Tobin C. Harding 2 participants 8 messages Feb 12, 2017 – Feb 21, 2017 x86

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover arch/x86: Fix sparse warning

This series fixes multiple occurences of sparse warning, 'symbol is not declared. Should it be static?'. Initial patch adds 'static' keyword to variable declarations. Second patch declares function in order to clear same warning.

Tobin C. Harding (2):
arch/x86: Fix sparse warning symbol not declared arch/x86: Fix sparse warning symbol not declared

 arch/x86/purgatory/purgatory.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 arch/x86: Fix sparse warning symbol not declared

This patch adds static declaration to a number of variables. Fixes sparse symbol was not declared warnings.

---
 arch/x86/purgatory/purgatory.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/purgatory/purgatory.c +5 -5
index 25e068b..2a2cbe5 100644
@@ -18,11 +18,11 @@ struct sha_region {
 	unsigned long len;
 };
 
-unsigned long backup_dest = 0;
-unsigned long backup_src = 0;
-unsigned long backup_sz = 0;
+static unsigned long backup_dest = 0;
+static unsigned long backup_src = 0;
+static unsigned long backup_sz = 0;
 
-u8 sha256_digest[SHA256_DIGEST_SIZE] = { 0 };
+static u8 sha256_digest[SHA256_DIGEST_SIZE] = { 0 };
 
 struct sha_region sha_regions[16] = {};
 
@@ -39,7 +39,7 @@ static int copy_backup_region(void)
 	return 0;
 }
 
-int verify_sha256_digest(void)
+static int verify_sha256_digest(void)
 {
 	struct sha_region *ptr, *end;
 	u8 digest[SHA256_DIGEST_SIZE];
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/2] arch/x86: Fix sparse warning symbol not declared

On Sun, 12 Feb 2017, Tobin C. Harding wrote:

A few nitpicks.

Quoted 1 line

Subject: [PATCH 1/2] arch/x86: Fix sparse warning symbol not declared

arch/x86: is not the correct prefix. Run git log on a file to figure out what the usual prefix is. The file was checked in with 'purgatory', but I'd prefer 'x86/purgatory' for future changes.

Quoted 2 lines

This patch adds static declaration to a number of variables. Fixes sparse symbol was not declared warnings.

Please read 'Documentation...SubmittingPatches' and look for 'This patch'.

I give you an example for a changelog:

Sparse emits several 'symbol not declared' warnings.

Make the variables and functions, which have only file scope static.

Now try to map that to the advise in Documentation.

Thanks,

tglx

#3 lore raw

PATCH 2/2 arch/x86: Fix sparse warning symbol not declared

In reply to Tobin C. Harding

This patch adds function declaration in order to quiet sparse symbol not declared warning.

---

Unsure why adding declaration quiets sparse. This may not be the correct solution. Only testing done is building and booting kernel. Since 'purgatory' is called from assembler and does not need forward declaration the only advantage to this patch seems to be to save the next newbie from investigating the sparse warning.

arch/x86/purgatory/purgatory.c | 2 ++

 1 file changed, 2 insertions(+)
arch/x86/purgatory/purgatory.c +2 -0
index 2a2cbe5..129433c 100644
@@ -18,6 +18,8 @@ struct sha_region {
 	unsigned long len;
 };
 
+void purgatory(void);
+
 static unsigned long backup_dest = 0;
 static unsigned long backup_src = 0;
 static unsigned long backup_sz = 0;
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH 2/2] arch/x86: Fix sparse warning symbol not declared

Quoted 2 lines · Tobin C. Harding

This patch adds function declaration in order to quiet sparse symbol not declared warning.

Same comment vs. 'This patch' as before. Hint, we already know that this is a patch, otherwise it would be mislabeled.

Quoted 5 lines

---

Unsure why adding declaration quiets sparse.

Because sparse finds a declaration before the definition.

Quoted 1 line

This may not be the correct solution.

Right, it's not.

Quoted 4 lines

Only testing done is building and booting kernel. Since 'purgatory' is called from assembler and does not need forward declaration the only advantage to this patch seems to be to save the next newbie from investigating the sparse warning.

Well, yes. But just quietening a checker by slapping a pointless forward declaration into the code is not pretty either. A smarter checker might catch that.

The proper solution is to have a local include file 'purgatory.h' and put the declaration there. Include it in both files even if that's not required for the ASM file. But that documents, that the function is used outside of purgatory.c

Thanks,

tglx

#5 lore raw

Re: [PATCH 2/2] arch/x86: Fix sparse warning symbol not declared

Quoted 25 lines · Thomas Gleixner
Quoted 2 lines · Tobin C. Harding

This patch adds function declaration in order to quiet sparse symbol not declared warning.

Same comment vs. 'This patch' as before. Hint, we already know that this is a patch, otherwise it would be mislabeled.

Quoted 5 lines

---

Unsure why adding declaration quiets sparse.

Because sparse finds a declaration before the definition.

Quoted 1 line

This may not be the correct solution.

Right, it's not.

Quoted 4 lines

Only testing done is building and booting kernel. Since 'purgatory' is called from assembler and does not need forward declaration the only advantage to this patch seems to be to save the next newbie from investigating the sparse warning.

Quoted 8 lines

Well, yes. But just quietening a checker by slapping a pointless forward declaration into the code is not pretty either. A smarter checker might catch that.

The proper solution is to have a local include file 'purgatory.h' and put the declaration there. Include it in both files even if that's not required for the ASM file. But that documents, that the function is used outside of purgatory.c

Blindly following instructions led to the bone headed patch I submitted yesterday (without building). Is there some way to include a C header in an ASM file that I do not know about?

Thanks for patiently pointing out how to write a commit log. May I please bother you with another small etiquette question. Should I have replayed to you as I have done so or should I have re-sent another patch (v3) with the mistakes fixed (and stated in the log that I did not know how to implement the suggestions).

thanks,
Tobin.

#6 lore raw

Re: [PATCH 2/2] arch/x86: Fix sparse warning symbol not declared

Quoted 9 lines · Tobin Harding
Quoted 4 lines · Thomas Gleixner

The proper solution is to have a local include file 'purgatory.h' and put the declaration there. Include it in both files even if that's not required for the ASM file. But that documents, that the function is used outside of purgatory.c

Blindly following instructions led to the bone headed patch I submitted yesterday (without building). Is there some way to include a C header in an ASM file that I do not know about?

Yes, you have to guard the function declaration with

#ifndef __ASSEMBLY__

I did not think about that when I suggested this. Brainslip :)

So yes, it's kinda pointless, but it still has documentatory value and keeps the sparse build clean.

Quoted 5 lines

Thanks for patiently pointing out how to write a commit log. May I please bother you with another small etiquette question. Should I have replayed to you as I have done so or should I have re-sent another patch (v3) with the mistakes fixed (and stated in the log that I did not know how to implement the suggestions).

All good. Either way works as long as you notice your own mistakes. It's also fine to tell me that I suggested nonsense. :)

Thanks,

tglx

#7 lore raw

Re: [PATCH 2/2] arch/x86: Fix sparse warning symbol not declared

Quoted 20 lines · Thomas Gleixner
Quoted 9 lines · Tobin Harding
Quoted 4 lines · Thomas Gleixner

The proper solution is to have a local include file 'purgatory.h' and put the declaration there. Include it in both files even if that's not required for the ASM file. But that documents, that the function is used outside of purgatory.c

Blindly following instructions led to the bone headed patch I submitted yesterday (without building). Is there some way to include a C header in an ASM file that I do not know about?

Yes, you have to guard the function declaration with

#ifndef __ASSEMBLY__

I did not think about that when I suggested this. Brainslip :)

So yes, it's kinda pointless, but it still has documentatory value and keeps the sparse build clean.

Quoted 9 lines
Quoted 5 lines

Thanks for patiently pointing out how to write a commit log. May I please bother you with another small etiquette question. Should I have replayed to you as I have done so or should I have re-sent another patch (v3) with the mistakes fixed (and stated in the log that I did not know how to implement the suggestions).

All good. Either way works as long as you notice your own mistakes. It's also fine to tell me that I suggested nonsense. :)

It has been pointed out to me that I could have approached the dev process of this patch better. In the name of learning the correct method I am now replying to your comments Thomas. Thanks for being patient, if you could please slap me if I slip I should be able to blossom into a decent contributor.

After sending an incorrect version (v3) with the __ASSEMBLY__ preprocessor guard in the wrong place, I re-sent v4 with what I believe is all of your comments implemented and functioning.

Thanks for taking the time to review my annoying multi-version almost trivial patch series.

thanks,
Tobin.