__alloc_flex(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 __alloc_flex β€” Kernel API Manual ✨

Hiii bestie, welcome to the page for __alloc_flex from the Linux Kernel API Manual πŸ’– This one's a macro (iykyk) and it's lowkey iconic β€” it's gonna hand you a struct with a little extra room at the end for your flexible array member. Let's get into it 🫢


✨ NAME ✨

__alloc_flex β€” allocate an object that has a trailing flexible array πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

__alloc_flex (KMALLOC , GFP , TYPE , FAM , COUNT );

That's the whole vibe. Five things go in, one pointer comes out πŸ‘‘


πŸ¦‹ ARGUMENTS πŸ¦‹

  • KMALLOC β€” the kmalloc wrapper function you wanna use for the allocation, bestie. Pick your fave πŸ’«
  • GFP β€” the GFP flags for the allocation 🌱 (yes they matter, no you can't skip them)
  • TYPE β€” the type of structure you're allocating space for, like the actual struct name πŸ—οΈ
  • FAM β€” the name of the flexible array member inside the TYPE struct 🌈 (the trailing bit, the main character of the tail end)
  • COUNT β€” how many FAM elements you want space for πŸ”’ like, how many lil guys are riding along at the end

⭐ RETURN ⭐

You get back a newly allocated pointer to TYPE with COUNT-many trailing FAM elements πŸ’–

OR you get NULL 😭 β€” and that happens in two cases, no cap:

  • the allocation failed, or
  • COUNT cannot be represented by the member of TYPE that counts the FAM elements (the one annotated via __counted_by) πŸ™ˆ
So fr fr, always check for NULL. It's giving "trust me bro" if you don't 🚨

πŸ”₯ SEE ALSO πŸ”₯

Kernel file ./include/linux/slab.h β€” and honestly the whole slab/allocator friend group 🫢:


Okay that's the whole page, you ate that πŸ’…βœ¨ This lil masterpiece lives over in ./include/linux and it's dated October 2026, filed under __alloc_flex(9). Go forth and allocate responsibly, bestie πŸ§šπŸ’œ

πŸ“¦ where this page comes from