zfs/module
Richard Yao a93c30a2f2 Cleanup: Replace oldstyle struct hack with C99 flexible array members
The Linux 5.16.14 kernel's coccicheck caught this. The semantic
patch that caught it was:

./scripts/coccinelle/misc/flexible_array.cocci

However, unlike the cases where the GNU zero length array extension had
been used, coccicheck would not suggest patches for the older style
single member arrays. That was good because blindly changing them would
break size calculations in most cases.

Therefore, this required care to make sure that we did not break size
calculations. In the case of `indirect_split_t`, we use
`offsetof(indirect_split_t, is_child[is->is_children])` to calculate
size. This might be subtly wrong according to an old mailing list
thread:

https://inbox.sourceware.org/gcc-prs/20021226123454.27019.qmail@sources.redhat.com/T/

That is because the C99 specification should consider the flexible array
members to start at the end of a structure, but compilers prefer to put
padding at the end. A suggestion was made to allow compilers to allocate
padding after the VLA like compilers already did:

http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n983.htm

However, upon thinking about it, whether or not we allocate end of
structure padding does not matter, so using offsetof() to calculate the
size of the structure is fine, so long as we do not mix it with sizeof()
on structures with no array members.

In the case that we mix them and padding causes offsetof(struct_t,
vla_member[0]) to differ from sizeof(struct_t), we would be doing unsafe
operations if we underallocate via `offsetof()` and then overcopy via
sizeof().

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14372
2023-09-20 10:10:41 -07:00
..
avl AVL: Remove obsolete branching optimizations 2022-07-26 10:10:37 -07:00
icp Fix Clang 15 compilation errors 2023-06-05 18:25:57 -07:00
lua Cleanup: Replace oldstyle struct hack with C99 flexible array members 2023-09-20 10:10:41 -07:00
nvpair Update `checkstyle` workflow env to ubuntu-20.04 2021-12-08 13:27:56 -08:00
os Cleanup: Replace oldstyle struct hack with C99 flexible array members 2023-09-20 10:10:41 -07:00
spl Cleanup linux module kbuild files 2020-06-10 09:24:15 -07:00
unicode Illumos #15286: do_composition() needs sign awareness 2023-01-19 12:50:42 -08:00
zcommon Fix Clang 15 compilation errors 2023-06-05 18:25:57 -07:00
zfs Cleanup: Replace oldstyle struct hack with C99 flexible array members 2023-09-20 10:10:41 -07:00
zstd module: zstd: check we don't leak symbols; regenerate symbol map 2022-05-16 15:48:21 -07:00
.gitignore FreeBSD: Ignore symlink to i386 includes 2022-09-28 10:35:13 -07:00
Kbuild.in Fix Clang 15 compilation errors 2023-06-05 18:25:57 -07:00
Makefile.bsd FreeBSD: Silence clang unused-but-set-variable 2022-06-15 11:27:28 -07:00
Makefile.in Add support for $KERNEL_{CC,LD,LLVM} variables 2022-02-16 17:58:55 -08:00