list_first_or_null_rcu(9)
β¨ 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 thelist_headwithin 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:
list_for_each_rcu(9)list_tail_rcu(9)list_add_rcu(9)list_add_tail_rcu(9)list_del_rcu(9)list_bidir_del_rcu(9)hlist_del_init_rcu(9)list_replace_rcu(9)list_splice_rcu(9)__list_splice_init_rcu(9)list_splice_init_rcu(9)list_splice_tail_init_rcu(9)list_entry_rcu(9)list_next_or_null_rcu(9)list_for_each_entry_rcu(9)list_for_each_entry_srcu(9)list_entry_lockless(9)list_for_each_entry_lockless(9)list_for_each_entry_continue_rcu(9)list_for_each_entry_from_rcu(9)hlist_del_rcu(9)hlist_replace_rcu(9)hlists_swap_heads_rcu(9)hlist_add_head_rcu(9)hlist_add_tail_rcu(9)hlist_add_before_rcu(9)hlist_add_behind_rcu(9)hlist_for_each_entry_rcu(9)hlist_for_each_entry_srcu(9)hlist_for_each_entry_rcu_notrace(9)hlist_for_each_entry_rcu_bh(9)hlist_for_each_entry_continue_rcu(9)hlist_for_each_entry_continue_rcu_bh(9)hlist_for_each_entry_from_rcu(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms