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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jun 8, 2024 at 2:01 AM Benjamin Tissoires <bentiss@xxxxxxxxxx> 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@xxxxxxxxxx>





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux