On Tue, May 13, 2025 at 9:36 AM T.J. Mercier <tjmerc...@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 <tjmerc...@google.com>
> Acked-by: Christian König <christian.koe...@amd.com>

Acked-by: Song Liu <s...@kernel.org>

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)



> +               if (*c == '\n')
> +                       *c = ' ';
> +}
> +
[...]

Reply via email to