On 12/09/2023 11:22, Zachary Leaf wrote:
- case BPF_PROG_BIND_MAP:
dest->prog_bind_map.prog_fd = cattr->prog_bind_map.prog_fd;
dest->prog_bind_map.map_fd = cattr->prog_bind_map.map_fd;
dest->prog_bind_map.flags = cattr->prog_bind_map.flags;
break;
- };
Considering the really large number of assignments, I think it would be worth introducing a macro that takes dest, cattr and the name of the member to copy. That would shorten things a bit for nested structs, but most importantly it would prevent typos slipping in.
That's a good idea.
I've added a generic copy_field() macro in include/linux/stddef.h:
#define copy_field(DEST, SRC, FIELD) \ ((DEST)->FIELD = (SRC)->FIELD)
I wasn't thinking about adding it to a generic header but considering that it is indeed a completely generic macro, I don't see why not! stddef.h looks like a reasonable place to add it. Usual comment: macro arguments should not be capitalised.
All macro arguments in include/linux/stddef.h are capitalised so I've made it consistent with that.
Ah yes that makes sense. Looks like offsetof() has had capitalised arguments since <forever>, and as a result everything else added to that header followed the same convention. I doubt there is much logic to it, but local consistency always wins!
Kevin