@@ -24,21 +24,19 @@ extern "C" {
24
24
#endif
25
25
26
26
/**
27
- * struct list_head - Head and node of a doubly-linked list
28
- * @prev: pointer to the previous node in the list
29
- * @next: pointer to the next node in the list
27
+ * struct list_head - Node structure for a circular doubly-linked list
28
+ * @next: Pointer to the next node in the list.
29
+ * @prev: Pointer to the previous node in the list.
30
30
*
31
- * The simple doubly-linked list consists of a head and nodes attached to
32
- * this head. Both node and head share the same struct type. The list_*
33
- * functions and macros can be used to access and modify this data structure.
31
+ * Defines both the head and nodes of a circular doubly-linked list. The head's
32
+ * @next points to the first node and @prev to the last node; in an empty list,
33
+ * both point to the head itself. All nodes, including the head, share this
34
+ * structure type.
34
35
*
35
- * The @prev pointer of the list head points to the last list node of the
36
- * list and @next points to the first list node of the list. For an empty list,
37
- * both member variables point to the head.
38
- *
39
- * The list nodes are usually embedded in a container structure which holds the
40
- * actual data. Such container structure is called entry. The helper list_entry
41
- * can be used to calculate the structure address from the address of the node.
36
+ * Nodes are typically embedded within a container structure holding actual
37
+ * data, accessible via the list_entry() helper, which computes the container's
38
+ * address from a node pointer. The list_* functions and macros provide an API
39
+ * for manipulating this data structure efficiently.
42
40
*/
43
41
struct list_head {
44
42
struct list_head * prev ;
@@ -67,25 +65,23 @@ struct list_head {
67
65
#endif
68
66
69
67
/**
70
- * LIST_HEAD - Declare list head and initialize it
68
+ * LIST_HEAD - Define and initialize a circular list head
71
69
* @head: name of the new list
72
70
*/
73
71
#define LIST_HEAD (head ) struct list_head head = {&(head), &(head)}
74
72
75
73
/**
76
74
* INIT_LIST_HEAD() - Initialize empty list head
77
- * @head: pointer to list head
78
- *
79
- * This can also be used to initialize a unlinked list node.
75
+ * @head: Pointer to the list_head structure to initialize.
80
76
*
81
- * A node is usually linked inside a list, will be added to a list in
82
- * the near future or the entry containing the node will be free'd soon.
77
+ * It sets both @next and @prev to point to the structure itself. The
78
+ * initialization applies to either a list head or an unlinked node that is
79
+ * not yet part of a list.
83
80
*
84
- * But an unlinked node may be given to a function which uses list_del(_init)
85
- * before it ends up in a previously mentioned state. The list_del(_init) on an
86
- * initialized node is well defined and safe. But the result of a
87
- * list_del(_init) on an uninitialized node is undefined (unrelated memory is
88
- * modified, crashes, ...).
81
+ * Unlinked nodes may be passed to functions using 'list_del()' or
82
+ * 'list_del_init()', which are safe only on initialized nodes. Applying these
83
+ * operations to an uninitialized node results in undefined behavior, such as
84
+ * memory corruption or crashes.
89
85
*/
90
86
static inline void INIT_LIST_HEAD (struct list_head * head )
91
87
{
@@ -94,9 +90,13 @@ static inline void INIT_LIST_HEAD(struct list_head *head)
94
90
}
95
91
96
92
/**
97
- * list_add() - Add a list node to the beginning of the list
98
- * @node: pointer to the new node
99
- * @head: pointer to the head of the list
93
+ * list_add - Insert a node at the beginning of a circular list
94
+ * @node: Pointer to the list_head structure to add.
95
+ * @head: Pointer to the list_head structure representing the list head.
96
+ *
97
+ * Adds the specified @node immediately after @head in a circular doubly-linked
98
+ * list, effectively placing it at the beginning. The existing first node, if
99
+ * any, shifts to follow @node, and the list's circular structure is maintained.
100
100
*/
101
101
static inline void list_add (struct list_head * node , struct list_head * head )
102
102
{
@@ -124,20 +124,22 @@ static inline void list_add_tail(struct list_head *node, struct list_head *head)
124
124
}
125
125
126
126
/**
127
- * list_del() - Remove a list node from the list
128
- * @node: pointer to the node
127
+ * list_del - Remove a node from a circular doubly-linked list
128
+ * @node: Pointer to the list_head structure to remove.
129
129
*
130
- * The node is only removed from the list. Neither the memory of the removed
131
- * node nor the memory of the entry containing the node is free'd. The node
132
- * has to be handled like an uninitialized node. Accessing the next or prev
133
- * pointer of the node is not safe.
130
+ * Removes @node from its list by updating the adjacent nodes’ pointers to
131
+ * bypass it. The node’s memory and its containing structure, if any, are not
132
+ * freed. After removal, @node is left unlinked and should be treated as
133
+ * uninitialized; accessing its @next or @prev pointers is unsafe and may cause
134
+ * undefined behavior.
134
135
*
135
- * Unlinked, initialized nodes are also uninitialized after list_del.
136
+ * Even previously initialized but unlinked nodes become uninitialized after
137
+ * this operation. To reintegrate @node into a list, it must be reinitialized
138
+ * (e.g., via INIT_LIST_HEAD).
136
139
*
137
- * LIST_POISONING can be enabled during build-time to provoke an invalid memory
138
- * access when the memory behind the next/prev pointer is used after a list_del.
139
- * This only works on systems which prohibit access to the predefined memory
140
- * addresses.
140
+ * If LIST_POISONING is enabled at build time, @next and @prev are set to
141
+ * invalid addresses to trigger memory access faults on misuse. This feature is
142
+ * effective only on systems that restrict access to these specific addresses.
141
143
*/
142
144
static inline void list_del (struct list_head * node )
143
145
{
@@ -154,11 +156,13 @@ static inline void list_del(struct list_head *node)
154
156
}
155
157
156
158
/**
157
- * list_del_init() - Remove a list node from the list and reinitialize it
158
- * @node: pointer to the node
159
+ * list_del_init - Remove a node and reinitialize it as unlinked
160
+ * @node: Pointer to the list_head structure to remove and reinitialize.
159
161
*
160
- * The removed node will not end up in an uninitialized state like when using
161
- * list_del. Instead the node is initialized again to the unlinked state.
162
+ * Removes @node from its circular doubly-linked list using list_del() and then
163
+ * reinitializes it as an unlinked node via INIT_LIST_HEAD(). Unlike list_del(),
164
+ * which leaves the node uninitialized, this ensures @node is safely reset to an
165
+ * empty, standalone state with @next and @prev pointing to itself.
162
166
*/
163
167
static inline void list_del_init (struct list_head * node )
164
168
{
@@ -167,10 +171,14 @@ static inline void list_del_init(struct list_head *node)
167
171
}
168
172
169
173
/**
170
- * list_empty() - Check if list head has no nodes attached
171
- * @head: pointer to the head of the list
174
+ * list_empty - Test if a circular list has no nodes
175
+ * @head: Pointer to the list_head structure representing the list head.
176
+ *
177
+ * Checks whether the circular doubly-linked list headed by @head is empty.
178
+ * A list is empty if @head’s @next points to itself, indicating no nodes are
179
+ * attached.
172
180
*
173
- * Return : 0 - list is not empty !0 - list is empty
181
+ * Returns : 0 if the list has nodes, non-zero if the list is empty.
174
182
*/
175
183
static inline int list_empty (const struct list_head * head )
176
184
{
@@ -181,7 +189,8 @@ static inline int list_empty(const struct list_head *head)
181
189
* list_is_singular() - Check if list head has exactly one node attached
182
190
* @head: pointer to the head of the list
183
191
*
184
- * Return: 0 - list is not singular !0 -list has exactly one entry
192
+ * Returns: 0 if the list is not singular, non-zero if the list has exactly one
193
+ * entry.
185
194
*/
186
195
static inline int list_is_singular (const struct list_head * head )
187
196
{
0 commit comments