diff options
author | Gustavo A. R. Silva <gustavoars@kernel.org> | 2020-06-09 04:22:33 +0300 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2020-06-17 06:45:08 +0300 |
commit | b19d57d0f3cc6f1022edf94daf1d70506a09e3c2 (patch) | |
tree | c0bf158b81e425eeb159a12dd173a421cf7ddef1 /mm | |
parent | b3a9e3b9622ae10064826dccb4f7a52bd88c7407 (diff) | |
download | linux-b19d57d0f3cc6f1022edf94daf1d70506a09e3c2.tar.xz |
overflow.h: Add flex_array_size() helper
Add flex_array_size() helper for the calculation of the size, in bytes,
of a flexible array member contained within an enclosing structure.
Example of usage:
struct something {
size_t count;
struct foo items[];
};
struct something *instance;
instance = kmalloc(struct_size(instance, items, count), GFP_KERNEL);
instance->count = count;
memcpy(instance->items, src, flex_array_size(instance, items, instance->count));
The helper returns SIZE_MAX on overflow instead of wrapping around.
Additionally replaces parameter "n" with "count" in struct_size() helper
for greater clarity and unification.
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20200609012233.GA3371@embeddedor
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'mm')
0 files changed, 0 insertions, 0 deletions