public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm:kasan: fix sparse warnings: Should it be static?
@ 2024-10-11  3:36 Nihar Chaithanya
  2024-10-11  8:36 ` Dmitry Vyukov
  0 siblings, 1 reply; 2+ messages in thread
From: Nihar Chaithanya @ 2024-10-11  3:36 UTC (permalink / raw)
  To: ryabinin.a.a
  Cc: andreyknvl, kasan-dev, linux-kernel, skhan, Nihar Chaithanya,
	kernel test robot

The kernel test robot had found sparse warnings: Should it be static,
for the variables kasan_ptr_result and kasan_int_result. These were
declared globally and three functions in kasan_test_c.c use them currently.
Add them to be declared within these functions and remove the global
versions of these.

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>
---
 mm/kasan/kasan_test_c.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
index a181e4780d9d..d0d3a9eea80b 100644
--- a/mm/kasan/kasan_test_c.c
+++ b/mm/kasan/kasan_test_c.c
@@ -41,13 +41,6 @@ static struct {
 	bool async_fault;
 } test_status;
 
-/*
- * 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;
-
 /* Probe for console output: obtains test_status lines of interest. */
 static void probe_console(void *ignore, const char *buf, size_t len)
 {
@@ -1488,6 +1481,7 @@ static void kasan_memchr(struct kunit *test)
 {
 	char *ptr;
 	size_t size = 24;
+	void *kasan_ptr_result;
 
 	/*
 	 * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT.
@@ -1514,6 +1508,7 @@ static void kasan_memcmp(struct kunit *test)
 	char *ptr;
 	size_t size = 24;
 	int arr[9];
+	int kasan_int_result;
 
 	/*
 	 * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT.
@@ -1539,6 +1534,8 @@ static void kasan_strings(struct kunit *test)
 {
 	char *ptr;
 	size_t size = 24;
+	void *kasan_ptr_result;
+	int kasan_int_result;
 
 	/*
 	 * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT.
@@ -1585,6 +1582,8 @@ static void kasan_bitops_modify(struct kunit *test, int nr, void *addr)
 
 static void kasan_bitops_test_and_modify(struct kunit *test, int nr, void *addr)
 {
+	int kasan_int_result;
+
 	KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit(nr, addr));
 	KUNIT_EXPECT_KASAN_FAIL(test, __test_and_set_bit(nr, addr));
 	KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit_lock(nr, addr));
-- 
2.34.1


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

* Re: [PATCH] mm:kasan: fix sparse warnings: Should it be static?
  2024-10-11  3:36 [PATCH] mm:kasan: fix sparse warnings: Should it be static? Nihar Chaithanya
@ 2024-10-11  8:36 ` Dmitry Vyukov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Vyukov @ 2024-10-11  8:36 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 05:40, Nihar Chaithanya
<niharchaithanya@gmail.com> wrote:
>
> The kernel test robot had found sparse warnings: Should it be static,
> for the variables kasan_ptr_result and kasan_int_result. These were
> declared globally and three functions in kasan_test_c.c use them currently.
> Add them to be declared within these functions and remove the global
> versions of these.
>
> 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>
> ---
>  mm/kasan/kasan_test_c.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
> index a181e4780d9d..d0d3a9eea80b 100644
> --- a/mm/kasan/kasan_test_c.c
> +++ b/mm/kasan/kasan_test_c.c
> @@ -41,13 +41,6 @@ static struct {
>         bool async_fault;
>  } test_status;
>
> -/*
> - * Some tests use these global variables to store return values from function
> - * calls that could otherwise be eliminated by the compiler as dead code.

Doesn't this change break what's described in this comment?
Since we are assigning to a local var, I assume the compiler can
remove these assignments.

> - */
> -void *kasan_ptr_result;
> -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)
>  {
> @@ -1488,6 +1481,7 @@ static void kasan_memchr(struct kunit *test)
>  {
>         char *ptr;
>         size_t size = 24;
> +       void *kasan_ptr_result;
>
>         /*
>          * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT.
> @@ -1514,6 +1508,7 @@ static void kasan_memcmp(struct kunit *test)
>         char *ptr;
>         size_t size = 24;
>         int arr[9];
> +       int kasan_int_result;
>
>         /*
>          * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT.
> @@ -1539,6 +1534,8 @@ static void kasan_strings(struct kunit *test)
>  {
>         char *ptr;
>         size_t size = 24;
> +       void *kasan_ptr_result;
> +       int kasan_int_result;
>
>         /*
>          * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT.
> @@ -1585,6 +1582,8 @@ static void kasan_bitops_modify(struct kunit *test, int nr, void *addr)
>
>  static void kasan_bitops_test_and_modify(struct kunit *test, int nr, void *addr)
>  {
> +       int kasan_int_result;
> +
>         KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit(nr, addr));
>         KUNIT_EXPECT_KASAN_FAIL(test, __test_and_set_bit(nr, addr));
>         KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit_lock(nr, addr));
> --
> 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/20241011033604.266084-1-niharchaithanya%40gmail.com.

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

end of thread, other threads:[~2024-10-11  8:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-11  3:36 [PATCH] mm:kasan: fix sparse warnings: Should it be static? Nihar Chaithanya
2024-10-11  8:36 ` Dmitry Vyukov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox