sgl_free_n_order(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ sgl_free_n_order ✨

okay bestie, welcome to the sgl_free_n_order page from the Kernel API Manual β€” yes we're in kernel land today, and yes you're gonna slay it πŸ’…


🌸 NAME 🌸

sgl_free_n_order β€” free a scatterlist and its pages πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

void sgl_free_n_order (struct scatterlist *sgl , int nents , int order );

like, that's the whole signature. no cap. ✨


πŸ’– ARGUMENTS πŸ’–

  • sgl β€” the scatterlist, and it's got one or more elements in it 🫢
  • nents β€” the maximum number of elements to free. max, not exact. keep that in mind bestie πŸ‘€
  • order β€” this is literally just the second argument you hand to __free_pages ⭐

πŸŽ€ NOTES πŸŽ€

okay so this is the part where you actually pay attention 😭

  • if several scatterlists have been chained together and each chain element is freed separately, then it is essential to set nents correctly β€” otherwise a page could get freed twice. and a double free is not the vibe. not iconic. avoid at all costs πŸ’€
  • but if you'd rather free all the pages in a chained scatterlist at once? easy. just set nents to a high number and boom, done 🌈
fr fr, that nents value is the whole plot. get it wrong and the kernel gets mad at you πŸ™ˆ

πŸ”₯ SEE ALSO πŸ”₯

they really said "include everything" huh 😭 here's the whole friend group, all living in the kernel file ./lib/scatterlist.c:

sg_nents(9), sg_nents_for_len(9), sg_nents_for_dma(9), sg_last(9), sg_init_table(9), sg_init_one(9), __sg_free_table(9), sg_free_append_table(9), sg_free_table(9), __sg_alloc_table(9), sg_alloc_table(9), sg_alloc_append_table_from_pages(9), sg_alloc_table_from_pages_segment(9), sgl_alloc_order(9), sgl_alloc(9), sgl_free_order(9), sgl_free(9), sg_miter_start(9), sg_miter_skip(9), sg_miter_next(9), sg_miter_stop(9), sg_copy_buffer(9), sg_copy_from_buffer(9), sg_copy_to_buffer(9), sg_pcopy_from_buffer(9), sg_pcopy_to_buffer(9), sg_zero_buffer(9), extract_iter_to_sg(9)

like. that's a lot of friends. collect them all πŸ’œ


and that's the page!! mwah 🫢 this one lives in ./lib and it's dated October 2026 β€” so go forth, free your scatterlist, and don't double-free anything. xoxo πŸ’…βœ¨πŸ“

πŸ“¦ where this page comes from