On Wed, May 14, 2025 at 1:53 PM Song Liu song@kernel.org wrote:
On Tue, May 13, 2025 at 9:36 AM T.J. Mercier tjmercier@google.com wrote:
This test creates a udmabuf, and a dmabuf from the system dmabuf heap, and uses a BPF program that prints dmabuf metadata with the new dmabuf_iter to verify they can be found.
Signed-off-by: T.J. Mercier tjmercier@google.com Acked-by: Christian König christian.koenig@amd.com
Acked-by: Song Liu song@kernel.org
Thanks.
With one more comment below.
[...]
diff --git a/tools/testing/selftests/bpf/progs/dmabuf_iter.c b/tools/testing/selftests/bpf/progs/dmabuf_iter.c new file mode 100644 index 000000000000..2a1b5397196d --- /dev/null +++ b/tools/testing/selftests/bpf/progs/dmabuf_iter.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2025 Google LLC */ +#include <vmlinux.h> +#include <bpf/bpf_core_read.h> +#include <bpf/bpf_helpers.h>
+/* From uapi/linux/dma-buf.h */ +#define DMA_BUF_NAME_LEN 32
+char _license[] SEC("license") = "GPL";
+/*
- Fields output by this iterator are delimited by newlines. Convert any
- newlines in user-provided printed strings to spaces.
- */
+static void sanitize_string(char *src, size_t size) +{
for (char *c = src; *c && (size_t)(c - src) < size; ++c)
We should do the size check first, right? IOW:
for (char *c = src; (size_t)(c - src) < size && *c; ++c)
Yeah if you call the function with size = 0, which is kinda questionable and not possible with the non-zero array size that is tied to immutable UAPI. Let's change it like you suggest.
if (*c == '\n')
*c = ' ';
+}
[...]
linaro-mm-sig@lists.linaro.org