linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions
@ 2024-02-21  9:27 David Gow
  2024-02-21  9:27 ` [PATCH 1/9] kunit: test: Log the correct filter string in executor_test David Gow
                   ` (10 more replies)
  0 siblings, 11 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

KUnit has several macros which accept a log message, which can contain
printf format specifiers. Some of these (the explicit log macros)
already use the __printf() gcc attribute to ensure the format specifiers
are valid, but those which could fail the test, and hence used
__kunit_do_failed_assertion() behind the scenes, did not.

These include:
- KUNIT_EXPECT_*_MSG()
- KUNIT_ASSERT_*_MSG()
- KUNIT_FAIL()

This series adds the __printf() attribute, and fixes all of the issues
uncovered. (Or, at least, all of those I could find with an x86_64
allyesconfig, and the default KUnit config on a number of other
architectures. Please test!)

The issues in question basically take the following forms:
- int / long / long long confusion: typically a type being updated, but
  the format string not.
- Use of integer format specifiers (%d/%u/%li/etc) for types like size_t
  or pointer differences (technically ptrdiff_t), which would only work
  on some architectures.
- Use of integer format specifiers in combination with PTR_ERR(), where
  %pe would make more sense.
- Use of empty messages which, whilst technically not incorrect, are not
  useful and trigger a gcc warning.

We'd like to get these (or equivalent) in for 6.9 if possible, so please
do take a look if possible.

Thanks,
-- David

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Closes: https://lore.kernel.org/linux-kselftest/CAHk-=wgJMOquDO5f8ShH1f4rzZwzApNVCw643m5-Yj+BfsFstA@mail.gmail.com/

David Gow (9):
  kunit: test: Log the correct filter string in executor_test
  lib/cmdline: Fix an invalid format specifier in an assertion msg
  lib: memcpy_kunit: Fix an invalid format specifier in an assertion msg
  time: test: Fix incorrect format specifier
  rtc: test: Fix invalid format specifier.
  net: test: Fix printf format specifier in skb_segment kunit test
  drm: tests: Fix invalid printf format specifiers in KUnit tests
  drm/xe/tests: Fix printf format specifiers in xe_migrate test
  kunit: Annotate _MSG assertion variants with gnu printf specifiers

 drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++++++-------
 drivers/gpu/drm/tests/drm_mm_test.c    |  6 +++---
 drivers/gpu/drm/xe/tests/xe_migrate.c  |  8 ++++----
 drivers/rtc/lib_test.c                 |  2 +-
 include/kunit/test.h                   | 12 ++++++------
 kernel/time/time_test.c                |  2 +-
 lib/cmdline_kunit.c                    |  2 +-
 lib/kunit/executor_test.c              |  2 +-
 lib/memcpy_kunit.c                     |  4 ++--
 net/core/gso_test.c                    |  2 +-
 10 files changed, 27 insertions(+), 27 deletions(-)

-- 
2.44.0.rc0.258.g7320e95886-goog


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

* [PATCH 1/9] kunit: test: Log the correct filter string in executor_test
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
@ 2024-02-21  9:27 ` David Gow
  2024-02-21 13:25   ` Guenter Roeck
                     ` (3 more replies)
  2024-02-21  9:27 ` [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg David Gow
                   ` (9 subsequent siblings)
  10 siblings, 4 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

KUnit's executor_test logs the filter string in KUNIT_ASSERT_EQ_MSG(),
but passed a random character from the filter, rather than the whole
string.

This was found by annotating KUNIT_ASSERT_EQ_MSG() to let gcc validate
the format string.

Fixes: 76066f93f1df ("kunit: add tests for filtering attributes")
Signed-off-by: David Gow <davidgow@google.com>
---
 lib/kunit/executor_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
index 22d4ee86dbed..3f7f967e3688 100644
--- a/lib/kunit/executor_test.c
+++ b/lib/kunit/executor_test.c
@@ -129,7 +129,7 @@ static void parse_filter_attr_test(struct kunit *test)
 			GFP_KERNEL);
 	for (j = 0; j < filter_count; j++) {
 		parsed_filters[j] = kunit_next_attr_filter(&filter, &err);
-		KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter '%s'", filters[j]);
+		KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter from '%s'", filters);
 	}
 
 	KUNIT_EXPECT_STREQ(test, kunit_attr_filter_name(parsed_filters[0]), "speed");
-- 
2.44.0.rc0.258.g7320e95886-goog


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

* [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
  2024-02-21  9:27 ` [PATCH 1/9] kunit: test: Log the correct filter string in executor_test David Gow
@ 2024-02-21  9:27 ` David Gow
  2024-02-21 13:25   ` Guenter Roeck
  2024-02-21 20:10   ` Justin Stitt
  2024-02-21  9:27 ` [PATCH 3/9] lib: memcpy_kunit: " David Gow
                   ` (8 subsequent siblings)
  10 siblings, 2 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

The correct format specifier for p - n (both p and n are pointers) is
%td, as the type should be ptrdiff_t.

This was discovered by annotating KUnit assertion macros with gcc's
printf specifier, but note that gcc incorrectly suggested a %d or %ld
specifier (depending on the pointer size of the architecture being
built).

Fixes: 0ea09083116d ("lib/cmdline: Allow get_options() to take 0 to validate the input")
Signed-off-by: David Gow <davidgow@google.com>
---
 lib/cmdline_kunit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/cmdline_kunit.c b/lib/cmdline_kunit.c
index d4572dbc9145..705b82736be0 100644
--- a/lib/cmdline_kunit.c
+++ b/lib/cmdline_kunit.c
@@ -124,7 +124,7 @@ static void cmdline_do_one_range_test(struct kunit *test, const char *in,
 			    n, e[0], r[0]);
 
 	p = memchr_inv(&r[1], 0, sizeof(r) - sizeof(r[0]));
-	KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %u out of bound", n, p - r);
+	KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %td out of bound", n, p - r);
 }
 
 static void cmdline_test_range(struct kunit *test)
-- 
2.44.0.rc0.258.g7320e95886-goog


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

* [PATCH 3/9] lib: memcpy_kunit: Fix an invalid format specifier in an assertion msg
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
  2024-02-21  9:27 ` [PATCH 1/9] kunit: test: Log the correct filter string in executor_test David Gow
  2024-02-21  9:27 ` [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg David Gow
@ 2024-02-21  9:27 ` David Gow
  2024-02-21 13:25   ` Guenter Roeck
  2024-02-21 21:05   ` Justin Stitt
  2024-02-21  9:27 ` [PATCH 4/9] time: test: Fix incorrect format specifier David Gow
                   ` (7 subsequent siblings)
  10 siblings, 2 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

The 'i' passed as an assertion message is a size_t, so should use '%zu',
not '%d'.

This was found by annotating the _MSG() variants of KUnit's assertions
to let gcc validate the format strings.

Fixes: bb95ebbe89a7 ("lib: Introduce CONFIG_MEMCPY_KUNIT_TEST")
Signed-off-by: David Gow <davidgow@google.com>
---
 lib/memcpy_kunit.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/memcpy_kunit.c b/lib/memcpy_kunit.c
index 440aee705ccc..30e00ef0bf2e 100644
--- a/lib/memcpy_kunit.c
+++ b/lib/memcpy_kunit.c
@@ -32,7 +32,7 @@ struct some_bytes {
 	BUILD_BUG_ON(sizeof(instance.data) != 32);	\
 	for (size_t i = 0; i < sizeof(instance.data); i++) {	\
 		KUNIT_ASSERT_EQ_MSG(test, instance.data[i], v, \
-			"line %d: '%s' not initialized to 0x%02x @ %d (saw 0x%02x)\n", \
+			"line %d: '%s' not initialized to 0x%02x @ %zu (saw 0x%02x)\n", \
 			__LINE__, #instance, v, i, instance.data[i]);	\
 	}	\
 } while (0)
@@ -41,7 +41,7 @@ struct some_bytes {
 	BUILD_BUG_ON(sizeof(one) != sizeof(two)); \
 	for (size_t i = 0; i < sizeof(one); i++) {	\
 		KUNIT_EXPECT_EQ_MSG(test, one.data[i], two.data[i], \
-			"line %d: %s.data[%d] (0x%02x) != %s.data[%d] (0x%02x)\n", \
+			"line %d: %s.data[%zu] (0x%02x) != %s.data[%zu] (0x%02x)\n", \
 			__LINE__, #one, i, one.data[i], #two, i, two.data[i]); \
 	}	\
 	kunit_info(test, "ok: " TEST_OP "() " name "\n");	\
-- 
2.44.0.rc0.258.g7320e95886-goog


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

* [PATCH 4/9] time: test: Fix incorrect format specifier
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
                   ` (2 preceding siblings ...)
  2024-02-21  9:27 ` [PATCH 3/9] lib: memcpy_kunit: " David Gow
@ 2024-02-21  9:27 ` David Gow
  2024-02-21 13:25   ` Guenter Roeck
  2024-02-21 21:06   ` Justin Stitt
  2024-02-21  9:27 ` [PATCH 5/9] rtc: test: Fix invalid " David Gow
                   ` (6 subsequent siblings)
  10 siblings, 2 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

'days' is a s64 (from div_s64), and so should use a %lld specifier.

This was found by extending KUnit's assertion macros to use gcc's
__printf attribute.

Fixes: 276010551664 ("time: Improve performance of time64_to_tm()")
Signed-off-by: David Gow <davidgow@google.com>
---
 kernel/time/time_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/time_test.c b/kernel/time/time_test.c
index ca058c8af6ba..3e5d422dd15c 100644
--- a/kernel/time/time_test.c
+++ b/kernel/time/time_test.c
@@ -73,7 +73,7 @@ static void time64_to_tm_test_date_range(struct kunit *test)
 
 		days = div_s64(secs, 86400);
 
-		#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %ld", \
+		#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %lld", \
 			year, month, mdday, yday, days
 
 		KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);
-- 
2.44.0.rc0.258.g7320e95886-goog


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

* [PATCH 5/9] rtc: test: Fix invalid format specifier.
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
                   ` (3 preceding siblings ...)
  2024-02-21  9:27 ` [PATCH 4/9] time: test: Fix incorrect format specifier David Gow
@ 2024-02-21  9:27 ` David Gow
  2024-02-21 13:26   ` Guenter Roeck
                     ` (2 more replies)
  2024-02-21  9:27 ` [PATCH 6/9] net: test: Fix printf format specifier in skb_segment kunit test David Gow
                   ` (5 subsequent siblings)
  10 siblings, 3 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

'days' is a s64 (from div_s64), and so should use a %lld specifier.

This was found by extending KUnit's assertion macros to use gcc's
__printf attribute.

Fixes: 1d1bb12a8b18 ("rtc: Improve performance of rtc_time64_to_tm(). Add tests.")
Signed-off-by: David Gow <davidgow@google.com>
---
 drivers/rtc/lib_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/lib_test.c b/drivers/rtc/lib_test.c
index d5caf36c56cd..225c859d6da5 100644
--- a/drivers/rtc/lib_test.c
+++ b/drivers/rtc/lib_test.c
@@ -54,7 +54,7 @@ static void rtc_time64_to_tm_test_date_range(struct kunit *test)
 
 		days = div_s64(secs, 86400);
 
-		#define FAIL_MSG "%d/%02d/%02d (%2d) : %ld", \
+		#define FAIL_MSG "%d/%02d/%02d (%2d) : %lld", \
 			year, month, mday, yday, days
 
 		KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);
-- 
2.44.0.rc0.258.g7320e95886-goog


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

* [PATCH 6/9] net: test: Fix printf format specifier in skb_segment kunit test
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
                   ` (4 preceding siblings ...)
  2024-02-21  9:27 ` [PATCH 5/9] rtc: test: Fix invalid " David Gow
@ 2024-02-21  9:27 ` David Gow
  2024-02-21 13:26   ` Guenter Roeck
  2024-02-21 21:26   ` Justin Stitt
  2024-02-21  9:27 ` [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests David Gow
                   ` (4 subsequent siblings)
  10 siblings, 2 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

KUNIT_FAIL() accepts a printf-style format string, but previously did
not let gcc validate it with the __printf() attribute. The use of %lld
for the result of PTR_ERR() is not correct.

Instead, use %pe and pass the actual error pointer. printk() will format
it correctly (and give a symbolic name rather than a number if
available, which should make the output more readable, too).

Fixes: b3098d32ed6e ("net: add skb_segment kunit test")
Signed-off-by: David Gow <davidgow@google.com>
---
 net/core/gso_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/gso_test.c b/net/core/gso_test.c
index 4c2e77bd12f4..358c44680d91 100644
--- a/net/core/gso_test.c
+++ b/net/core/gso_test.c
@@ -225,7 +225,7 @@ static void gso_test_func(struct kunit *test)
 
 	segs = skb_segment(skb, features);
 	if (IS_ERR(segs)) {
-		KUNIT_FAIL(test, "segs error %lld", PTR_ERR(segs));
+		KUNIT_FAIL(test, "segs error %pe", segs);
 		goto free_gso_skb;
 	} else if (!segs) {
 		KUNIT_FAIL(test, "no segments");
-- 
2.44.0.rc0.258.g7320e95886-goog


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

* [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
                   ` (5 preceding siblings ...)
  2024-02-21  9:27 ` [PATCH 6/9] net: test: Fix printf format specifier in skb_segment kunit test David Gow
@ 2024-02-21  9:27 ` David Gow
  2024-02-21 10:21   ` Matthew Auld
                     ` (3 more replies)
  2024-02-21  9:27 ` [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test David Gow
                   ` (3 subsequent siblings)
  10 siblings, 4 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
which was then updated to be an 'unsigned long' to avoid 64-bit
multiplication division helpers.

However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
'%d' or '%llu' format specifiers, the former of which is always wrong,
and the latter is no longer correct now that ps is no longer a u64. Fix
these to all use '%lu'.

Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
message. gcc warns if a printf format string is empty (apparently), so
give these some more detailed error messages, which should be more
useful anyway.

Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit targets")
Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
Signed-off-by: David Gow <davidgow@google.com>
---
 drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++++++-------
 drivers/gpu/drm/tests/drm_mm_test.c    |  6 +++---
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c
index 8a464f7f4c61..3dbfa3078449 100644
--- a/drivers/gpu/drm/tests/drm_buddy_test.c
+++ b/drivers/gpu/drm/tests/drm_buddy_test.c
@@ -55,30 +55,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
 		KUNIT_ASSERT_FALSE_MSG(test,
 				       drm_buddy_alloc_blocks(&mm, 0, mm_size,
 							      ps, ps, list, 0),
-				       "buddy_alloc hit an error size=%d\n",
+				       "buddy_alloc hit an error size=%lu\n",
 				       ps);
 	} while (++i < n_pages);
 
 	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
 							   3 * ps, ps, &allocated,
 							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-			       "buddy_alloc didn't error size=%d\n", 3 * ps);
+			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
 
 	drm_buddy_free_list(&mm, &middle);
 	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
 							   3 * ps, ps, &allocated,
 							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
+			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
 	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
 							   2 * ps, ps, &allocated,
 							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-			       "buddy_alloc didn't error size=%llu\n", 2 * ps);
+			       "buddy_alloc didn't error size=%lu\n", 2 * ps);
 
 	drm_buddy_free_list(&mm, &right);
 	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
 							   3 * ps, ps, &allocated,
 							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
+			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
 	/*
 	 * At this point we should have enough contiguous space for 2 blocks,
 	 * however they are never buddies (since we freed middle and right) so
@@ -87,13 +87,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
 	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
 							    2 * ps, ps, &allocated,
 							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-			       "buddy_alloc hit an error size=%d\n", 2 * ps);
+			       "buddy_alloc hit an error size=%lu\n", 2 * ps);
 
 	drm_buddy_free_list(&mm, &left);
 	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
 							    3 * ps, ps, &allocated,
 							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-			       "buddy_alloc hit an error size=%d\n", 3 * ps);
+			       "buddy_alloc hit an error size=%lu\n", 3 * ps);
 
 	total = 0;
 	list_for_each_entry(block, &allocated, link)
diff --git a/drivers/gpu/drm/tests/drm_mm_test.c b/drivers/gpu/drm/tests/drm_mm_test.c
index 1eb0c304f960..f37c0d765865 100644
--- a/drivers/gpu/drm/tests/drm_mm_test.c
+++ b/drivers/gpu/drm/tests/drm_mm_test.c
@@ -157,7 +157,7 @@ static void drm_test_mm_init(struct kunit *test)
 
 	/* After creation, it should all be one massive hole */
 	if (!assert_one_hole(test, &mm, 0, size)) {
-		KUNIT_FAIL(test, "");
+		KUNIT_FAIL(test, "mm not one hole on creation");
 		goto out;
 	}
 
@@ -171,14 +171,14 @@ static void drm_test_mm_init(struct kunit *test)
 
 	/* After filling the range entirely, there should be no holes */
 	if (!assert_no_holes(test, &mm)) {
-		KUNIT_FAIL(test, "");
+		KUNIT_FAIL(test, "mm has holes when filled");
 		goto out;
 	}
 
 	/* And then after emptying it again, the massive hole should be back */
 	drm_mm_remove_node(&tmp);
 	if (!assert_one_hole(test, &mm, 0, size)) {
-		KUNIT_FAIL(test, "");
+		KUNIT_FAIL(test, "mm does not have single hole after emptying");
 		goto out;
 	}
 
-- 
2.44.0.rc0.258.g7320e95886-goog


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

* [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
                   ` (6 preceding siblings ...)
  2024-02-21  9:27 ` [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests David Gow
@ 2024-02-21  9:27 ` David Gow
  2024-02-21 13:26   ` Guenter Roeck
                     ` (2 more replies)
  2024-02-21  9:27 ` [PATCH 9/9] kunit: Annotate _MSG assertion variants with gnu printf specifiers David Gow
                   ` (2 subsequent siblings)
  10 siblings, 3 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

KUNIT_FAIL() is used to fail the xe_migrate test when an error occurs.
However, there's a mismatch in the format specifier: '%li' is used to
log 'err', which is an 'int'.

Use '%i' instead of '%li', and for the case where we're printing an
error pointer, just use '%pe', instead of extracting the error code
manually with PTR_ERR(). (This also results in a nicer output when the
error code is known.)

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Signed-off-by: David Gow <davidgow@google.com>
---
 drivers/gpu/drm/xe/tests/xe_migrate.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/xe/tests/xe_migrate.c b/drivers/gpu/drm/xe/tests/xe_migrate.c
index a6523df0f1d3..c347e2c29f81 100644
--- a/drivers/gpu/drm/xe/tests/xe_migrate.c
+++ b/drivers/gpu/drm/xe/tests/xe_migrate.c
@@ -114,21 +114,21 @@ static void test_copy(struct xe_migrate *m, struct xe_bo *bo,
 						   region |
 						   XE_BO_NEEDS_CPU_ACCESS);
 	if (IS_ERR(remote)) {
-		KUNIT_FAIL(test, "Failed to allocate remote bo for %s: %li\n",
-			   str, PTR_ERR(remote));
+		KUNIT_FAIL(test, "Failed to allocate remote bo for %s: %pe\n",
+			   str, remote);
 		return;
 	}
 
 	err = xe_bo_validate(remote, NULL, false);
 	if (err) {
-		KUNIT_FAIL(test, "Failed to validate system bo for %s: %li\n",
+		KUNIT_FAIL(test, "Failed to validate system bo for %s: %i\n",
 			   str, err);
 		goto out_unlock;
 	}
 
 	err = xe_bo_vmap(remote);
 	if (err) {
-		KUNIT_FAIL(test, "Failed to vmap system bo for %s: %li\n",
+		KUNIT_FAIL(test, "Failed to vmap system bo for %s: %i\n",
 			   str, err);
 		goto out_unlock;
 	}
-- 
2.44.0.rc0.258.g7320e95886-goog


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

* [PATCH 9/9] kunit: Annotate _MSG assertion variants with gnu printf specifiers
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
                   ` (7 preceding siblings ...)
  2024-02-21  9:27 ` [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test David Gow
@ 2024-02-21  9:27 ` David Gow
  2024-02-21 13:26   ` Guenter Roeck
  2024-02-21 20:02   ` Justin Stitt
  2024-02-22 14:23 ` [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions Shuah Khan
  2024-02-27 23:32 ` Shuah Khan
  10 siblings, 2 replies; 43+ messages in thread
From: David Gow @ 2024-02-21  9:27 UTC (permalink / raw)
  To: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: David Gow, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

KUnit's assertion macros have variants which accept a printf format
string, to allow tests to specify a more detailed message on failure.
These (and the related KUNIT_FAIL() macro) ultimately wrap the
__kunit_do_failed_assertion() function, which accepted a printf format
specifier, but did not have the __printf attribute, so gcc couldn't warn
on incorrect agruments.

It turns out there were quite a few tests with such incorrect arguments.

Add the __printf() specifier now that we've fixed these errors, to
prevent them from recurring.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: David Gow <davidgow@google.com>
---
 include/kunit/test.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index fcb4a4940ace..61637ef32302 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -579,12 +579,12 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
 
 void __noreturn __kunit_abort(struct kunit *test);
 
-void __kunit_do_failed_assertion(struct kunit *test,
-			       const struct kunit_loc *loc,
-			       enum kunit_assert_type type,
-			       const struct kunit_assert *assert,
-			       assert_format_t assert_format,
-			       const char *fmt, ...);
+void __printf(6, 7) __kunit_do_failed_assertion(struct kunit *test,
+						const struct kunit_loc *loc,
+						enum kunit_assert_type type,
+						const struct kunit_assert *assert,
+						assert_format_t assert_format,
+						const char *fmt, ...);
 
 #define _KUNIT_FAILED(test, assert_type, assert_class, assert_format, INITIALIZER, fmt, ...) do { \
 	static const struct kunit_loc __loc = KUNIT_CURRENT_LOC;	       \
-- 
2.44.0.rc0.258.g7320e95886-goog


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

* Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests
  2024-02-21  9:27 ` [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests David Gow
@ 2024-02-21 10:21   ` Matthew Auld
  2024-02-21 10:45   ` Christian König
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 43+ messages in thread
From: Matthew Auld @ 2024-02-21 10:21 UTC (permalink / raw)
  To: David Gow, Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo
  Cc: Brendan Higgins, Daniel Latypov, Stephen Boyd, David Airlie,
	Maxime Ripard, David S . Miller, dri-devel, linux-kernel,
	intel-xe, linux-rtc, linux-kselftest, kunit-dev, linux-hardening,
	netdev

On 21/02/2024 09:27, David Gow wrote:
> The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
> which was then updated to be an 'unsigned long' to avoid 64-bit
> multiplication division helpers.
> 
> However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
> '%d' or '%llu' format specifiers, the former of which is always wrong,
> and the latter is no longer correct now that ps is no longer a u64. Fix
> these to all use '%lu'.
> 
> Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
> message. gcc warns if a printf format string is empty (apparently), so
> give these some more detailed error messages, which should be more
> useful anyway.
> 
> Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
> Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit targets")
> Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
> Signed-off-by: David Gow <davidgow@google.com>
> ---
>   drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++++++-------
>   drivers/gpu/drm/tests/drm_mm_test.c    |  6 +++---
>   2 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c
> index 8a464f7f4c61..3dbfa3078449 100644
> --- a/drivers/gpu/drm/tests/drm_buddy_test.c
> +++ b/drivers/gpu/drm/tests/drm_buddy_test.c
> @@ -55,30 +55,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
>   		KUNIT_ASSERT_FALSE_MSG(test,
>   				       drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							      ps, ps, list, 0),
> -				       "buddy_alloc hit an error size=%d\n",
> +				       "buddy_alloc hit an error size=%lu\n",
>   				       ps);
>   	} while (++i < n_pages);
>   
>   	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							   3 * ps, ps, &allocated,
>   							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%d\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>   
>   	drm_buddy_free_list(&mm, &middle);
>   	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							   3 * ps, ps, &allocated,
>   							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>   	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							   2 * ps, ps, &allocated,
>   							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 2 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 2 * ps);
>   
>   	drm_buddy_free_list(&mm, &right);
>   	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							   3 * ps, ps, &allocated,
>   							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>   	/*
>   	 * At this point we should have enough contiguous space for 2 blocks,
>   	 * however they are never buddies (since we freed middle and right) so
> @@ -87,13 +87,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
>   	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							    2 * ps, ps, &allocated,
>   							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc hit an error size=%d\n", 2 * ps);
> +			       "buddy_alloc hit an error size=%lu\n", 2 * ps);
>   
>   	drm_buddy_free_list(&mm, &left);
>   	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							    3 * ps, ps, &allocated,
>   							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc hit an error size=%d\n", 3 * ps);
> +			       "buddy_alloc hit an error size=%lu\n", 3 * ps);

There was also a fix for this in: 335126937753 ("drm/tests/drm_buddy: 
fix 32b build"), but there everything was made u32.

Reviewed-by: Matthew Auld <matthew.auld@intel.com>

>   
>   	total = 0;
>   	list_for_each_entry(block, &allocated, link)
> diff --git a/drivers/gpu/drm/tests/drm_mm_test.c b/drivers/gpu/drm/tests/drm_mm_test.c
> index 1eb0c304f960..f37c0d765865 100644
> --- a/drivers/gpu/drm/tests/drm_mm_test.c
> +++ b/drivers/gpu/drm/tests/drm_mm_test.c
> @@ -157,7 +157,7 @@ static void drm_test_mm_init(struct kunit *test)
>   
>   	/* After creation, it should all be one massive hole */
>   	if (!assert_one_hole(test, &mm, 0, size)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm not one hole on creation");
>   		goto out;
>   	}
>   
> @@ -171,14 +171,14 @@ static void drm_test_mm_init(struct kunit *test)
>   
>   	/* After filling the range entirely, there should be no holes */
>   	if (!assert_no_holes(test, &mm)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm has holes when filled");
>   		goto out;
>   	}
>   
>   	/* And then after emptying it again, the massive hole should be back */
>   	drm_mm_remove_node(&tmp);
>   	if (!assert_one_hole(test, &mm, 0, size)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm does not have single hole after emptying");
>   		goto out;
>   	}
>   

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

* Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests
  2024-02-21  9:27 ` [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests David Gow
  2024-02-21 10:21   ` Matthew Auld
@ 2024-02-21 10:45   ` Christian König
  2024-02-21 13:26   ` Guenter Roeck
  2024-02-21 21:29   ` Justin Stitt
  3 siblings, 0 replies; 43+ messages in thread
From: Christian König @ 2024-02-21 10:45 UTC (permalink / raw)
  To: David Gow, Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo
  Cc: Brendan Higgins, Daniel Latypov, Stephen Boyd, David Airlie,
	Maxime Ripard, David S . Miller, dri-devel, linux-kernel,
	intel-xe, linux-rtc, linux-kselftest, kunit-dev, linux-hardening,
	netdev

Am 21.02.24 um 10:27 schrieb David Gow:
> The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
> which was then updated to be an 'unsigned long' to avoid 64-bit
> multiplication division helpers.
>
> However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
> '%d' or '%llu' format specifiers, the former of which is always wrong,
> and the latter is no longer correct now that ps is no longer a u64. Fix
> these to all use '%lu'.
>
> Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
> message. gcc warns if a printf format string is empty (apparently), so
> give these some more detailed error messages, which should be more
> useful anyway.
>
> Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
> Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit targets")
> Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
> Signed-off-by: David Gow <davidgow@google.com>

Acked-by: Christian König <christian.koenig@amd.com>

Ping me if you want this patch pushed upstream through the DRM tree.

Christian.

> ---
>   drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++++++-------
>   drivers/gpu/drm/tests/drm_mm_test.c    |  6 +++---
>   2 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c
> index 8a464f7f4c61..3dbfa3078449 100644
> --- a/drivers/gpu/drm/tests/drm_buddy_test.c
> +++ b/drivers/gpu/drm/tests/drm_buddy_test.c
> @@ -55,30 +55,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
>   		KUNIT_ASSERT_FALSE_MSG(test,
>   				       drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							      ps, ps, list, 0),
> -				       "buddy_alloc hit an error size=%d\n",
> +				       "buddy_alloc hit an error size=%lu\n",
>   				       ps);
>   	} while (++i < n_pages);
>   
>   	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							   3 * ps, ps, &allocated,
>   							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%d\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>   
>   	drm_buddy_free_list(&mm, &middle);
>   	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							   3 * ps, ps, &allocated,
>   							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>   	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							   2 * ps, ps, &allocated,
>   							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 2 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 2 * ps);
>   
>   	drm_buddy_free_list(&mm, &right);
>   	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							   3 * ps, ps, &allocated,
>   							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>   	/*
>   	 * At this point we should have enough contiguous space for 2 blocks,
>   	 * however they are never buddies (since we freed middle and right) so
> @@ -87,13 +87,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
>   	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							    2 * ps, ps, &allocated,
>   							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc hit an error size=%d\n", 2 * ps);
> +			       "buddy_alloc hit an error size=%lu\n", 2 * ps);
>   
>   	drm_buddy_free_list(&mm, &left);
>   	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>   							    3 * ps, ps, &allocated,
>   							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc hit an error size=%d\n", 3 * ps);
> +			       "buddy_alloc hit an error size=%lu\n", 3 * ps);
>   
>   	total = 0;
>   	list_for_each_entry(block, &allocated, link)
> diff --git a/drivers/gpu/drm/tests/drm_mm_test.c b/drivers/gpu/drm/tests/drm_mm_test.c
> index 1eb0c304f960..f37c0d765865 100644
> --- a/drivers/gpu/drm/tests/drm_mm_test.c
> +++ b/drivers/gpu/drm/tests/drm_mm_test.c
> @@ -157,7 +157,7 @@ static void drm_test_mm_init(struct kunit *test)
>   
>   	/* After creation, it should all be one massive hole */
>   	if (!assert_one_hole(test, &mm, 0, size)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm not one hole on creation");
>   		goto out;
>   	}
>   
> @@ -171,14 +171,14 @@ static void drm_test_mm_init(struct kunit *test)
>   
>   	/* After filling the range entirely, there should be no holes */
>   	if (!assert_no_holes(test, &mm)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm has holes when filled");
>   		goto out;
>   	}
>   
>   	/* And then after emptying it again, the massive hole should be back */
>   	drm_mm_remove_node(&tmp);
>   	if (!assert_one_hole(test, &mm, 0, size)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm does not have single hole after emptying");
>   		goto out;
>   	}
>   


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

* Re: [PATCH 1/9] kunit: test: Log the correct filter string in executor_test
  2024-02-21  9:27 ` [PATCH 1/9] kunit: test: Log the correct filter string in executor_test David Gow
@ 2024-02-21 13:25   ` Guenter Roeck
  2024-02-21 20:04   ` Justin Stitt
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 43+ messages in thread
From: Guenter Roeck @ 2024-02-21 13:25 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:14PM +0800, David Gow wrote:
> KUnit's executor_test logs the filter string in KUNIT_ASSERT_EQ_MSG(),
> but passed a random character from the filter, rather than the whole
> string.
> 
> This was found by annotating KUNIT_ASSERT_EQ_MSG() to let gcc validate
> the format string.
> 
> Fixes: 76066f93f1df ("kunit: add tests for filtering attributes")
> Signed-off-by: David Gow <davidgow@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  lib/kunit/executor_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
> index 22d4ee86dbed..3f7f967e3688 100644
> --- a/lib/kunit/executor_test.c
> +++ b/lib/kunit/executor_test.c
> @@ -129,7 +129,7 @@ static void parse_filter_attr_test(struct kunit *test)
>  			GFP_KERNEL);
>  	for (j = 0; j < filter_count; j++) {
>  		parsed_filters[j] = kunit_next_attr_filter(&filter, &err);
> -		KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter '%s'", filters[j]);
> +		KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter from '%s'", filters);
>  	}
>  
>  	KUNIT_EXPECT_STREQ(test, kunit_attr_filter_name(parsed_filters[0]), "speed");
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 

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

* Re: [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg
  2024-02-21  9:27 ` [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg David Gow
@ 2024-02-21 13:25   ` Guenter Roeck
  2024-02-21 20:10   ` Justin Stitt
  1 sibling, 0 replies; 43+ messages in thread
From: Guenter Roeck @ 2024-02-21 13:25 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:15PM +0800, David Gow wrote:
> The correct format specifier for p - n (both p and n are pointers) is
> %td, as the type should be ptrdiff_t.
> 
> This was discovered by annotating KUnit assertion macros with gcc's
> printf specifier, but note that gcc incorrectly suggested a %d or %ld
> specifier (depending on the pointer size of the architecture being
> built).
> 
> Fixes: 0ea09083116d ("lib/cmdline: Allow get_options() to take 0 to validate the input")
> Signed-off-by: David Gow <davidgow@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  lib/cmdline_kunit.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/cmdline_kunit.c b/lib/cmdline_kunit.c
> index d4572dbc9145..705b82736be0 100644
> --- a/lib/cmdline_kunit.c
> +++ b/lib/cmdline_kunit.c
> @@ -124,7 +124,7 @@ static void cmdline_do_one_range_test(struct kunit *test, const char *in,
>  			    n, e[0], r[0]);
>  
>  	p = memchr_inv(&r[1], 0, sizeof(r) - sizeof(r[0]));
> -	KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %u out of bound", n, p - r);
> +	KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %td out of bound", n, p - r);
>  }
>  
>  static void cmdline_test_range(struct kunit *test)
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 

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

* Re: [PATCH 3/9] lib: memcpy_kunit: Fix an invalid format specifier in an assertion msg
  2024-02-21  9:27 ` [PATCH 3/9] lib: memcpy_kunit: " David Gow
@ 2024-02-21 13:25   ` Guenter Roeck
  2024-02-21 21:05   ` Justin Stitt
  1 sibling, 0 replies; 43+ messages in thread
From: Guenter Roeck @ 2024-02-21 13:25 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:16PM +0800, David Gow wrote:
> The 'i' passed as an assertion message is a size_t, so should use '%zu',
> not '%d'.
> 
> This was found by annotating the _MSG() variants of KUnit's assertions
> to let gcc validate the format strings.
> 
> Fixes: bb95ebbe89a7 ("lib: Introduce CONFIG_MEMCPY_KUNIT_TEST")
> Signed-off-by: David Gow <davidgow@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  lib/memcpy_kunit.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/memcpy_kunit.c b/lib/memcpy_kunit.c
> index 440aee705ccc..30e00ef0bf2e 100644
> --- a/lib/memcpy_kunit.c
> +++ b/lib/memcpy_kunit.c
> @@ -32,7 +32,7 @@ struct some_bytes {
>  	BUILD_BUG_ON(sizeof(instance.data) != 32);	\
>  	for (size_t i = 0; i < sizeof(instance.data); i++) {	\
>  		KUNIT_ASSERT_EQ_MSG(test, instance.data[i], v, \
> -			"line %d: '%s' not initialized to 0x%02x @ %d (saw 0x%02x)\n", \
> +			"line %d: '%s' not initialized to 0x%02x @ %zu (saw 0x%02x)\n", \
>  			__LINE__, #instance, v, i, instance.data[i]);	\
>  	}	\
>  } while (0)
> @@ -41,7 +41,7 @@ struct some_bytes {
>  	BUILD_BUG_ON(sizeof(one) != sizeof(two)); \
>  	for (size_t i = 0; i < sizeof(one); i++) {	\
>  		KUNIT_EXPECT_EQ_MSG(test, one.data[i], two.data[i], \
> -			"line %d: %s.data[%d] (0x%02x) != %s.data[%d] (0x%02x)\n", \
> +			"line %d: %s.data[%zu] (0x%02x) != %s.data[%zu] (0x%02x)\n", \
>  			__LINE__, #one, i, one.data[i], #two, i, two.data[i]); \
>  	}	\
>  	kunit_info(test, "ok: " TEST_OP "() " name "\n");	\
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 

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

* Re: [PATCH 4/9] time: test: Fix incorrect format specifier
  2024-02-21  9:27 ` [PATCH 4/9] time: test: Fix incorrect format specifier David Gow
@ 2024-02-21 13:25   ` Guenter Roeck
  2024-02-21 21:06   ` Justin Stitt
  1 sibling, 0 replies; 43+ messages in thread
From: Guenter Roeck @ 2024-02-21 13:25 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:17PM +0800, David Gow wrote:
> 'days' is a s64 (from div_s64), and so should use a %lld specifier.
> 
> This was found by extending KUnit's assertion macros to use gcc's
> __printf attribute.
> 
> Fixes: 276010551664 ("time: Improve performance of time64_to_tm()")
> Signed-off-by: David Gow <davidgow@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  kernel/time/time_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/time/time_test.c b/kernel/time/time_test.c
> index ca058c8af6ba..3e5d422dd15c 100644
> --- a/kernel/time/time_test.c
> +++ b/kernel/time/time_test.c
> @@ -73,7 +73,7 @@ static void time64_to_tm_test_date_range(struct kunit *test)
>  
>  		days = div_s64(secs, 86400);
>  
> -		#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %ld", \
> +		#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %lld", \
>  			year, month, mdday, yday, days
>  
>  		KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 

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

* Re: [PATCH 5/9] rtc: test: Fix invalid format specifier.
  2024-02-21  9:27 ` [PATCH 5/9] rtc: test: Fix invalid " David Gow
@ 2024-02-21 13:26   ` Guenter Roeck
  2024-02-21 21:06   ` Justin Stitt
  2024-02-27 20:32   ` Alexandre Belloni
  2 siblings, 0 replies; 43+ messages in thread
From: Guenter Roeck @ 2024-02-21 13:26 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:18PM +0800, David Gow wrote:
> 'days' is a s64 (from div_s64), and so should use a %lld specifier.
> 
> This was found by extending KUnit's assertion macros to use gcc's
> __printf attribute.
> 
> Fixes: 1d1bb12a8b18 ("rtc: Improve performance of rtc_time64_to_tm(). Add tests.")
> Signed-off-by: David Gow <davidgow@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/rtc/lib_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/lib_test.c b/drivers/rtc/lib_test.c
> index d5caf36c56cd..225c859d6da5 100644
> --- a/drivers/rtc/lib_test.c
> +++ b/drivers/rtc/lib_test.c
> @@ -54,7 +54,7 @@ static void rtc_time64_to_tm_test_date_range(struct kunit *test)
>  
>  		days = div_s64(secs, 86400);
>  
> -		#define FAIL_MSG "%d/%02d/%02d (%2d) : %ld", \
> +		#define FAIL_MSG "%d/%02d/%02d (%2d) : %lld", \
>  			year, month, mday, yday, days
>  
>  		KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 

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

* Re: [PATCH 6/9] net: test: Fix printf format specifier in skb_segment kunit test
  2024-02-21  9:27 ` [PATCH 6/9] net: test: Fix printf format specifier in skb_segment kunit test David Gow
@ 2024-02-21 13:26   ` Guenter Roeck
  2024-02-21 21:26   ` Justin Stitt
  1 sibling, 0 replies; 43+ messages in thread
From: Guenter Roeck @ 2024-02-21 13:26 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:19PM +0800, David Gow wrote:
> KUNIT_FAIL() accepts a printf-style format string, but previously did
> not let gcc validate it with the __printf() attribute. The use of %lld
> for the result of PTR_ERR() is not correct.
> 
> Instead, use %pe and pass the actual error pointer. printk() will format
> it correctly (and give a symbolic name rather than a number if
> available, which should make the output more readable, too).
> 
> Fixes: b3098d32ed6e ("net: add skb_segment kunit test")
> Signed-off-by: David Gow <davidgow@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  net/core/gso_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/core/gso_test.c b/net/core/gso_test.c
> index 4c2e77bd12f4..358c44680d91 100644
> --- a/net/core/gso_test.c
> +++ b/net/core/gso_test.c
> @@ -225,7 +225,7 @@ static void gso_test_func(struct kunit *test)
>  
>  	segs = skb_segment(skb, features);
>  	if (IS_ERR(segs)) {
> -		KUNIT_FAIL(test, "segs error %lld", PTR_ERR(segs));
> +		KUNIT_FAIL(test, "segs error %pe", segs);
>  		goto free_gso_skb;
>  	} else if (!segs) {
>  		KUNIT_FAIL(test, "no segments");
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 

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

* Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests
  2024-02-21  9:27 ` [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests David Gow
  2024-02-21 10:21   ` Matthew Auld
  2024-02-21 10:45   ` Christian König
@ 2024-02-21 13:26   ` Guenter Roeck
  2024-02-21 21:29   ` Justin Stitt
  3 siblings, 0 replies; 43+ messages in thread
From: Guenter Roeck @ 2024-02-21 13:26 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:20PM +0800, David Gow wrote:
> The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
> which was then updated to be an 'unsigned long' to avoid 64-bit
> multiplication division helpers.
> 
> However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
> '%d' or '%llu' format specifiers, the former of which is always wrong,
> and the latter is no longer correct now that ps is no longer a u64. Fix
> these to all use '%lu'.
> 
> Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
> message. gcc warns if a printf format string is empty (apparently), so
> give these some more detailed error messages, which should be more
> useful anyway.
> 
> Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
> Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit targets")
> Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
> Signed-off-by: David Gow <davidgow@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++++++-------
>  drivers/gpu/drm/tests/drm_mm_test.c    |  6 +++---
>  2 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c
> index 8a464f7f4c61..3dbfa3078449 100644
> --- a/drivers/gpu/drm/tests/drm_buddy_test.c
> +++ b/drivers/gpu/drm/tests/drm_buddy_test.c
> @@ -55,30 +55,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
>  		KUNIT_ASSERT_FALSE_MSG(test,
>  				       drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							      ps, ps, list, 0),
> -				       "buddy_alloc hit an error size=%d\n",
> +				       "buddy_alloc hit an error size=%lu\n",
>  				       ps);
>  	} while (++i < n_pages);
>  
>  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							   3 * ps, ps, &allocated,
>  							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%d\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>  
>  	drm_buddy_free_list(&mm, &middle);
>  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							   3 * ps, ps, &allocated,
>  							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							   2 * ps, ps, &allocated,
>  							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 2 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 2 * ps);
>  
>  	drm_buddy_free_list(&mm, &right);
>  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							   3 * ps, ps, &allocated,
>  							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>  	/*
>  	 * At this point we should have enough contiguous space for 2 blocks,
>  	 * however they are never buddies (since we freed middle and right) so
> @@ -87,13 +87,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
>  	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							    2 * ps, ps, &allocated,
>  							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc hit an error size=%d\n", 2 * ps);
> +			       "buddy_alloc hit an error size=%lu\n", 2 * ps);
>  
>  	drm_buddy_free_list(&mm, &left);
>  	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							    3 * ps, ps, &allocated,
>  							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc hit an error size=%d\n", 3 * ps);
> +			       "buddy_alloc hit an error size=%lu\n", 3 * ps);
>  
>  	total = 0;
>  	list_for_each_entry(block, &allocated, link)
> diff --git a/drivers/gpu/drm/tests/drm_mm_test.c b/drivers/gpu/drm/tests/drm_mm_test.c
> index 1eb0c304f960..f37c0d765865 100644
> --- a/drivers/gpu/drm/tests/drm_mm_test.c
> +++ b/drivers/gpu/drm/tests/drm_mm_test.c
> @@ -157,7 +157,7 @@ static void drm_test_mm_init(struct kunit *test)
>  
>  	/* After creation, it should all be one massive hole */
>  	if (!assert_one_hole(test, &mm, 0, size)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm not one hole on creation");
>  		goto out;
>  	}
>  
> @@ -171,14 +171,14 @@ static void drm_test_mm_init(struct kunit *test)
>  
>  	/* After filling the range entirely, there should be no holes */
>  	if (!assert_no_holes(test, &mm)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm has holes when filled");
>  		goto out;
>  	}
>  
>  	/* And then after emptying it again, the massive hole should be back */
>  	drm_mm_remove_node(&tmp);
>  	if (!assert_one_hole(test, &mm, 0, size)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm does not have single hole after emptying");
>  		goto out;
>  	}
>  
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 

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

* Re: [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test
  2024-02-21  9:27 ` [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test David Gow
@ 2024-02-21 13:26   ` Guenter Roeck
  2024-02-22  5:05   ` Lucas De Marchi
  2024-02-22  9:52   ` Thomas Hellström
  2 siblings, 0 replies; 43+ messages in thread
From: Guenter Roeck @ 2024-02-21 13:26 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:21PM +0800, David Gow wrote:
> KUNIT_FAIL() is used to fail the xe_migrate test when an error occurs.
> However, there's a mismatch in the format specifier: '%li' is used to
> log 'err', which is an 'int'.
> 
> Use '%i' instead of '%li', and for the case where we're printing an
> error pointer, just use '%pe', instead of extracting the error code
> manually with PTR_ERR(). (This also results in a nicer output when the
> error code is known.)
> 
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> Signed-off-by: David Gow <davidgow@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/gpu/drm/xe/tests/xe_migrate.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/tests/xe_migrate.c b/drivers/gpu/drm/xe/tests/xe_migrate.c
> index a6523df0f1d3..c347e2c29f81 100644
> --- a/drivers/gpu/drm/xe/tests/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/tests/xe_migrate.c
> @@ -114,21 +114,21 @@ static void test_copy(struct xe_migrate *m, struct xe_bo *bo,
>  						   region |
>  						   XE_BO_NEEDS_CPU_ACCESS);
>  	if (IS_ERR(remote)) {
> -		KUNIT_FAIL(test, "Failed to allocate remote bo for %s: %li\n",
> -			   str, PTR_ERR(remote));
> +		KUNIT_FAIL(test, "Failed to allocate remote bo for %s: %pe\n",
> +			   str, remote);
>  		return;
>  	}
>  
>  	err = xe_bo_validate(remote, NULL, false);
>  	if (err) {
> -		KUNIT_FAIL(test, "Failed to validate system bo for %s: %li\n",
> +		KUNIT_FAIL(test, "Failed to validate system bo for %s: %i\n",
>  			   str, err);
>  		goto out_unlock;
>  	}
>  
>  	err = xe_bo_vmap(remote);
>  	if (err) {
> -		KUNIT_FAIL(test, "Failed to vmap system bo for %s: %li\n",
> +		KUNIT_FAIL(test, "Failed to vmap system bo for %s: %i\n",
>  			   str, err);
>  		goto out_unlock;
>  	}
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 

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

* Re: [PATCH 9/9] kunit: Annotate _MSG assertion variants with gnu printf specifiers
  2024-02-21  9:27 ` [PATCH 9/9] kunit: Annotate _MSG assertion variants with gnu printf specifiers David Gow
@ 2024-02-21 13:26   ` Guenter Roeck
  2024-02-21 20:02   ` Justin Stitt
  1 sibling, 0 replies; 43+ messages in thread
From: Guenter Roeck @ 2024-02-21 13:26 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:22PM +0800, David Gow wrote:
> KUnit's assertion macros have variants which accept a printf format
> string, to allow tests to specify a more detailed message on failure.
> These (and the related KUNIT_FAIL() macro) ultimately wrap the
> __kunit_do_failed_assertion() function, which accepted a printf format
> specifier, but did not have the __printf attribute, so gcc couldn't warn
> on incorrect agruments.
> 
> It turns out there were quite a few tests with such incorrect arguments.
> 
> Add the __printf() specifier now that we've fixed these errors, to
> prevent them from recurring.
> 
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: David Gow <davidgow@google.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  include/kunit/test.h | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index fcb4a4940ace..61637ef32302 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -579,12 +579,12 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
>  
>  void __noreturn __kunit_abort(struct kunit *test);
>  
> -void __kunit_do_failed_assertion(struct kunit *test,
> -			       const struct kunit_loc *loc,
> -			       enum kunit_assert_type type,
> -			       const struct kunit_assert *assert,
> -			       assert_format_t assert_format,
> -			       const char *fmt, ...);
> +void __printf(6, 7) __kunit_do_failed_assertion(struct kunit *test,
> +						const struct kunit_loc *loc,
> +						enum kunit_assert_type type,
> +						const struct kunit_assert *assert,
> +						assert_format_t assert_format,
> +						const char *fmt, ...);
>  
>  #define _KUNIT_FAILED(test, assert_type, assert_class, assert_format, INITIALIZER, fmt, ...) do { \
>  	static const struct kunit_loc __loc = KUNIT_CURRENT_LOC;	       \
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 

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

* Re: [PATCH 9/9] kunit: Annotate _MSG assertion variants with gnu printf specifiers
  2024-02-21  9:27 ` [PATCH 9/9] kunit: Annotate _MSG assertion variants with gnu printf specifiers David Gow
  2024-02-21 13:26   ` Guenter Roeck
@ 2024-02-21 20:02   ` Justin Stitt
  1 sibling, 0 replies; 43+ messages in thread
From: Justin Stitt @ 2024-02-21 20:02 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

Hi,

On Wed, Feb 21, 2024 at 05:27:22PM +0800, David Gow wrote:
> KUnit's assertion macros have variants which accept a printf format
> string, to allow tests to specify a more detailed message on failure.
> These (and the related KUNIT_FAIL() macro) ultimately wrap the
> __kunit_do_failed_assertion() function, which accepted a printf format
> specifier, but did not have the __printf attribute, so gcc couldn't warn
> on incorrect agruments.
>
> It turns out there were quite a few tests with such incorrect arguments.
>
> Add the __printf() specifier now that we've fixed these errors, to
> prevent them from recurring.
>
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: David Gow <davidgow@google.com>

Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
>  include/kunit/test.h | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index fcb4a4940ace..61637ef32302 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -579,12 +579,12 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
>
>  void __noreturn __kunit_abort(struct kunit *test);
>
> -void __kunit_do_failed_assertion(struct kunit *test,
> -			       const struct kunit_loc *loc,
> -			       enum kunit_assert_type type,
> -			       const struct kunit_assert *assert,
> -			       assert_format_t assert_format,
> -			       const char *fmt, ...);
> +void __printf(6, 7) __kunit_do_failed_assertion(struct kunit *test,
> +						const struct kunit_loc *loc,
> +						enum kunit_assert_type type,
> +						const struct kunit_assert *assert,
> +						assert_format_t assert_format,
> +						const char *fmt, ...);
>
>  #define _KUNIT_FAILED(test, assert_type, assert_class, assert_format, INITIALIZER, fmt, ...) do { \
>  	static const struct kunit_loc __loc = KUNIT_CURRENT_LOC;	       \
> --
> 2.44.0.rc0.258.g7320e95886-goog
>

Thanks
Justin

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

* Re: [PATCH 1/9] kunit: test: Log the correct filter string in executor_test
  2024-02-21  9:27 ` [PATCH 1/9] kunit: test: Log the correct filter string in executor_test David Gow
  2024-02-21 13:25   ` Guenter Roeck
@ 2024-02-21 20:04   ` Justin Stitt
  2024-02-21 20:29   ` Daniel Latypov
  2024-02-22 20:58   ` Rae Moar
  3 siblings, 0 replies; 43+ messages in thread
From: Justin Stitt @ 2024-02-21 20:04 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

Hi,

On Wed, Feb 21, 2024 at 05:27:14PM +0800, David Gow wrote:
> KUnit's executor_test logs the filter string in KUNIT_ASSERT_EQ_MSG(),
> but passed a random character from the filter, rather than the whole
> string.
>
> This was found by annotating KUNIT_ASSERT_EQ_MSG() to let gcc validate
> the format string.
>
> Fixes: 76066f93f1df ("kunit: add tests for filtering attributes")
> Signed-off-by: David Gow <davidgow@google.com>

Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
>  lib/kunit/executor_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
> index 22d4ee86dbed..3f7f967e3688 100644
> --- a/lib/kunit/executor_test.c
> +++ b/lib/kunit/executor_test.c
> @@ -129,7 +129,7 @@ static void parse_filter_attr_test(struct kunit *test)
>  			GFP_KERNEL);
>  	for (j = 0; j < filter_count; j++) {
>  		parsed_filters[j] = kunit_next_attr_filter(&filter, &err);
> -		KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter '%s'", filters[j]);
> +		KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter from '%s'", filters);
>  	}
>
>  	KUNIT_EXPECT_STREQ(test, kunit_attr_filter_name(parsed_filters[0]), "speed");
> --
> 2.44.0.rc0.258.g7320e95886-goog
>

Thanks
Justin

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

* Re: [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg
  2024-02-21  9:27 ` [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg David Gow
  2024-02-21 13:25   ` Guenter Roeck
@ 2024-02-21 20:10   ` Justin Stitt
  2024-02-22  6:22     ` David Gow
  1 sibling, 1 reply; 43+ messages in thread
From: Justin Stitt @ 2024-02-21 20:10 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

Hi,

On Wed, Feb 21, 2024 at 05:27:15PM +0800, David Gow wrote:
> The correct format specifier for p - n (both p and n are pointers) is
> %td, as the type should be ptrdiff_t.

I think %tu is better. d specifies a signed type. I don't doubt that the
warning is fixed but I think %tu represents the type semantics here.

>
> This was discovered by annotating KUnit assertion macros with gcc's
> printf specifier, but note that gcc incorrectly suggested a %d or %ld
> specifier (depending on the pointer size of the architecture being
> built).
>
> Fixes: 0ea09083116d ("lib/cmdline: Allow get_options() to take 0 to validate the input")
> Signed-off-by: David Gow <davidgow@google.com>


> ---
>  lib/cmdline_kunit.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/cmdline_kunit.c b/lib/cmdline_kunit.c
> index d4572dbc9145..705b82736be0 100644
> --- a/lib/cmdline_kunit.c
> +++ b/lib/cmdline_kunit.c
> @@ -124,7 +124,7 @@ static void cmdline_do_one_range_test(struct kunit *test, const char *in,
>  			    n, e[0], r[0]);
>
>  	p = memchr_inv(&r[1], 0, sizeof(r) - sizeof(r[0]));
> -	KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %u out of bound", n, p - r);
> +	KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %td out of bound", n, p - r);
>  }
>
>  static void cmdline_test_range(struct kunit *test)
> --
> 2.44.0.rc0.258.g7320e95886-goog
>

Thanks
Justin

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

* Re: [PATCH 1/9] kunit: test: Log the correct filter string in executor_test
  2024-02-21  9:27 ` [PATCH 1/9] kunit: test: Log the correct filter string in executor_test David Gow
  2024-02-21 13:25   ` Guenter Roeck
  2024-02-21 20:04   ` Justin Stitt
@ 2024-02-21 20:29   ` Daniel Latypov
  2024-02-22 20:58   ` Rae Moar
  3 siblings, 0 replies; 43+ messages in thread
From: Daniel Latypov @ 2024-02-21 20:29 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Stephen Boyd, David Airlie, Maxime Ripard, David S . Miller,
	dri-devel, linux-kernel, intel-xe, linux-rtc, linux-kselftest,
	kunit-dev, linux-hardening, netdev

On Wed, Feb 21, 2024 at 1:28 AM David Gow <davidgow@google.com> wrote:
>
> KUnit's executor_test logs the filter string in KUNIT_ASSERT_EQ_MSG(),
> but passed a random character from the filter, rather than the whole
> string.

Note: it's worse than that, afaict.

It's printing from a random bit of memory.
I was curious about this, so I found under UML, the string I got was
always "efault)" if I make it fail for j=0.

>
> This was found by annotating KUNIT_ASSERT_EQ_MSG() to let gcc validate
> the format string.
>
> Fixes: 76066f93f1df ("kunit: add tests for filtering attributes")
> Signed-off-by: David Gow <davidgow@google.com>

Reviewed-by: Daniel Latypov <dlatypov@google.com>

> ---
>  lib/kunit/executor_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
> index 22d4ee86dbed..3f7f967e3688 100644
> --- a/lib/kunit/executor_test.c
> +++ b/lib/kunit/executor_test.c
> @@ -129,7 +129,7 @@ static void parse_filter_attr_test(struct kunit *test)
>                         GFP_KERNEL);
>         for (j = 0; j < filter_count; j++) {
>                 parsed_filters[j] = kunit_next_attr_filter(&filter, &err);
> -               KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter '%s'", filters[j]);
> +               KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter from '%s'", filters);

note: if there is a v2, it might be nice to include `j` in the message.

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

* Re: [PATCH 3/9] lib: memcpy_kunit: Fix an invalid format specifier in an assertion msg
  2024-02-21  9:27 ` [PATCH 3/9] lib: memcpy_kunit: " David Gow
  2024-02-21 13:25   ` Guenter Roeck
@ 2024-02-21 21:05   ` Justin Stitt
  1 sibling, 0 replies; 43+ messages in thread
From: Justin Stitt @ 2024-02-21 21:05 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

Hi,

On Wed, Feb 21, 2024 at 05:27:16PM +0800, David Gow wrote:
> The 'i' passed as an assertion message is a size_t, so should use '%zu',
> not '%d'.
>
> This was found by annotating the _MSG() variants of KUnit's assertions
> to let gcc validate the format strings.
>
> Fixes: bb95ebbe89a7 ("lib: Introduce CONFIG_MEMCPY_KUNIT_TEST")
> Signed-off-by: David Gow <davidgow@google.com>
> ---

Reviewed-by: Justin Stitt <justinstitt@google.com>
>  lib/memcpy_kunit.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/memcpy_kunit.c b/lib/memcpy_kunit.c
> index 440aee705ccc..30e00ef0bf2e 100644
> --- a/lib/memcpy_kunit.c
> +++ b/lib/memcpy_kunit.c
> @@ -32,7 +32,7 @@ struct some_bytes {
>  	BUILD_BUG_ON(sizeof(instance.data) != 32);	\
>  	for (size_t i = 0; i < sizeof(instance.data); i++) {	\
>  		KUNIT_ASSERT_EQ_MSG(test, instance.data[i], v, \
> -			"line %d: '%s' not initialized to 0x%02x @ %d (saw 0x%02x)\n", \
> +			"line %d: '%s' not initialized to 0x%02x @ %zu (saw 0x%02x)\n", \
>  			__LINE__, #instance, v, i, instance.data[i]);	\
>  	}	\
>  } while (0)
> @@ -41,7 +41,7 @@ struct some_bytes {
>  	BUILD_BUG_ON(sizeof(one) != sizeof(two)); \
>  	for (size_t i = 0; i < sizeof(one); i++) {	\
>  		KUNIT_EXPECT_EQ_MSG(test, one.data[i], two.data[i], \
> -			"line %d: %s.data[%d] (0x%02x) != %s.data[%d] (0x%02x)\n", \
> +			"line %d: %s.data[%zu] (0x%02x) != %s.data[%zu] (0x%02x)\n", \
>  			__LINE__, #one, i, one.data[i], #two, i, two.data[i]); \
>  	}	\
>  	kunit_info(test, "ok: " TEST_OP "() " name "\n");	\
> --
> 2.44.0.rc0.258.g7320e95886-goog
>

Thanks
Justin

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

* Re: [PATCH 4/9] time: test: Fix incorrect format specifier
  2024-02-21  9:27 ` [PATCH 4/9] time: test: Fix incorrect format specifier David Gow
  2024-02-21 13:25   ` Guenter Roeck
@ 2024-02-21 21:06   ` Justin Stitt
  1 sibling, 0 replies; 43+ messages in thread
From: Justin Stitt @ 2024-02-21 21:06 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

Hi,

On Wed, Feb 21, 2024 at 05:27:17PM +0800, David Gow wrote:
> 'days' is a s64 (from div_s64), and so should use a %lld specifier.
>
> This was found by extending KUnit's assertion macros to use gcc's
> __printf attribute.
>
> Fixes: 276010551664 ("time: Improve performance of time64_to_tm()")
> Signed-off-by: David Gow <davidgow@google.com>

Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
>  kernel/time/time_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/time_test.c b/kernel/time/time_test.c
> index ca058c8af6ba..3e5d422dd15c 100644
> --- a/kernel/time/time_test.c
> +++ b/kernel/time/time_test.c
> @@ -73,7 +73,7 @@ static void time64_to_tm_test_date_range(struct kunit *test)
>
>  		days = div_s64(secs, 86400);
>
> -		#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %ld", \
> +		#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %lld", \
>  			year, month, mdday, yday, days
>
>  		KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);
> --
> 2.44.0.rc0.258.g7320e95886-goog
>

Thanks
Justin

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

* Re: [PATCH 5/9] rtc: test: Fix invalid format specifier.
  2024-02-21  9:27 ` [PATCH 5/9] rtc: test: Fix invalid " David Gow
  2024-02-21 13:26   ` Guenter Roeck
@ 2024-02-21 21:06   ` Justin Stitt
  2024-02-27 20:32   ` Alexandre Belloni
  2 siblings, 0 replies; 43+ messages in thread
From: Justin Stitt @ 2024-02-21 21:06 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

Hi,

On Wed, Feb 21, 2024 at 05:27:18PM +0800, David Gow wrote:
> 'days' is a s64 (from div_s64), and so should use a %lld specifier.
>
> This was found by extending KUnit's assertion macros to use gcc's
> __printf attribute.
>
> Fixes: 1d1bb12a8b18 ("rtc: Improve performance of rtc_time64_to_tm(). Add tests.")
> Signed-off-by: David Gow <davidgow@google.com>

Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
>  drivers/rtc/lib_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/rtc/lib_test.c b/drivers/rtc/lib_test.c
> index d5caf36c56cd..225c859d6da5 100644
> --- a/drivers/rtc/lib_test.c
> +++ b/drivers/rtc/lib_test.c
> @@ -54,7 +54,7 @@ static void rtc_time64_to_tm_test_date_range(struct kunit *test)
>
>  		days = div_s64(secs, 86400);
>
> -		#define FAIL_MSG "%d/%02d/%02d (%2d) : %ld", \
> +		#define FAIL_MSG "%d/%02d/%02d (%2d) : %lld", \
>  			year, month, mday, yday, days
>
>  		KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);
> --
> 2.44.0.rc0.258.g7320e95886-goog
>

Thanks
Justin

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

* Re: [PATCH 6/9] net: test: Fix printf format specifier in skb_segment kunit test
  2024-02-21  9:27 ` [PATCH 6/9] net: test: Fix printf format specifier in skb_segment kunit test David Gow
  2024-02-21 13:26   ` Guenter Roeck
@ 2024-02-21 21:26   ` Justin Stitt
  1 sibling, 0 replies; 43+ messages in thread
From: Justin Stitt @ 2024-02-21 21:26 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

Hi,

On Wed, Feb 21, 2024 at 05:27:19PM +0800, David Gow wrote:
> KUNIT_FAIL() accepts a printf-style format string, but previously did
> not let gcc validate it with the __printf() attribute. The use of %lld
> for the result of PTR_ERR() is not correct.
>
> Instead, use %pe and pass the actual error pointer. printk() will format
> it correctly (and give a symbolic name rather than a number if
> available, which should make the output more readable, too).
>
> Fixes: b3098d32ed6e ("net: add skb_segment kunit test")
> Signed-off-by: David Gow <davidgow@google.com>

Looks good.

For those wondering, %pe has a special meaning in the kernel which can
be seen in lib/vsprintf.c.

Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
>  net/core/gso_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/gso_test.c b/net/core/gso_test.c
> index 4c2e77bd12f4..358c44680d91 100644
> --- a/net/core/gso_test.c
> +++ b/net/core/gso_test.c
> @@ -225,7 +225,7 @@ static void gso_test_func(struct kunit *test)
>
>  	segs = skb_segment(skb, features);
>  	if (IS_ERR(segs)) {
> -		KUNIT_FAIL(test, "segs error %lld", PTR_ERR(segs));
> +		KUNIT_FAIL(test, "segs error %pe", segs);
>  		goto free_gso_skb;
>  	} else if (!segs) {
>  		KUNIT_FAIL(test, "no segments");
> --
> 2.44.0.rc0.258.g7320e95886-goog
>

Thanks
Justin

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

* Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests
  2024-02-21  9:27 ` [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests David Gow
                     ` (2 preceding siblings ...)
  2024-02-21 13:26   ` Guenter Roeck
@ 2024-02-21 21:29   ` Justin Stitt
  2024-02-27 23:24     ` Shuah Khan
  3 siblings, 1 reply; 43+ messages in thread
From: Justin Stitt @ 2024-02-21 21:29 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

Hi,

On Wed, Feb 21, 2024 at 05:27:20PM +0800, David Gow wrote:
> The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
> which was then updated to be an 'unsigned long' to avoid 64-bit
> multiplication division helpers.
>
> However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
> '%d' or '%llu' format specifiers, the former of which is always wrong,
> and the latter is no longer correct now that ps is no longer a u64. Fix
> these to all use '%lu'.
>
> Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
> message. gcc warns if a printf format string is empty (apparently), so

clang does too; under -Wformat-zero-length

> give these some more detailed error messages, which should be more
> useful anyway.
>
> Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
> Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit targets")
> Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
> Signed-off-by: David Gow <davidgow@google.com>

Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
>  drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++++++-------
>  drivers/gpu/drm/tests/drm_mm_test.c    |  6 +++---
>  2 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c
> index 8a464f7f4c61..3dbfa3078449 100644
> --- a/drivers/gpu/drm/tests/drm_buddy_test.c
> +++ b/drivers/gpu/drm/tests/drm_buddy_test.c
> @@ -55,30 +55,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
>  		KUNIT_ASSERT_FALSE_MSG(test,
>  				       drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							      ps, ps, list, 0),
> -				       "buddy_alloc hit an error size=%d\n",
> +				       "buddy_alloc hit an error size=%lu\n",
>  				       ps);
>  	} while (++i < n_pages);
>
>  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							   3 * ps, ps, &allocated,
>  							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%d\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>
>  	drm_buddy_free_list(&mm, &middle);
>  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							   3 * ps, ps, &allocated,
>  							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							   2 * ps, ps, &allocated,
>  							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 2 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 2 * ps);
>
>  	drm_buddy_free_list(&mm, &right);
>  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							   3 * ps, ps, &allocated,
>  							   DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc didn't error size=%llu\n", 3 * ps);
> +			       "buddy_alloc didn't error size=%lu\n", 3 * ps);
>  	/*
>  	 * At this point we should have enough contiguous space for 2 blocks,
>  	 * however they are never buddies (since we freed middle and right) so
> @@ -87,13 +87,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
>  	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							    2 * ps, ps, &allocated,
>  							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc hit an error size=%d\n", 2 * ps);
> +			       "buddy_alloc hit an error size=%lu\n", 2 * ps);
>
>  	drm_buddy_free_list(&mm, &left);
>  	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
>  							    3 * ps, ps, &allocated,
>  							    DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -			       "buddy_alloc hit an error size=%d\n", 3 * ps);
> +			       "buddy_alloc hit an error size=%lu\n", 3 * ps);
>
>  	total = 0;
>  	list_for_each_entry(block, &allocated, link)
> diff --git a/drivers/gpu/drm/tests/drm_mm_test.c b/drivers/gpu/drm/tests/drm_mm_test.c
> index 1eb0c304f960..f37c0d765865 100644
> --- a/drivers/gpu/drm/tests/drm_mm_test.c
> +++ b/drivers/gpu/drm/tests/drm_mm_test.c
> @@ -157,7 +157,7 @@ static void drm_test_mm_init(struct kunit *test)
>
>  	/* After creation, it should all be one massive hole */
>  	if (!assert_one_hole(test, &mm, 0, size)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm not one hole on creation");
>  		goto out;
>  	}
>
> @@ -171,14 +171,14 @@ static void drm_test_mm_init(struct kunit *test)
>
>  	/* After filling the range entirely, there should be no holes */
>  	if (!assert_no_holes(test, &mm)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm has holes when filled");
>  		goto out;
>  	}
>
>  	/* And then after emptying it again, the massive hole should be back */
>  	drm_mm_remove_node(&tmp);
>  	if (!assert_one_hole(test, &mm, 0, size)) {
> -		KUNIT_FAIL(test, "");
> +		KUNIT_FAIL(test, "mm does not have single hole after emptying");
>  		goto out;
>  	}
>
> --
> 2.44.0.rc0.258.g7320e95886-goog
>

Thanks
Justin

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

* Re: [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test
  2024-02-21  9:27 ` [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test David Gow
  2024-02-21 13:26   ` Guenter Roeck
@ 2024-02-22  5:05   ` Lucas De Marchi
  2024-02-22  5:59     ` Linus Torvalds
  2024-02-22  9:52   ` Thomas Hellström
  2 siblings, 1 reply; 43+ messages in thread
From: Lucas De Marchi @ 2024-02-22  5:05 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

On Wed, Feb 21, 2024 at 05:27:21PM +0800, David Gow wrote:
>KUNIT_FAIL() is used to fail the xe_migrate test when an error occurs.
>However, there's a mismatch in the format specifier: '%li' is used to
>log 'err', which is an 'int'.
>
>Use '%i' instead of '%li', and for the case where we're printing an
>error pointer, just use '%pe', instead of extracting the error code
>manually with PTR_ERR(). (This also results in a nicer output when the
>error code is known.)
>
>Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
>Signed-off-by: David Gow <davidgow@google.com>


Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>

this has a potential to cause conflicts with upcoming work, so I think
it's better to apply this through drm-xe-next. Let me know if you agree.

thanks
Lucas De Marchi

>---
> drivers/gpu/drm/xe/tests/xe_migrate.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/gpu/drm/xe/tests/xe_migrate.c b/drivers/gpu/drm/xe/tests/xe_migrate.c
>index a6523df0f1d3..c347e2c29f81 100644
>--- a/drivers/gpu/drm/xe/tests/xe_migrate.c
>+++ b/drivers/gpu/drm/xe/tests/xe_migrate.c
>@@ -114,21 +114,21 @@ static void test_copy(struct xe_migrate *m, struct xe_bo *bo,
> 						   region |
> 						   XE_BO_NEEDS_CPU_ACCESS);
> 	if (IS_ERR(remote)) {
>-		KUNIT_FAIL(test, "Failed to allocate remote bo for %s: %li\n",
>-			   str, PTR_ERR(remote));
>+		KUNIT_FAIL(test, "Failed to allocate remote bo for %s: %pe\n",
>+			   str, remote);
> 		return;
> 	}
>
> 	err = xe_bo_validate(remote, NULL, false);
> 	if (err) {
>-		KUNIT_FAIL(test, "Failed to validate system bo for %s: %li\n",
>+		KUNIT_FAIL(test, "Failed to validate system bo for %s: %i\n",
> 			   str, err);
> 		goto out_unlock;
> 	}
>
> 	err = xe_bo_vmap(remote);
> 	if (err) {
>-		KUNIT_FAIL(test, "Failed to vmap system bo for %s: %li\n",
>+		KUNIT_FAIL(test, "Failed to vmap system bo for %s: %i\n",
> 			   str, err);
> 		goto out_unlock;
> 	}
>-- 
>2.44.0.rc0.258.g7320e95886-goog
>

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

* Re: [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test
  2024-02-22  5:05   ` Lucas De Marchi
@ 2024-02-22  5:59     ` Linus Torvalds
  0 siblings, 0 replies; 43+ messages in thread
From: Linus Torvalds @ 2024-02-22  5:59 UTC (permalink / raw)
  To: Lucas De Marchi
  Cc: David Gow, Shuah Khan, Guenter Roeck, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, 21 Feb 2024 at 21:05, Lucas De Marchi <lucas.demarchi@intel.com> wrote:
>
> this has a potential to cause conflicts with upcoming work, so I think
> it's better to apply this through drm-xe-next. Let me know if you agree.

I disagree. Violently.

For this to be fixed, we need to have the printf format checking enabled.

And we can't enable it until all the problems have been fixed.

Which means that we should *not* have to wait for [N] different trees
to fix their issues separately.

This should get fixed in the Kunit tree, so that the Kunit tree can
just send a pull request to me to enable format checking for the KUnit
tests, together with all the fixes.  Trying to spread those fixes out
to different git branches will only result in pain and pointless
dependencies between different trees.

Honestly, the reason I noticed the problem in the first place was that
the drm tree had a separate bug, that had been apparently noted in
linux-next, and *despite* that it made it into a pull request to me
and caused new build failures in rc5.

So as things are, I am not IN THE LEAST interested in some kind of
"let us fix this in the drm tree separately" garbage.  We're not
making things worse by trying to fix this in different trees.

We're fixing this in the Kunit tree, and I do not want to get *more*
problems from the drm side. I've had enough.

               Linus

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

* Re: [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg
  2024-02-21 20:10   ` Justin Stitt
@ 2024-02-22  6:22     ` David Gow
  2024-02-22 17:36       ` Daniel Latypov
  0 siblings, 1 reply; 43+ messages in thread
From: David Gow @ 2024-02-22  6:22 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

[-- Attachment #1: Type: text/plain, Size: 1490 bytes --]

On Thu, 22 Feb 2024 at 04:10, 'Justin Stitt' via KUnit Development
<kunit-dev@googlegroups.com> wrote:
>
> Hi,
>
> On Wed, Feb 21, 2024 at 05:27:15PM +0800, David Gow wrote:
> > The correct format specifier for p - n (both p and n are pointers) is
> > %td, as the type should be ptrdiff_t.
>
> I think %tu is better. d specifies a signed type. I don't doubt that the
> warning is fixed but I think %tu represents the type semantics here.
>

While I agree that this should never be negative, I'd still lean on
this being a signed type, for two reasons:
- I think, if there's a bug in this code, it's easier to debug this if
a 'negative' value were to appear as such.
- While, as I understand it, the C spec does provide for a
ptrdiff_t-sized unsigned printf specifier in '%tu', the difference
between two pointers is always signed:

"When two pointers are subtracted, both shall point to elements of the
same array object,
or one past the last element of the array object; the result is the
difference of the
subscripts of the two array elements. The size of the result is
implementation-defined,
and its type (a signed integer type) is ptrdiff_t defined in the
<stddef.h> header"

(Technically, the kernel's ptrdiff_t type isn't defined in stddef.h,
so a bit of deviation from the spec is happening anyway, though.)

If there's a particularly good reason to make this unsigned in this
case, I'd be happy to change it, of course. But I'd otherwise prefer
to keep it as-is.

Cheers,
-- David

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4014 bytes --]

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

* Re: [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test
  2024-02-21  9:27 ` [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test David Gow
  2024-02-21 13:26   ` Guenter Roeck
  2024-02-22  5:05   ` Lucas De Marchi
@ 2024-02-22  9:52   ` Thomas Hellström
  2 siblings, 0 replies; 43+ messages in thread
From: Thomas Hellström @ 2024-02-22  9:52 UTC (permalink / raw)
  To: David Gow, Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo
  Cc: Brendan Higgins, Daniel Latypov, Stephen Boyd, David Airlie,
	Maxime Ripard, David S . Miller, dri-devel, linux-kernel,
	intel-xe, linux-rtc, linux-kselftest, kunit-dev, linux-hardening,
	netdev

On Wed, 2024-02-21 at 17:27 +0800, David Gow wrote:
> KUNIT_FAIL() is used to fail the xe_migrate test when an error
> occurs.
> However, there's a mismatch in the format specifier: '%li' is used to
> log 'err', which is an 'int'.
> 
> Use '%i' instead of '%li', and for the case where we're printing an
> error pointer, just use '%pe', instead of extracting the error code
> manually with PTR_ERR(). (This also results in a nicer output when
> the
> error code is known.)
> 
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel
> GPUs")
> Signed-off-by: David Gow <davidgow@google.com>

Ack to merge through the Kunit tree.
Acked-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>



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

* Re: [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
                   ` (8 preceding siblings ...)
  2024-02-21  9:27 ` [PATCH 9/9] kunit: Annotate _MSG assertion variants with gnu printf specifiers David Gow
@ 2024-02-22 14:23 ` Shuah Khan
  2024-02-27 23:32 ` Shuah Khan
  10 siblings, 0 replies; 43+ messages in thread
From: Shuah Khan @ 2024-02-22 14:23 UTC (permalink / raw)
  To: David Gow, Linus Torvalds, Guenter Roeck, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo
  Cc: Brendan Higgins, Daniel Latypov, Stephen Boyd, David Airlie,
	Maxime Ripard, David S . Miller, dri-devel, linux-kernel,
	intel-xe, linux-rtc, linux-kselftest, kunit-dev, linux-hardening,
	netdev, Shuah Khan

On 2/21/24 02:27, David Gow wrote:
> KUnit has several macros which accept a log message, which can contain
> printf format specifiers. Some of these (the explicit log macros)
> already use the __printf() gcc attribute to ensure the format specifiers
> are valid, but those which could fail the test, and hence used
> __kunit_do_failed_assertion() behind the scenes, did not.
> 
> These include:
> - KUNIT_EXPECT_*_MSG()
> - KUNIT_ASSERT_*_MSG()
> - KUNIT_FAIL()
> 
> This series adds the __printf() attribute, and fixes all of the issues
> uncovered. (Or, at least, all of those I could find with an x86_64
> allyesconfig, and the default KUnit config on a number of other
> architectures. Please test!)
> 
> The issues in question basically take the following forms:
> - int / long / long long confusion: typically a type being updated, but
>    the format string not.
> - Use of integer format specifiers (%d/%u/%li/etc) for types like size_t
>    or pointer differences (technically ptrdiff_t), which would only work
>    on some architectures.
> - Use of integer format specifiers in combination with PTR_ERR(), where
>    %pe would make more sense.
> - Use of empty messages which, whilst technically not incorrect, are not
>    useful and trigger a gcc warning.
> 
> We'd like to get these (or equivalent) in for 6.9 if possible, so please
> do take a look if possible.
> 
> Thanks,
> -- David
> 
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Closes: https://lore.kernel.org/linux-kselftest/CAHk-=wgJMOquDO5f8ShH1f4rzZwzApNVCw643m5-Yj+BfsFstA@mail.gmail.com/
> 
>

Thank you for a quick response David. I will apply the series to
kunit next for Linux 6.9 as soon as the reviews are complete.

thanks,
-- Shuah


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

* Re: [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg
  2024-02-22  6:22     ` David Gow
@ 2024-02-22 17:36       ` Daniel Latypov
  2024-02-22 17:56         ` Linus Torvalds
  0 siblings, 1 reply; 43+ messages in thread
From: Daniel Latypov @ 2024-02-22 17:36 UTC (permalink / raw)
  To: David Gow
  Cc: Justin Stitt, Linus Torvalds, Shuah Khan, Guenter Roeck,
	Rae Moar, Matthew Auld, Arunpravin Paneer Selvam,
	Christian König, Kees Cook, Maíra Canal, Rodrigo Vivi,
	Matthew Brost, Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Stephen Boyd, David Airlie, Maxime Ripard, David S . Miller,
	dri-devel, linux-kernel, intel-xe, linux-rtc, linux-kselftest,
	kunit-dev, linux-hardening, netdev

On Wed, Feb 21, 2024 at 10:22 PM David Gow <davidgow@google.com> wrote:
>
> On Thu, 22 Feb 2024 at 04:10, 'Justin Stitt' via KUnit Development
> <kunit-dev@googlegroups.com> wrote:
> >
> > Hi,
> >
> > On Wed, Feb 21, 2024 at 05:27:15PM +0800, David Gow wrote:
> > > The correct format specifier for p - n (both p and n are pointers) is
> > > %td, as the type should be ptrdiff_t.
> >
> > I think %tu is better. d specifies a signed type. I don't doubt that the
> > warning is fixed but I think %tu represents the type semantics here.
> >
>
> While I agree that this should never be negative, I'd still lean on
> this being a signed type, for two reasons:
> - I think, if there's a bug in this code, it's easier to debug this if
> a 'negative' value were to appear as such.
> - While, as I understand it, the C spec does provide for a
> ptrdiff_t-sized unsigned printf specifier in '%tu', the difference
> between two pointers is always signed:
>
> "When two pointers are subtracted, both shall point to elements of the
> same array object,
> or one past the last element of the array object; the result is the
> difference of the
> subscripts of the two array elements. The size of the result is
> implementation-defined,
> and its type (a signed integer type) is ptrdiff_t defined in the
> <stddef.h> header"
>
> (Technically, the kernel's ptrdiff_t type isn't defined in stddef.h,
> so a bit of deviation from the spec is happening anyway, though.)
>
> If there's a particularly good reason to make this unsigned in this
> case, I'd be happy to change it, of course. But I'd otherwise prefer
> to keep it as-is.

Copying the line for context, it's about `p-r` where
  p = memchr_inv(&r[1], 0, sizeof(r) - sizeof(r[0]));
`p-r` should never be negative unless something has gone horribly
horribly wrong.

So in this particular case, either %tu or %td would be fine.

(sorta bikeshedding warning)
But, I'd personally lean towards using the signed %td in tests to
guard against typos in test code as _a guiding principle._

This is especially true given that the failure messages aren't
verified since they are mostly "dead code."
You can have crazy incorrect things going on in the format arguments,
see patch 1/9 in this series [1]. One of kunit's own tests would do a
read from a ~random memory region if that specific assertion failed.
Not a good look ;)
We never noticed until this series enabled the format string checks.
You also can't expect reviewers to go through and modify every
assertion to fail to see what the failure mode looks like, so these
kinds of errors will continue to slip through.

*So IMO, we should generally adopt a more defensive stance when it
comes to these.*

Also consider the user experience if there is a failure and I
accidentally wrote `r-p` here.
Someone else sees an error report from this test and needs to investigate.

What message is easier to deal with?
>  in test 18 at -5 out of bound
or
> in test 18 at 18446744073709551611 out of bound

Sure, I can eventually figure out what both messages mean, but it's a
immediately obvious from the first that there's a
a) real error: something is wrong at index 5
b) test code error: there's a flipped sign somewhere

So I'd strongly prefer the current version of the patch over one with %tu.
Reviewed-by: Daniel Latypov <dlatypov@google.com>

[1] https://lore.kernel.org/linux-kselftest/20240221092728.1281499-2-davidgow@google.com/

Thanks,
Daniel

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

* Re: [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg
  2024-02-22 17:36       ` Daniel Latypov
@ 2024-02-22 17:56         ` Linus Torvalds
  0 siblings, 0 replies; 43+ messages in thread
From: Linus Torvalds @ 2024-02-22 17:56 UTC (permalink / raw)
  To: Daniel Latypov
  Cc: David Gow, Justin Stitt, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Stephen Boyd, David Airlie, Maxime Ripard, David S . Miller,
	dri-devel, linux-kernel, intel-xe, linux-rtc, linux-kselftest,
	kunit-dev, linux-hardening, netdev

On Thu, 22 Feb 2024 at 09:36, Daniel Latypov <dlatypov@google.com> wrote:
>
> Copying the line for context, it's about `p-r` where
>   p = memchr_inv(&r[1], 0, sizeof(r) - sizeof(r[0]));
> `p-r` should never be negative unless something has gone horribly
> horribly wrong.

Sure it would - if 'p' is NULL.

Of course, then a negative value wouldn't be helpful either, and in
this case that's what the EXPECT_PTR_EQ checking is testing in the
first place, so it's a non-issue.

IOW, in practice clearly the sign should simply not matter here.

I do think that the default case for pointer differences should be
that they are signed, because they *can* be.

Just because of that "default case", unless there's some actual reason
to use '%tu', I think '%td' should be seen as the normal case to use.

That said, just as a quick aside: be careful with pointer differences
in the kernel.

For this particular case, when we're talking about just 'char *', it's
not a big deal, but we've had code where people didn't think about
what it means to do a pointer difference in C, and how it can be often
unnecessarily expensive due to the implied "divide by the size of the
pointed object".

Sometimes it's actually worth writing the code in ways that avoids
pointer differences entirely (which might involve passing around
indexes instead of pointers).

                 Linus

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

* Re: [PATCH 1/9] kunit: test: Log the correct filter string in executor_test
  2024-02-21  9:27 ` [PATCH 1/9] kunit: test: Log the correct filter string in executor_test David Gow
                     ` (2 preceding siblings ...)
  2024-02-21 20:29   ` Daniel Latypov
@ 2024-02-22 20:58   ` Rae Moar
  3 siblings, 0 replies; 43+ messages in thread
From: Rae Moar @ 2024-02-22 20:58 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On Wed, Feb 21, 2024 at 4:28 AM David Gow <davidgow@google.com> wrote:
>
> KUnit's executor_test logs the filter string in KUNIT_ASSERT_EQ_MSG(),
> but passed a random character from the filter, rather than the whole
> string.
>
> This was found by annotating KUNIT_ASSERT_EQ_MSG() to let gcc validate
> the format string.
>
> Fixes: 76066f93f1df ("kunit: add tests for filtering attributes")
> Signed-off-by: David Gow <davidgow@google.com>

Hello!

This change looks good to me. Thanks for fixing this mistake.

Thanks!
-Rae

Reviewed-by: Rae Moar <rmoar@google.com>

> ---
>  lib/kunit/executor_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
> index 22d4ee86dbed..3f7f967e3688 100644
> --- a/lib/kunit/executor_test.c
> +++ b/lib/kunit/executor_test.c
> @@ -129,7 +129,7 @@ static void parse_filter_attr_test(struct kunit *test)
>                         GFP_KERNEL);
>         for (j = 0; j < filter_count; j++) {
>                 parsed_filters[j] = kunit_next_attr_filter(&filter, &err);
> -               KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter '%s'", filters[j]);
> +               KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter from '%s'", filters);
>         }
>
>         KUNIT_EXPECT_STREQ(test, kunit_attr_filter_name(parsed_filters[0]), "speed");
> --
> 2.44.0.rc0.258.g7320e95886-goog
>

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

* Re: [PATCH 5/9] rtc: test: Fix invalid format specifier.
  2024-02-21  9:27 ` [PATCH 5/9] rtc: test: Fix invalid " David Gow
  2024-02-21 13:26   ` Guenter Roeck
  2024-02-21 21:06   ` Justin Stitt
@ 2024-02-27 20:32   ` Alexandre Belloni
  2024-02-27 21:23     ` Shuah Khan
  2 siblings, 1 reply; 43+ messages in thread
From: Alexandre Belloni @ 2024-02-27 20:32 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Shuah Khan, Guenter Roeck, Rae Moar,
	Matthew Auld, Arunpravin Paneer Selvam, Christian König,
	Kees Cook, Maíra Canal, Rodrigo Vivi, Matthew Brost,
	Willem de Bruijn, Florian Westphal, Cassio Neri,
	Javier Martinez Canillas, Arthur Grillo, Brendan Higgins,
	Daniel Latypov, Stephen Boyd, David Airlie, Maxime Ripard,
	David S . Miller, dri-devel, linux-kernel, intel-xe, linux-rtc,
	linux-kselftest, kunit-dev, linux-hardening, netdev

Hello,

On 21/02/2024 17:27:18+0800, David Gow wrote:
> 'days' is a s64 (from div_s64), and so should use a %lld specifier.
> 
> This was found by extending KUnit's assertion macros to use gcc's
> __printf attribute.
> 
> Fixes: 1d1bb12a8b18 ("rtc: Improve performance of rtc_time64_to_tm(). Add tests.")
> Signed-off-by: David Gow <davidgow@google.com>

Who do you expect to take this patch?

> ---
>  drivers/rtc/lib_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/lib_test.c b/drivers/rtc/lib_test.c
> index d5caf36c56cd..225c859d6da5 100644
> --- a/drivers/rtc/lib_test.c
> +++ b/drivers/rtc/lib_test.c
> @@ -54,7 +54,7 @@ static void rtc_time64_to_tm_test_date_range(struct kunit *test)
>  
>  		days = div_s64(secs, 86400);
>  
> -		#define FAIL_MSG "%d/%02d/%02d (%2d) : %ld", \
> +		#define FAIL_MSG "%d/%02d/%02d (%2d) : %lld", \
>  			year, month, mday, yday, days
>  
>  		KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);
> -- 
> 2.44.0.rc0.258.g7320e95886-goog
> 
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH 5/9] rtc: test: Fix invalid format specifier.
  2024-02-27 20:32   ` Alexandre Belloni
@ 2024-02-27 21:23     ` Shuah Khan
  2024-02-27 22:48       ` Alexandre Belloni
  0 siblings, 1 reply; 43+ messages in thread
From: Shuah Khan @ 2024-02-27 21:23 UTC (permalink / raw)
  To: Alexandre Belloni, David Gow
  Cc: Linus Torvalds, Guenter Roeck, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev, Shuah Khan

On 2/27/24 13:32, Alexandre Belloni wrote:
> Hello,
> 
> On 21/02/2024 17:27:18+0800, David Gow wrote:
>> 'days' is a s64 (from div_s64), and so should use a %lld specifier.
>>
>> This was found by extending KUnit's assertion macros to use gcc's
>> __printf attribute.
>>
>> Fixes: 1d1bb12a8b18 ("rtc: Improve performance of rtc_time64_to_tm(). Add tests.")
>> Signed-off-by: David Gow <davidgow@google.com>
> 
> Who do you expect to take this patch?
> 

I am going to be applying this series to linux-kselftest kunit next
in just a bit. Would you like to ack the pacth?

thanks,
-- Shuah


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

* Re: [PATCH 5/9] rtc: test: Fix invalid format specifier.
  2024-02-27 21:23     ` Shuah Khan
@ 2024-02-27 22:48       ` Alexandre Belloni
  0 siblings, 0 replies; 43+ messages in thread
From: Alexandre Belloni @ 2024-02-27 22:48 UTC (permalink / raw)
  To: Shuah Khan
  Cc: David Gow, Linus Torvalds, Guenter Roeck, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev

On 27/02/2024 14:23:29-0700, Shuah Khan wrote:
> On 2/27/24 13:32, Alexandre Belloni wrote:
> > Hello,
> > 
> > On 21/02/2024 17:27:18+0800, David Gow wrote:
> > > 'days' is a s64 (from div_s64), and so should use a %lld specifier.
> > > 
> > > This was found by extending KUnit's assertion macros to use gcc's
> > > __printf attribute.
> > > 
> > > Fixes: 1d1bb12a8b18 ("rtc: Improve performance of rtc_time64_to_tm(). Add tests.")
> > > Signed-off-by: David Gow <davidgow@google.com>
> > 
> > Who do you expect to take this patch?
> > 
> 
> I am going to be applying this series to linux-kselftest kunit next
> in just a bit. Would you like to ack the pacth?

Sure,

Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> 
> thanks,
> -- Shuah
> 
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests
  2024-02-21 21:29   ` Justin Stitt
@ 2024-02-27 23:24     ` Shuah Khan
  0 siblings, 0 replies; 43+ messages in thread
From: Shuah Khan @ 2024-02-27 23:24 UTC (permalink / raw)
  To: David Gow
  Cc: Linus Torvalds, Guenter Roeck, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo, Brendan Higgins, Daniel Latypov, Stephen Boyd,
	David Airlie, Maxime Ripard, David S . Miller, dri-devel,
	linux-kernel, intel-xe, linux-rtc, linux-kselftest, kunit-dev,
	linux-hardening, netdev, Shuah Khan, Justin Stitt

On 2/21/24 14:29, Justin Stitt wrote:
> Hi,
> 
> On Wed, Feb 21, 2024 at 05:27:20PM +0800, David Gow wrote:
>> The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
>> which was then updated to be an 'unsigned long' to avoid 64-bit
>> multiplication division helpers.
>>
>> However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
>> '%d' or '%llu' format specifiers, the former of which is always wrong,
>> and the latter is no longer correct now that ps is no longer a u64. Fix
>> these to all use '%lu'.
>>
>> Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
>> message. gcc warns if a printf format string is empty (apparently), so
> 
> clang does too; under -Wformat-zero-length
> 
>> give these some more detailed error messages, which should be more
>> useful anyway.
>>
>> Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
>> Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit targets")
>> Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
>> Signed-off-by: David Gow <davidgow@google.com>
> 
> Reviewed-by: Justin Stitt <justinstitt@google.com>

David,

Please send this on top of Linux 6.9-rc6 - this one doesn't
apply as is due to conflict between this one and fca7526b7d89

I think if we can fix this here - we won't problems during pull
request merge.

thanks,
-- Shuah



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

* Re: [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions
  2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
                   ` (9 preceding siblings ...)
  2024-02-22 14:23 ` [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions Shuah Khan
@ 2024-02-27 23:32 ` Shuah Khan
  10 siblings, 0 replies; 43+ messages in thread
From: Shuah Khan @ 2024-02-27 23:32 UTC (permalink / raw)
  To: David Gow, Linus Torvalds, Guenter Roeck, Rae Moar, Matthew Auld,
	Arunpravin Paneer Selvam, Christian König, Kees Cook,
	Maíra Canal, Rodrigo Vivi, Matthew Brost, Willem de Bruijn,
	Florian Westphal, Cassio Neri, Javier Martinez Canillas,
	Arthur Grillo
  Cc: Brendan Higgins, Daniel Latypov, Stephen Boyd, David Airlie,
	Maxime Ripard, David S . Miller, dri-devel, linux-kernel,
	intel-xe, linux-rtc, linux-kselftest, kunit-dev, linux-hardening,
	netdev, Shuah Khan

On 2/21/24 02:27, David Gow wrote:
> KUnit has several macros which accept a log message, which can contain
> printf format specifiers. Some of these (the explicit log macros)
> already use the __printf() gcc attribute to ensure the format specifiers
> are valid, but those which could fail the test, and hence used
> __kunit_do_failed_assertion() behind the scenes, did not.
> 
> These include:
> - KUNIT_EXPECT_*_MSG()
> - KUNIT_ASSERT_*_MSG()
> - KUNIT_FAIL()
> 
> This series adds the __printf() attribute, and fixes all of the issues
> uncovered. (Or, at least, all of those I could find with an x86_64
> allyesconfig, and the default KUnit config on a number of other
> architectures. Please test!)
> 
> The issues in question basically take the following forms:
> - int / long / long long confusion: typically a type being updated, but
>    the format string not.
> - Use of integer format specifiers (%d/%u/%li/etc) for types like size_t
>    or pointer differences (technically ptrdiff_t), which would only work
>    on some architectures.
> - Use of integer format specifiers in combination with PTR_ERR(), where
>    %pe would make more sense.
> - Use of empty messages which, whilst technically not incorrect, are not
>    useful and trigger a gcc warning.
> 
> We'd like to get these (or equivalent) in for 6.9 if possible, so please
> do take a look if possible.
> 
> Thanks,
> -- David
> 
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Closes: https://lore.kernel.org/linux-kselftest/CAHk-=wgJMOquDO5f8ShH1f4rzZwzApNVCw643m5-Yj+BfsFstA@mail.gmail.com/
> 
> David Gow (9):
>    kunit: test: Log the correct filter string in executor_test
>    lib/cmdline: Fix an invalid format specifier in an assertion msg
>    lib: memcpy_kunit: Fix an invalid format specifier in an assertion msg
>    time: test: Fix incorrect format specifier
>    rtc: test: Fix invalid format specifier.
>    net: test: Fix printf format specifier in skb_segment kunit test
>    drm: tests: Fix invalid printf format specifiers in KUnit tests
>    drm/xe/tests: Fix printf format specifiers in xe_migrate test
>    kunit: Annotate _MSG assertion variants with gnu printf specifiers
> 

Applied all patches in this series except to linux-ksefltest kunit
for linux 6.9-rc1

drm: tests: Fix invalid printf format specifiers in KUnit tests

David, as requtested in 7/9 thread, if you can send me patch on
top pf 6.8-rc6, will apply it

7-9 drm: tests: Fix invalid printf format specifiers in KUnit tests

thanks,
-- Shuah



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

end of thread, other threads:[~2024-02-27 23:32 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-21  9:27 [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions David Gow
2024-02-21  9:27 ` [PATCH 1/9] kunit: test: Log the correct filter string in executor_test David Gow
2024-02-21 13:25   ` Guenter Roeck
2024-02-21 20:04   ` Justin Stitt
2024-02-21 20:29   ` Daniel Latypov
2024-02-22 20:58   ` Rae Moar
2024-02-21  9:27 ` [PATCH 2/9] lib/cmdline: Fix an invalid format specifier in an assertion msg David Gow
2024-02-21 13:25   ` Guenter Roeck
2024-02-21 20:10   ` Justin Stitt
2024-02-22  6:22     ` David Gow
2024-02-22 17:36       ` Daniel Latypov
2024-02-22 17:56         ` Linus Torvalds
2024-02-21  9:27 ` [PATCH 3/9] lib: memcpy_kunit: " David Gow
2024-02-21 13:25   ` Guenter Roeck
2024-02-21 21:05   ` Justin Stitt
2024-02-21  9:27 ` [PATCH 4/9] time: test: Fix incorrect format specifier David Gow
2024-02-21 13:25   ` Guenter Roeck
2024-02-21 21:06   ` Justin Stitt
2024-02-21  9:27 ` [PATCH 5/9] rtc: test: Fix invalid " David Gow
2024-02-21 13:26   ` Guenter Roeck
2024-02-21 21:06   ` Justin Stitt
2024-02-27 20:32   ` Alexandre Belloni
2024-02-27 21:23     ` Shuah Khan
2024-02-27 22:48       ` Alexandre Belloni
2024-02-21  9:27 ` [PATCH 6/9] net: test: Fix printf format specifier in skb_segment kunit test David Gow
2024-02-21 13:26   ` Guenter Roeck
2024-02-21 21:26   ` Justin Stitt
2024-02-21  9:27 ` [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests David Gow
2024-02-21 10:21   ` Matthew Auld
2024-02-21 10:45   ` Christian König
2024-02-21 13:26   ` Guenter Roeck
2024-02-21 21:29   ` Justin Stitt
2024-02-27 23:24     ` Shuah Khan
2024-02-21  9:27 ` [PATCH 8/9] drm/xe/tests: Fix printf format specifiers in xe_migrate test David Gow
2024-02-21 13:26   ` Guenter Roeck
2024-02-22  5:05   ` Lucas De Marchi
2024-02-22  5:59     ` Linus Torvalds
2024-02-22  9:52   ` Thomas Hellström
2024-02-21  9:27 ` [PATCH 9/9] kunit: Annotate _MSG assertion variants with gnu printf specifiers David Gow
2024-02-21 13:26   ` Guenter Roeck
2024-02-21 20:02   ` Justin Stitt
2024-02-22 14:23 ` [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions Shuah Khan
2024-02-27 23:32 ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).