Silva: How to use the new counted_by attribute in C (and Linux)
Gustavo A. R. Silva describesthe path to safer flexible arrays in the kernel, thanks to thecounted_by attribute supported by Clang18 and GCC15.
There are a number of requirements to properly use thecounted_by attribute. One crucial requirement is that thecounter must be initialized before the first reference to theflexible-array member. Another requirement is that the array mustalways contain at least as many elements as indicated by thecounter.
See also: this article from 2023.