kmalloc_flex(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– kmalloc_flex(9) β€” from the Kernel API Manual, bestie πŸŽ€

okay so picture this: you're in the kernel, you have a struct with a flexible array member at the end, and you need exactly one of them β€” sized just right for however many FAM elements you want. that's the whole vibe of kmalloc_flex. it's giving one-stop-shop, no cap. ✨


🌸 SYNOPSIS 🌸

kmalloc_flex (VAR_OR_TYPE , FAM , COUNT , ... );

like, that's it. that's the call. four-ish things and you're done 🫢


✨ ARGUMENTS ✨

  • VAR_OR_TYPE β€” the variable or the type you wanna allocate (flex array included, obviously πŸ’…). you can hand it a type or a var, either eats.
  • FAM β€” the name of the flexible array member on that struct. yes, the one doing all the work at the end of the struct. she's the main character πŸ”₯
  • COUNT β€” how many flexible-array-member elements you want, fr fr. just the number, bestie.
  • ... β€” optional GFP flags for the allocation. and if you don't specify any? it defaults to GFP_KERNEL like a sweetie. no stress πŸ’œ

πŸ‘‘ RETURN πŸ‘‘

on success you get a newly allocated pointer to VAR_OR_TYPE β€” iconic, slay, allocated. on failure you get NULL, and that's your cue to handle it (don't ignore her 😭).

⚠️ ngl there's a catch worth knowing: if FAM has been annotated with __counted_by, the allocation will immediately fail if COUNT is larger than what the type of the struct's counter variable can represent. like it just says no. no graceful degradation, no vibes β€” straight to fail town πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

okay the friend group is large, but they're all icons, so:

Kernel file ./include/linux/slab.h πŸ’« plus the whole crew:


and that's the page, bestie 🌈 this one comes from ./include/linux and it's dated October 2026 β€” go forth and allocate responsibly, mwah πŸ’…πŸ’–

πŸ“¦ where this page comes from