Re: [PATCH V5 1/8] mm/slab: use unsigned long for orig_size to ensure proper metadata align
From: Alexander Potapenko
Date: Fri Jan 09 2026 - 04:37:27 EST
> > Instead of calculating the offset of the original size in several
> > places, should we maybe introduce a function that returns a pointer to
> > it?
>
> Good point.
>
> The calculation of various metadata offset (including the original size)
> is repeated in several places, and perhaps it's worth cleaning up,
> something like this:
>
> enum {
> FREE_POINTER_OFFSET,
> ALLOC_TRACK_OFFSET,
> FREE_TRACK_OFFSET,
> ORIG_SIZE_OFFSET,
> KASAN_ALLOC_META_OFFSET,
> OBJ_EXT_OFFSET,
> FINAL_ALIGNMENT_PADDING_OFFSET,
> ...
> };
>
> orig_size = *(unsigned long *)get_metadata_ptr(p, ORIG_SIZE_OFFSET);
An alternative would be to declare a struct containing all the
metadata fields and use offsetof() (or simply do a cast and access the
fields via the struct pointer)