Skip to contentSkip to conversation

mm:kasan: fix sparse warnings: Should it be static?

PATCH Applied Nihar Chaithanya 3 participants 3 messages Oct 11, 2024 – Oct 12, 2024

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

PATCH v3 1/1 mm:kasan: fix sparse warnings: Should it be static?

Yes, when making the global variables kasan_ptr_result and kasan_int_result as static volatile, the warnings are removed and the variable and assignments are retained, but when just static is used I understand that it might be optimized.

Add a fix making the global varaibles - static volatile, removing the
warnings:
mm/kasan/kasan_test.c:36:6: warning: symbol 'kasan_ptr_result' was not declared. Should it be static? mm/kasan/kasan_test.c:37:5: warning: symbol 'kasan_int_result' was not declared. Should it be static?

---
v1 -> v2: Used the aproach of making global variables static to resolve the warnings instead of local declarations.

v2 -> v3: Making the global variables static volatile to resolve the warnings.

Link to v1: https://lore.kernel.org/all/[email protected]/
Link to v2: https://lore.kernel.org/all/[email protected]/

 mm/kasan/kasan_test_c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/kasan/kasan_test_c.c +2 -2
index a181e4780d9d..7884b46a1e71 100644
@@ -45,8 +45,8 @@ static struct {
  * Some tests use these global variables to store return values from function
  * calls that could otherwise be eliminated by the compiler as dead code.
  */
-void *kasan_ptr_result;
-int kasan_int_result;
+static volatile void *kasan_ptr_result;
+static volatile int kasan_int_result;
 
 /* Probe for console output: obtains test_status lines of interest. */
 static void probe_console(void *ignore, const char *buf, size_t len)
Signature · 1 line
2.34.1
reviewer Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · Nihar Chaithanya

Yes, when making the global variables kasan_ptr_result and kasan_int_result as static volatile, the warnings are removed and the variable and assignments are retained, but when just static is used I understand that it might be optimized.

Quoted 8 lines

Add a fix making the global varaibles - static volatile, removing the
warnings:
mm/kasan/kasan_test.c:36:6: warning: symbol 'kasan_ptr_result' was not declared. Should it be static? mm/kasan/kasan_test.c:37:5: warning: symbol 'kasan_int_result' was not declared. Should it be static?

Quoted 35 lines

---
v1 -> v2: Used the aproach of making global variables static to resolve the warnings instead of local declarations.

v2 -> v3: Making the global variables static volatile to resolve the warnings.

Link to v1: https://lore.kernel.org/all/[email protected]/
Link to v2: https://lore.kernel.org/all/[email protected]/

 mm/kasan/kasan_test_c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/kasan/kasan_test_c.c +2 -3
index a181e4780d9d..7884b46a1e71 100644
@@ -45,8 +45,8 @@ static struct {
  * Some tests use these global variables to store return values from function
  * calls that could otherwise be eliminated by the compiler as dead code.
  */
-void *kasan_ptr_result;
-int kasan_int_result;
+static volatile void *kasan_ptr_result;
+static volatile int kasan_int_result;
 
 /* Probe for console output: obtains test_status lines of interest. */
 static void probe_console(void *ignore, const char *buf, size_t len)
--

2.34.1

--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20241011114537.35664-1-niharchaithanya%40gmail.com.

reviewer Reviewed-by on v3 1/1
#2 lore raw
In reply to Nihar Chaithanya
Quoted 5 lines · Nihar Chaithanya

Yes, when making the global variables kasan_ptr_result and kasan_int_result as static volatile, the warnings are removed and the variable and assignments are retained, but when just static is used I understand that it might be optimized.

For future reference: please write commit messages in a way that is readable standalone. I.e. without obscured references to the discussions on the previous versions of the patch. It's fine to give such references in itself, but you need to give enough context in the commit message to make it understandable without looking up those discussions.

Quoted 38 lines

Add a fix making the global varaibles - static volatile, removing the
warnings:
mm/kasan/kasan_test.c:36:6: warning: symbol 'kasan_ptr_result' was not declared. Should it be static? mm/kasan/kasan_test.c:37:5: warning: symbol 'kasan_int_result' was not declared. Should it be static?

---
v1 -> v2: Used the aproach of making global variables static to resolve the warnings instead of local declarations.

v2 -> v3: Making the global variables static volatile to resolve the warnings.

Link to v1: https://lore.kernel.org/all/[email protected]/
Link to v2: https://lore.kernel.org/all/[email protected]/

 mm/kasan/kasan_test_c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/kasan/kasan_test_c.c +2 -3
index a181e4780d9d..7884b46a1e71 100644
@@ -45,8 +45,8 @@ static struct {
  * Some tests use these global variables to store return values from function
  * calls that could otherwise be eliminated by the compiler as dead code.
  */
-void *kasan_ptr_result;
-int kasan_int_result;
+static volatile void *kasan_ptr_result;
+static volatile int kasan_int_result;
 
 /* Probe for console output: obtains test_status lines of interest. */
 static void probe_console(void *ignore, const char *buf, size_t len)
--
Quoted 2 lines

2.34.1

Thank you for fixing this!