Something went wrong. Try again.
(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Something went wrong. Try again.
C
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257/* SPDX-License-Identifier: GPL-2.0 */
/* * Copyright (c) 2025, Google LLC. * Pasha Tatashin <pasha.tatashin@soleen.com> */#ifndef _LINUX_LIST_PRIVATE_H#define _LINUX_LIST_PRIVATE_H
/** * DOC: Private List Primitives * * Provides a set of list primitives identical in function to those in * ``<linux/list.h>``, but designed for cases where the embedded * ``&struct list_head`` is private member. */
#include <linux/compiler.h>#include <linux/list.h>
#define __list_private_offset(type, member) \ ((size_t)(&ACCESS_PRIVATE(((type *)0), member)))
/** * list_private_entry - get the struct for this entry * @ptr: the &struct list_head pointer. * @type: the type of the struct this is embedded in. * @member: the identifier passed to ACCESS_PRIVATE. */#define list_private_entry(ptr, type, member) ({ \ const struct list_head *__mptr = (ptr); \ (type *)((char *)__mptr - __list_private_offset(type, member)); \})
/** * list_private_first_entry - get the first element from a list * @ptr: the list head to take the element from. * @type: the type of the struct this is embedded in. * @member: the identifier passed to ACCESS_PRIVATE. */#define list_private_first_entry(ptr, type, member) \ list_private_entry((ptr)->next, type, member)
/** * list_private_last_entry - get the last element from a list * @ptr: the list head to take the element from. * @type: the type of the struct this is embedded in. * @member: the identifier passed to ACCESS_PRIVATE. */#define list_private_last_entry(ptr, type, member) \ list_private_entry((ptr)->prev, type, member)
/** * list_private_next_entry - get the next element in list * @pos: the type * to cursor * @member: the name of the list_head within the struct. */#define list_private_next_entry(pos, member) \ list_private_entry(ACCESS_PRIVATE(pos, member).next, typeof(*(pos)), member)
/** * list_private_next_entry_circular - get the next element in list * @pos: the type * to cursor. * @head: the list head to take the element from. * @member: the name of the list_head within the struct. * * Wraparound if pos is the last element (return the first element). * Note, that list is expected to be not empty. */#define list_private_next_entry_circular(pos, head, member) \ (list_is_last(&ACCESS_PRIVATE(pos, member), head) ? \ list_private_first_entry(head, typeof(*(pos)), member) : \ list_private_next_entry(pos, member))
/** * list_private_prev_entry - get the prev element in list * @pos: the type * to cursor * @member: the name of the list_head within the struct. */#define list_private_prev_entry(pos, member) \ list_private_entry(ACCESS_PRIVATE(pos, member).prev, typeof(*(pos)), member)
/** * list_private_prev_entry_circular - get the prev element in list * @pos: the type * to cursor. * @head: the list head to take the element from. * @member: the name of the list_head within the struct. * * Wraparound if pos is the first element (return the last element). * Note, that list is expected to be not empty. */#define list_private_prev_entry_circular(pos, head, member) \ (list_is_first(&ACCESS_PRIVATE(pos, member), head) ? \ list_private_last_entry(head, typeof(*(pos)), member) : \ list_private_prev_entry(pos, member))
/** * list_private_entry_is_head - test if the entry points to the head of the list * @pos: the type * to cursor * @head: the head for your list. * @member: the name of the list_head within the struct. */#define list_private_entry_is_head(pos, head, member) \ list_is_head(&ACCESS_PRIVATE(pos, member), (head))
/** * list_private_for_each_entry - iterate over list of given type * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_head within the struct. */#define list_private_for_each_entry(pos, head, member) \ for (pos = list_private_first_entry(head, typeof(*pos), member); \ !list_private_entry_is_head(pos, head, member); \ pos = list_private_next_entry(pos, member))
/** * list_private_for_each_entry_reverse - iterate backwards over list of given type. * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_head within the struct. */#define list_private_for_each_entry_reverse(pos, head, member) \ for (pos = list_private_last_entry(head, typeof(*pos), member); \ !list_private_entry_is_head(pos, head, member); \ pos = list_private_prev_entry(pos, member))
/** * list_private_for_each_entry_continue - continue iteration over list of given type * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_head within the struct. * * Continue to iterate over list of given type, continuing after * the current position. */#define list_private_for_each_entry_continue(pos, head, member) \ for (pos = list_private_next_entry(pos, member); \ !list_private_entry_is_head(pos, head, member); \ pos = list_private_next_entry(pos, member))
/** * list_private_for_each_entry_continue_reverse - iterate backwards from the given point * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_head within the struct. * * Start to iterate over list of given type backwards, continuing after * the current position. */#define list_private_for_each_entry_continue_reverse(pos, head, member) \ for (pos = list_private_prev_entry(pos, member); \ !list_private_entry_is_head(pos, head, member); \ pos = list_private_prev_entry(pos, member))
/** * list_private_for_each_entry_from - iterate over list of given type from the current point * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_head within the struct. * * Iterate over list of given type, continuing from current position. */#define list_private_for_each_entry_from(pos, head, member) \ for (; !list_private_entry_is_head(pos, head, member); \ pos = list_private_next_entry(pos, member))
/** * list_private_for_each_entry_from_reverse - iterate backwards over list of given type * from the current point * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_head within the struct. * * Iterate backwards over list of given type, continuing from current position. */#define list_private_for_each_entry_from_reverse(pos, head, member) \ for (; !list_private_entry_is_head(pos, head, member); \ pos = list_private_prev_entry(pos, member))
/** * list_private_for_each_entry_safe - iterate over list of given type safe against removal of list entry * @pos: the type * to use as a loop cursor. * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_head within the struct. */#define list_private_for_each_entry_safe(pos, n, head, member) \ for (pos = list_private_first_entry(head, typeof(*pos), member), \ n = list_private_next_entry(pos, member); \ !list_private_entry_is_head(pos, head, member); \ pos = n, n = list_private_next_entry(n, member))
/** * list_private_for_each_entry_safe_continue - continue list iteration safe against removal * @pos: the type * to use as a loop cursor. * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_head within the struct. * * Iterate over list of given type, continuing after current point, * safe against removal of list entry. */#define list_private_for_each_entry_safe_continue(pos, n, head, member) \ for (pos = list_private_next_entry(pos, member), \ n = list_private_next_entry(pos, member); \ !list_private_entry_is_head(pos, head, member); \ pos = n, n = list_private_next_entry(n, member))
/** * list_private_for_each_entry_safe_from - iterate over list from current point safe against removal * @pos: the type * to use as a loop cursor. * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_head within the struct. * * Iterate over list of given type from current point, safe against * removal of list entry. */#define list_private_for_each_entry_safe_from(pos, n, head, member) \ for (n = list_private_next_entry(pos, member); \ !list_private_entry_is_head(pos, head, member); \ pos = n, n = list_private_next_entry(n, member))
/** * list_private_for_each_entry_safe_reverse - iterate backwards over list safe against removal * @pos: the type * to use as a loop cursor. * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_head within the struct. * * Iterate backwards over list of given type, safe against removal * of list entry. */#define list_private_for_each_entry_safe_reverse(pos, n, head, member) \ for (pos = list_private_last_entry(head, typeof(*pos), member), \ n = list_private_prev_entry(pos, member); \ !list_private_entry_is_head(pos, head, member); \ pos = n, n = list_private_prev_entry(n, member))
/** * list_private_safe_reset_next - reset a stale list_for_each_entry_safe loop * @pos: the loop cursor used in the list_for_each_entry_safe loop * @n: temporary storage used in list_for_each_entry_safe * @member: the name of the list_head within the struct. * * list_safe_reset_next is not safe to use in general if the list may be * modified concurrently (eg. the lock is dropped in the loop body). An * exception to this is if the cursor element (pos) is pinned in the list, * and list_safe_reset_next is called after re-taking the lock and before * completing the current iteration of the loop body. */#define list_private_safe_reset_next(pos, n, member) \ n = list_private_next_entry(pos, member)
#endif /* _LINUX_LIST_PRIVATE_H */