Re: [PATCH] btf: Use BIN_ATTR_SIMPLE_RO() to define vmlinux attribute

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

 



On Fri, Nov 22, 2024 at 4:57 AM Thomas Weißschuh <linux@xxxxxxxxxxxxxx> wrote:
>
> The usage of the macro allows to remove the custom handler function,
> saving some memory. Additionally the code is easier to read.
>
> Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
> ---
> Something similar can be done to btf_module_read() in kernel/bpf/btf.c.
> But doing it here and now would lead to some conflicts with some other
> sysfs refactorings I'm doing. It will be part of a future series.
> ---
>  kernel/bpf/sysfs_btf.c | 21 +++++----------------
>  1 file changed, 5 insertions(+), 16 deletions(-)
>
> diff --git a/kernel/bpf/sysfs_btf.c b/kernel/bpf/sysfs_btf.c
> index fedb54c94cdb830a4890d33677dcc5a6e236c13f..a24381f933d0b80b11116d05463c35e9fa66acb1 100644
> --- a/kernel/bpf/sysfs_btf.c
> +++ b/kernel/bpf/sysfs_btf.c
> @@ -12,34 +12,23 @@
>  extern char __start_BTF[];
>  extern char __stop_BTF[];
>
> -static ssize_t
> -btf_vmlinux_read(struct file *file, struct kobject *kobj,
> -                struct bin_attribute *bin_attr,
> -                char *buf, loff_t off, size_t len)
> -{
> -       memcpy(buf, __start_BTF + off, len);
> -       return len;
> -}
> -
> -static struct bin_attribute bin_attr_btf_vmlinux __ro_after_init = {
> -       .attr = { .name = "vmlinux", .mode = 0444, },
> -       .read = btf_vmlinux_read,
> -};
> +static __ro_after_init BIN_ATTR_SIMPLE_RO(vmlinux);

To be honest I really don't like when code is hidden by macros like this.
Looks like you guys already managed to sprinkle it in a few places.

btf_vmlinux_read() can be replaced with sysfs_bin_attr_simple_read().
This part is fine, but macro pls dont.
It doesn't help readability.
imo mode = 0444 vs mode = 0400 is easier to understand
instead of _RO vs _ADMIN_RO suffix.
__ro_after_init should be a part of it, at least.

I'd like to hear what other maintainers think about
such obfuscation.





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux