u32 hash; /* Hash in the hastable */
u32 size; /* Number of frames in the stack */
union handle_parts handle;
- unsigned long entries[1]; /* Variable-sized array of entries. */
+ unsigned long entries[]; /* Variable-sized array of entries. */
};
static void *stack_slabs[STACK_ALLOC_MAX_SLABS];
static struct stack_record *depot_alloc_stack(unsigned long *entries, int size,
u32 hash, void **prealloc, gfp_t alloc_flags)
{
- int required_size = offsetof(struct stack_record, entries) +
- sizeof(unsigned long) * size;
struct stack_record *stack;
+ size_t required_size = struct_size(stack, entries, size);
required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN);
stack->handle.slabindex = depot_index;
stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN;
stack->handle.valid = 1;
- memcpy(stack->entries, entries, size * sizeof(unsigned long));
+ memcpy(stack->entries, entries, flex_array_size(stack, entries, size));
depot_offset += required_size;
return stack;
static inline u32 hash_stack(unsigned long *entries, unsigned int size)
{
return jhash2((u32 *)entries,
- size * sizeof(unsigned long) / sizeof(u32),
- STACK_HASH_SEED);
+ array_size(size, sizeof(*entries)) / sizeof(u32),
+ STACK_HASH_SEED);
}
/* Use our own, non-instrumented version of memcmp().