list_first_or_null_rcu(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ list_first_or_null_rcu β€” get the first element from a list ✨

okay so we're in the Kernel API Manual bestie, and this page is about list_first_or_null_rcu(9) β€” yes that whole mouthful, i promise it's actually so useful 🫢


πŸ’– NAME πŸ’–

list_first_or_null_rcu β€” get the first element from a list 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

list_first_or_null_rcu (ptr , type , member );

that's it. three little args. look at her go πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • ptr β€” the list head to take the element from. like, the starting point, the main character of this whole operation πŸ‘‘
  • type β€” the type of the struct this is embedded in. yes it's embedded, she's not a standalone queen, she lives inside a bigger struct πŸ’œ
  • member β€” the name of the list_head within the struct. so we know exactly which little field we're vibing with 🎯

🌈 DESCRIPTION 🌈

okay here's the tea, and it's important: note that if the list is empty, it returns NULL. ✨ no element, no problem, you just get NULL and you better check for it, bestie πŸ™ˆ

and now the iconic part β€” this primitive may safely run concurrently with the _rcu list-mutation primitives such as list_add_rcu, as long as it's guarded by rcu_read_lock. πŸ”₯ that rcu_read_lock guard is not optional, it's the whole vibe check. skip it and you're in undefined-behaviour territory, fr fr 😭

⚠️ no cap: concurrent safety here is conditional. rcu_read_lock is the condition. don't fumble that.

πŸ‘‘ SEE ALSO πŸ‘‘

bestie the cross-reference list is long and i'm obsessed, every single one made it in πŸ‘‡

Kernel file ./include/linux/rculist.h:

like, she's connected to everyone. networking icon behavior πŸ’€πŸ’–


okay that's the whole page bestie, go forth and read your RCU lists safely ✨

sign-off time πŸŽ€ β€” this one lives in the kernel file ./include/linux, and the page itself is dated October 2026, so yeah, she's fresh. mwah πŸ’‹ πŸ¦‹πŸŒΈπŸ’œ

πŸ“¦ where this page comes from