Thread (22 messages) 22 messages, 2 authors, 2024-06-14

Re: [PATCH HID v3 03/16] HID: bpf: implement HID-BPF through bpf_struct_ops

From: Alexei Starovoitov <hidden>
Date: 2024-06-10 18:34:51
Also in: bpf, linux-doc, linux-kselftest, lkml

On Sat, Jun 8, 2024 at 2:01 AM Benjamin Tissoires [off-list ref] wrote:
+
+static int hid_bpf_ops_init_member(const struct btf_type *t,
+                                const struct btf_member *member,
+                                void *kdata, const void *udata)
+{
+       u32 moff = __btf_member_bit_offset(t, member) / 8;
+       u32 flags;
+
+       switch (moff) {
+       case offsetof(struct hid_bpf_ops, hid_id):
+               /* For hid_id and flags fields, this function has to copy it
+                * and return 1 to indicate that the data has been handled by
+                * the struct_ops type, or the verifier will reject the map if
+                * the value of those fields is not zero.
+                */
+               ((struct hid_bpf_ops *)kdata)->hid_id = ((struct hid_bpf_ops *)udata)->hid_id;
+               return 1;
+       case offsetof(struct hid_bpf_ops, flags):
+               flags = ((struct hid_bpf_ops *)udata)->flags;
+               if (flags & ~BPF_F_BEFORE)
+                       return -EINVAL;
+               ((struct hid_bpf_ops *)kdata)->flags = flags;
minor nit: I'd cast kdata/udate in the beginning of
the function to make the lines shorter and less verbose.
Similar to how bpf_tcp_ca_init_member() does it.

Acked-by: Alexei Starovoitov <ast@kernel.org>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help