diff mbox series

[7/8] kselftest/arm64: mte: fix printf type warnings about pointers

Message ID 20240816153251.2833702-8-andre.przywara@arm.com (mailing list archive)
State New, archived
Headers show
Series kselftest/arm64: various compilation fixes | expand

Commit Message

Andre Przywara Aug. 16, 2024, 3:32 p.m. UTC
When printing the value of a pointer, we should not use an integer
format specifier, but the dedicated "%p" instead.

Fixes: e9b60476bea0 ("kselftest/arm64: Add utilities and a test to validate mte memory")
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 tools/testing/selftests/arm64/mte/check_buffer_fill.c | 4 ++--
 tools/testing/selftests/arm64/mte/mte_common_util.c   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Mark Brown Aug. 16, 2024, 4:32 p.m. UTC | #1
On Fri, Aug 16, 2024 at 04:32:50PM +0100, Andre Przywara wrote:
> When printing the value of a pointer, we should not use an integer
> format specifier, but the dedicated "%p" instead.
> 
> Fixes: e9b60476bea0 ("kselftest/arm64: Add utilities and a test to validate mte memory")

This is another one where calling it a fix seems like it's pushing it,
it's a modernisation rather than a correctness thing.  Otherwise

Reviewed-by: Mark Brown <broonie@kernel.org>
Andre Przywara Aug. 16, 2024, 4:59 p.m. UTC | #2
On Fri, 16 Aug 2024 17:32:39 +0100
Mark Brown <broonie@kernel.org> wrote:

> On Fri, Aug 16, 2024 at 04:32:50PM +0100, Andre Przywara wrote:
> > When printing the value of a pointer, we should not use an integer
> > format specifier, but the dedicated "%p" instead.
> > 
> > Fixes: e9b60476bea0 ("kselftest/arm64: Add utilities and a test to validate mte memory")  
> 
> This is another one where calling it a fix seems like it's pushing it,
> it's a modernisation rather than a correctness thing.

Well, I get compiler warnings, so I thought "fix" would be adequate. But
in general this confusion between pointers and integers sounds not good,
and not using %p looks like a genuine bug to me (though it's admittedly
working fine (TM) for now).

> Otherwise
> 
> Reviewed-by: Mark Brown <broonie@kernel.org>

Thanks for that!

Cheers,
Andre
Mark Brown Aug. 16, 2024, 5:12 p.m. UTC | #3
On Fri, Aug 16, 2024 at 05:59:08PM +0100, Andre Przywara wrote:
> Mark Brown <broonie@kernel.org> wrote:
> > On Fri, Aug 16, 2024 at 04:32:50PM +0100, Andre Przywara wrote:

> > > Fixes: e9b60476bea0 ("kselftest/arm64: Add utilities and a test to validate mte memory")  

> > This is another one where calling it a fix seems like it's pushing it,
> > it's a modernisation rather than a correctness thing.

> Well, I get compiler warnings, so I thought "fix" would be adequate. But
> in general this confusion between pointers and integers sounds not good,
> and not using %p looks like a genuine bug to me (though it's admittedly
> working fine (TM) for now).

Those compiler warnings are a relatively new thing - they won't have
been triggered when the code was written, and practically speaking on
arm64 it's more of a C language correctness thing than a meaningful
change.
diff mbox series

Patch

diff --git a/tools/testing/selftests/arm64/mte/check_buffer_fill.c b/tools/testing/selftests/arm64/mte/check_buffer_fill.c
index 1dbbbd47dd501..2ee7f114d7fa8 100644
--- a/tools/testing/selftests/arm64/mte/check_buffer_fill.c
+++ b/tools/testing/selftests/arm64/mte/check_buffer_fill.c
@@ -91,7 +91,7 @@  static int check_buffer_underflow_by_byte(int mem_type, int mode,
 		for (j = 0; j < sizes[i]; j++) {
 			if (ptr[j] != '1') {
 				err = true;
-				ksft_print_msg("Buffer is not filled at index:%d of ptr:0x%lx\n",
+				ksft_print_msg("Buffer is not filled at index:%d of ptr:0x%p\n",
 						j, ptr);
 				break;
 			}
@@ -189,7 +189,7 @@  static int check_buffer_overflow_by_byte(int mem_type, int mode,
 		for (j = 0; j < sizes[i]; j++) {
 			if (ptr[j] != '1') {
 				err = true;
-				ksft_print_msg("Buffer is not filled at index:%d of ptr:0x%lx\n",
+				ksft_print_msg("Buffer is not filled at index:%d of ptr:0x%p\n",
 						j, ptr);
 				break;
 			}
diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c
index 9380edca29c7d..17fbe5cfe4724 100644
--- a/tools/testing/selftests/arm64/mte/mte_common_util.c
+++ b/tools/testing/selftests/arm64/mte/mte_common_util.c
@@ -100,7 +100,7 @@  void *mte_insert_tags(void *ptr, size_t size)
 	int align_size;
 
 	if (!ptr || (unsigned long)(ptr) & MT_ALIGN_GRANULE) {
-		ksft_print_msg("FAIL: Addr=%lx: invalid\n", ptr);
+		ksft_print_msg("FAIL: Addr=%p: invalid\n", ptr);
 		return NULL;
 	}
 	align_size = MT_ALIGN_UP(size);
@@ -112,7 +112,7 @@  void *mte_insert_tags(void *ptr, size_t size)
 void mte_clear_tags(void *ptr, size_t size)
 {
 	if (!ptr || (unsigned long)(ptr) & MT_ALIGN_GRANULE) {
-		ksft_print_msg("FAIL: Addr=%lx: invalid\n", ptr);
+		ksft_print_msg("FAIL: Addr=%p: invalid\n", ptr);
 		return;
 	}
 	size = MT_ALIGN_UP(size);