All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] binder: Add copyright notice to new kunit files
@ 2025-07-22 23:45 Tiffany Yang
  2025-07-22 23:45 ` [PATCH v2 2/2] binder: Use seq_buf in binder_alloc kunit tests Tiffany Yang
  2025-07-25 19:38 ` [PATCH v2 1/2] binder: Add copyright notice to new kunit files Carlos Llamas
  0 siblings, 2 replies; 5+ messages in thread
From: Tiffany Yang @ 2025-07-22 23:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Carlos Llamas, Joel Fernandes, kernel-team, Greg Kroah-Hartman,
	Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
	Christian Brauner, Suren Baghdasaryan

Clean up for the binder_alloc kunit test series. Add a copyright notice
to new files, as suggested by Carlos [1].

[1] https://lore.kernel.org/all/CAFuZdDLD=3CBOLSWw3VxCf7Nkf884SSNmt1wresQgxgBwED=eQ@mail.gmail.com/

Fixes: 5e024582f494 ("binder: Scaffolding for binder_alloc KUnit tests")
Suggested-by: Carlos Llamas <cmllamas@google.com>
Cc: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Tiffany Yang <ynaffit@google.com>
---
This patch is based on top of char-misc-next.
---
 drivers/android/tests/.kunitconfig         | 4 ++++
 drivers/android/tests/Makefile             | 3 +++
 drivers/android/tests/binder_alloc_kunit.c | 5 ++++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/android/tests/.kunitconfig b/drivers/android/tests/.kunitconfig
index a73601231049..39b76bab9d9a 100644
--- a/drivers/android/tests/.kunitconfig
+++ b/drivers/android/tests/.kunitconfig
@@ -1,3 +1,7 @@
+#
+# Copyright 2025 Google LLC.
+#
+
 CONFIG_KUNIT=y
 CONFIG_ANDROID_BINDER_IPC=y
 CONFIG_ANDROID_BINDER_ALLOC_KUNIT_TEST=y
diff --git a/drivers/android/tests/Makefile b/drivers/android/tests/Makefile
index 6780967e573b..27268418eb03 100644
--- a/drivers/android/tests/Makefile
+++ b/drivers/android/tests/Makefile
@@ -1,3 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
+#
+# Copyright 2025 Google LLC.
+#
 
 obj-$(CONFIG_ANDROID_BINDER_ALLOC_KUNIT_TEST)	+= binder_alloc_kunit.o
diff --git a/drivers/android/tests/binder_alloc_kunit.c b/drivers/android/tests/binder_alloc_kunit.c
index 02aa4a135eb5..f8c05bf15c2d 100644
--- a/drivers/android/tests/binder_alloc_kunit.c
+++ b/drivers/android/tests/binder_alloc_kunit.c
@@ -1,6 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Test cases for binder allocator code
+ * Test cases for binder allocator code.
+ *
+ * Copyright 2025 Google LLC.
+ * Author: Tiffany Yang <ynaffit@google.com>
  */
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-- 
2.50.0.727.gbf7dc18ff4-goog


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

* [PATCH v2 2/2] binder: Use seq_buf in binder_alloc kunit tests
  2025-07-22 23:45 [PATCH v2 1/2] binder: Add copyright notice to new kunit files Tiffany Yang
@ 2025-07-22 23:45 ` Tiffany Yang
  2025-07-23  7:32   ` Kees Cook
  2025-07-25 19:38   ` Carlos Llamas
  2025-07-25 19:38 ` [PATCH v2 1/2] binder: Add copyright notice to new kunit files Carlos Llamas
  1 sibling, 2 replies; 5+ messages in thread
From: Tiffany Yang @ 2025-07-22 23:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Carlos Llamas, Joel Fernandes, kernel-team, Greg Kroah-Hartman,
	Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
	Christian Brauner, Suren Baghdasaryan, Kees Cook

Replace instances of snprintf with seq_buf functions, as suggested by
Kees [1].

[1] https://lore.kernel.org/all/202507160743.15E8044@keescook/

Fixes: d1934ed9803c ("binder: encapsulate individual alloc test cases")
Suggested-by: Kees Cook <kees@kernel.org>
Cc: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Tiffany Yang <ynaffit@google.com>
---
This patch is based on top of char-misc-next.
---
 drivers/android/tests/binder_alloc_kunit.c | 46 ++++++++++------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/android/tests/binder_alloc_kunit.c b/drivers/android/tests/binder_alloc_kunit.c
index f8c05bf15c2d..9b884d977f76 100644
--- a/drivers/android/tests/binder_alloc_kunit.c
+++ b/drivers/android/tests/binder_alloc_kunit.c
@@ -15,6 +15,7 @@
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <linux/mman.h>
+#include <linux/seq_buf.h>
 #include <linux/sizes.h>
 
 #include "../binder_alloc.h"
@@ -107,40 +108,33 @@ static const char *const buf_end_align_type_strs[LOOP_END] = {
 };
 
 struct binder_alloc_test_case_info {
+	char alignments[ALIGNMENTS_BUFLEN];
+	struct seq_buf alignments_sb;
 	size_t *buffer_sizes;
 	int *free_sequence;
-	char alignments[ALIGNMENTS_BUFLEN];
 	bool front_pages;
 };
 
-static void stringify_free_seq(struct kunit *test, int *seq, char *buf,
-			       size_t buf_len)
+static void stringify_free_seq(struct kunit *test, int *seq, struct seq_buf *sb)
 {
-	size_t bytes = 0;
 	int i;
 
-	for (i = 0; i < BUFFER_NUM; i++) {
-		bytes += snprintf(buf + bytes, buf_len - bytes, "[%d]", seq[i]);
-		if (bytes >= buf_len)
-			break;
-	}
-	KUNIT_EXPECT_LT(test, bytes, buf_len);
+	for (i = 0; i < BUFFER_NUM; i++)
+		seq_buf_printf(sb, "[%d]", seq[i]);
+
+	KUNIT_EXPECT_FALSE(test, seq_buf_has_overflowed(sb));
 }
 
 static void stringify_alignments(struct kunit *test, int *alignments,
-				 char *buf, size_t buf_len)
+				 struct seq_buf *sb)
 {
-	size_t bytes = 0;
 	int i;
 
-	for (i = 0; i < BUFFER_NUM; i++) {
-		bytes += snprintf(buf + bytes, buf_len - bytes, "[ %d:%s ]", i,
-				  buf_end_align_type_strs[alignments[i]]);
-		if (bytes >= buf_len)
-			break;
-	}
+	for (i = 0; i < BUFFER_NUM; i++)
+		seq_buf_printf(sb, "[ %d:%s ]", i,
+			       buf_end_align_type_strs[alignments[i]]);
 
-	KUNIT_EXPECT_LT(test, bytes, buf_len);
+	KUNIT_EXPECT_FALSE(test, seq_buf_has_overflowed(sb));
 }
 
 static bool check_buffer_pages_allocated(struct kunit *test,
@@ -311,19 +305,20 @@ static void permute_frees(struct kunit *test, struct binder_alloc *alloc,
 	int i;
 
 	if (index == BUFFER_NUM) {
-		char freeseq_buf[FREESEQ_BUFLEN];
+		DECLARE_SEQ_BUF(freeseq_sb, FREESEQ_BUFLEN);
 
 		case_failed = binder_alloc_test_alloc_free(test, alloc, tc, end);
 		*runs += 1;
 		*failures += case_failed;
 
 		if (case_failed || PRINT_ALL_CASES) {
-			stringify_free_seq(test, tc->free_sequence, freeseq_buf,
-					   FREESEQ_BUFLEN);
+			stringify_free_seq(test, tc->free_sequence,
+					   &freeseq_sb);
 			kunit_err(test, "case %lu: [%s] | %s - %s - %s", *runs,
 				  case_failed ? "FAILED" : "PASSED",
 				  tc->front_pages ? "front" : "back ",
-				  tc->alignments, freeseq_buf);
+				  seq_buf_str(&tc->alignments_sb),
+				  seq_buf_str(&freeseq_sb));
 		}
 
 		return;
@@ -383,8 +378,9 @@ static void gen_buf_offsets(struct kunit *test, struct binder_alloc *alloc,
 	if (index == BUFFER_NUM) {
 		struct binder_alloc_test_case_info tc = {0};
 
-		stringify_alignments(test, alignments, tc.alignments,
-				     ALIGNMENTS_BUFLEN);
+		seq_buf_init(&tc.alignments_sb, tc.alignments,
+			     ALIGNMENTS_BUFLEN);
+		stringify_alignments(test, alignments, &tc.alignments_sb);
 
 		gen_buf_sizes(test, alloc, &tc, end_offset, runs, failures);
 		return;
-- 
2.50.0.727.gbf7dc18ff4-goog


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

* Re: [PATCH v2 2/2] binder: Use seq_buf in binder_alloc kunit tests
  2025-07-22 23:45 ` [PATCH v2 2/2] binder: Use seq_buf in binder_alloc kunit tests Tiffany Yang
@ 2025-07-23  7:32   ` Kees Cook
  2025-07-25 19:38   ` Carlos Llamas
  1 sibling, 0 replies; 5+ messages in thread
From: Kees Cook @ 2025-07-23  7:32 UTC (permalink / raw)
  To: Tiffany Yang
  Cc: linux-kernel, Carlos Llamas, Joel Fernandes, kernel-team,
	Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
	Martijn Coenen, Christian Brauner, Suren Baghdasaryan

On Tue, Jul 22, 2025 at 04:45:07PM -0700, Tiffany Yang wrote:
> Replace instances of snprintf with seq_buf functions, as suggested by
> Kees [1].
> 
> [1] https://lore.kernel.org/all/202507160743.15E8044@keescook/
> 
> Fixes: d1934ed9803c ("binder: encapsulate individual alloc test cases")
> Suggested-by: Kees Cook <kees@kernel.org>
> Cc: Joel Fernandes <joelagnelf@nvidia.com>
> Signed-off-by: Tiffany Yang <ynaffit@google.com>
> ---
> This patch is based on top of char-misc-next.
> ---
>  drivers/android/tests/binder_alloc_kunit.c | 46 ++++++++++------------
>  1 file changed, 21 insertions(+), 25 deletions(-)

Yay, always nice to see using an alternative API results in fewer lines! :)

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

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

* Re: [PATCH v2 1/2] binder: Add copyright notice to new kunit files
  2025-07-22 23:45 [PATCH v2 1/2] binder: Add copyright notice to new kunit files Tiffany Yang
  2025-07-22 23:45 ` [PATCH v2 2/2] binder: Use seq_buf in binder_alloc kunit tests Tiffany Yang
@ 2025-07-25 19:38 ` Carlos Llamas
  1 sibling, 0 replies; 5+ messages in thread
From: Carlos Llamas @ 2025-07-25 19:38 UTC (permalink / raw)
  To: Tiffany Yang
  Cc: linux-kernel, Joel Fernandes, kernel-team, Greg Kroah-Hartman,
	Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
	Christian Brauner, Suren Baghdasaryan

On Tue, Jul 22, 2025 at 04:45:06PM -0700, Tiffany Yang wrote:
> Clean up for the binder_alloc kunit test series. Add a copyright notice
> to new files, as suggested by Carlos [1].
> 
> [1] https://lore.kernel.org/all/CAFuZdDLD=3CBOLSWw3VxCf7Nkf884SSNmt1wresQgxgBwED=eQ@mail.gmail.com/
> 
> Fixes: 5e024582f494 ("binder: Scaffolding for binder_alloc KUnit tests")
> Suggested-by: Carlos Llamas <cmllamas@google.com>
> Cc: Joel Fernandes <joelagnelf@nvidia.com>
> Signed-off-by: Tiffany Yang <ynaffit@google.com>
> ---

It looks like Greg has picked up this patch already. fwiw:

Acked-by: Carlos Llamas <cmllamas@google.com>

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

* Re: [PATCH v2 2/2] binder: Use seq_buf in binder_alloc kunit tests
  2025-07-22 23:45 ` [PATCH v2 2/2] binder: Use seq_buf in binder_alloc kunit tests Tiffany Yang
  2025-07-23  7:32   ` Kees Cook
@ 2025-07-25 19:38   ` Carlos Llamas
  1 sibling, 0 replies; 5+ messages in thread
From: Carlos Llamas @ 2025-07-25 19:38 UTC (permalink / raw)
  To: Tiffany Yang
  Cc: linux-kernel, Joel Fernandes, kernel-team, Greg Kroah-Hartman,
	Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
	Christian Brauner, Suren Baghdasaryan, Kees Cook

On Tue, Jul 22, 2025 at 04:45:07PM -0700, Tiffany Yang wrote:
> Replace instances of snprintf with seq_buf functions, as suggested by
> Kees [1].
> 
> [1] https://lore.kernel.org/all/202507160743.15E8044@keescook/
> 
> Fixes: d1934ed9803c ("binder: encapsulate individual alloc test cases")
> Suggested-by: Kees Cook <kees@kernel.org>
> Cc: Joel Fernandes <joelagnelf@nvidia.com>
> Signed-off-by: Tiffany Yang <ynaffit@google.com>
> ---

Acked-by: Carlos Llamas <cmllamas@google.com>

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

end of thread, other threads:[~2025-07-25 19:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-22 23:45 [PATCH v2 1/2] binder: Add copyright notice to new kunit files Tiffany Yang
2025-07-22 23:45 ` [PATCH v2 2/2] binder: Use seq_buf in binder_alloc kunit tests Tiffany Yang
2025-07-23  7:32   ` Kees Cook
2025-07-25 19:38   ` Carlos Llamas
2025-07-25 19:38 ` [PATCH v2 1/2] binder: Add copyright notice to new kunit files Carlos Llamas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.