* [PATCH v2] mm:kasan: fix sparse warnings: Should it be static?
@ 2024-10-11 9:53 Nihar Chaithanya
2024-10-11 10:35 ` Dmitry Vyukov
0 siblings, 1 reply; 2+ messages in thread
From: Nihar Chaithanya @ 2024-10-11 9:53 UTC (permalink / raw)
To: ryabinin.a.a
Cc: andreyknvl, kasan-dev, linux-kernel, skhan, Nihar Chaithanya,
kernel test robot
Sorry about that, thank you for the pointing it out, I understand now that
compiler might optimize and remove the assignments in case of local
variables where the global variables would be helpful, and making them as
static would be correct approach.
Add a fix making the global variables as static and doesn't trigger
the sparse 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?
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202312261010.o0lRiI9b-lkp@intel.com/
Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
---
v1 -> v2: Used the aproach of making global variables static to resolve the
warnings instead of local declarations.
Link to v1: https://lore.kernel.org/all/20241011033604.266084-1-niharchaithanya@gmail.com/
mm/kasan/kasan_test_c.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
index a181e4780d9d..4803a2c4d8a1 100644
--- a/mm/kasan/kasan_test_c.c
+++ b/mm/kasan/kasan_test_c.c
@@ -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 void *kasan_ptr_result;
+static 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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] mm:kasan: fix sparse warnings: Should it be static?
2024-10-11 9:53 [PATCH v2] mm:kasan: fix sparse warnings: Should it be static? Nihar Chaithanya
@ 2024-10-11 10:35 ` Dmitry Vyukov
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Vyukov @ 2024-10-11 10:35 UTC (permalink / raw)
To: Nihar Chaithanya
Cc: ryabinin.a.a, andreyknvl, kasan-dev, linux-kernel, skhan,
kernel test robot
On Fri, 11 Oct 2024 at 12:09, Nihar Chaithanya
<niharchaithanya@gmail.com> wrote:
>
> Sorry about that, thank you for the pointing it out, I understand now that
> compiler might optimize and remove the assignments in case of local
> variables where the global variables would be helpful, and making them as
> static would be correct approach.
It should be easy for the compiler to see all uses for a static var,
and in this case it's only assignments, so it becomes effectively
dead, and the compiler can remove the variable and all assignments.
Fighting the compiler in such cases when we want to preserve
non-observable behavior of the abstract C machine is hard.
"static volatile" may be a solution here. Does it help to remove the warnings?
> Add a fix making the global variables as static and doesn't trigger
> the sparse 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?
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202312261010.o0lRiI9b-lkp@intel.com/
> Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
> ---
> v1 -> v2: Used the aproach of making global variables static to resolve the
> warnings instead of local declarations.
>
> Link to v1: https://lore.kernel.org/all/20241011033604.266084-1-niharchaithanya@gmail.com/
>
> mm/kasan/kasan_test_c.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
> index a181e4780d9d..4803a2c4d8a1 100644
> --- a/mm/kasan/kasan_test_c.c
> +++ b/mm/kasan/kasan_test_c.c
> @@ -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 void *kasan_ptr_result;
> +static 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 kasan-dev+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20241011095259.17345-1-niharchaithanya%40gmail.com.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-11 10:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-11 9:53 [PATCH v2] mm:kasan: fix sparse warnings: Should it be static? Nihar Chaithanya
2024-10-11 10:35 ` Dmitry Vyukov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®