···15151616#define hash_head(table, key) (&(table)[(key) % HASH_SIZE(table)])17171818+static inline void __hash_init(struct hlist_head *ht, unsigned int sz)1919+{2020+ unsigned int i;2121+2222+ for (i = 0; i < sz; i++)2323+ INIT_HLIST_HEAD(&ht[i]);2424+}2525+2626+/**2727+ * hash_init - initialize a hash table2828+ * @table: hashtable to be initialized2929+ *3030+ * This has to be a macro since HASH_SIZE() will not work on pointers since3131+ * it calculates the size during preprocessing.3232+ */3333+#define hash_init(table) __hash_init(table, HASH_SIZE(table))3434+1835/**1936 * hash_add - add an object to a hashtable2037 * @table: hashtable to add to···4023 */4124#define hash_add(table, node, key) \4225 hlist_add_head(node, hash_head(table, key))2626+2727+/**2828+ * hash_del - remove an object from a hashtable2929+ * @node: &struct hlist_node of the object to remove3030+ */3131+static inline void hash_del(struct hlist_node *node)3232+{3333+ hlist_del_init(node);3434+}43354436/**4537 * hash_for_each - iterate over a hashtable···6135 hlist_for_each_entry(obj, &table[_bkt], member)62366337/**3838+ * hash_for_each_safe - iterate over a hashtable safe against removal of3939+ * hash entry4040+ * @table: hashtable to iterate4141+ * @obj: the type * to use as a loop cursor for each entry4242+ * @tmp: a &struct hlist_node used for temporary storage4343+ * @member: the name of the hlist_node within the struct4444+ */4545+#define hash_for_each_safe(table, obj, tmp, member) \4646+ for (int _bkt = 0; _bkt < HASH_SIZE(table); _bkt++) \4747+ hlist_for_each_entry_safe(obj, tmp, &table[_bkt], member)4848+4949+/**6450 * hash_for_each_possible - iterate over all possible objects hashing to the6551 * same bucket6652 * @table: hashtable to iterate···8244 */8345#define hash_for_each_possible(table, obj, member, key) \8446 hlist_for_each_entry(obj, hash_head(table, key), member)4747+4848+/**4949+ * hash_for_each_possible_safe - iterate over all possible objects hashing to the5050+ * same bucket safe against removals5151+ * @table: hashtable to iterate5252+ * @obj: the type * to use as a loop cursor for each entry5353+ * @tmp: a &struct hlist_node used for temporary storage5454+ * @member: the name of the hlist_node within the struct5555+ * @key: the key of the objects to iterate over5656+ */5757+#define hash_for_each_possible_safe(table, obj, tmp, member, key) \5858+ hlist_for_each_entry_safe(obj, tmp, hash_head(table, key), member)85598660#endif /* HASHTABLE_H */
+69
scripts/include/list.h
···268268 */269269270270#define HLIST_HEAD_INIT { .first = NULL }271271+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)272272+static inline void INIT_HLIST_NODE(struct hlist_node *h)273273+{274274+ h->next = NULL;275275+ h->pprev = NULL;276276+}277277+278278+/**279279+ * hlist_unhashed - Has node been removed from list and reinitialized?280280+ * @h: Node to be checked281281+ *282282+ * Not that not all removal functions will leave a node in unhashed283283+ * state. For example, hlist_nulls_del_init_rcu() does leave the284284+ * node in unhashed state, but hlist_nulls_del() does not.285285+ */286286+static inline int hlist_unhashed(const struct hlist_node *h)287287+{288288+ return !h->pprev;289289+}290290+291291+static inline void __hlist_del(struct hlist_node *n)292292+{293293+ struct hlist_node *next = n->next;294294+ struct hlist_node **pprev = n->pprev;295295+296296+ *pprev = next;297297+ if (next)298298+ next->pprev = pprev;299299+}300300+301301+/**302302+ * hlist_del - Delete the specified hlist_node from its list303303+ * @n: Node to delete.304304+ *305305+ * Note that this function leaves the node in hashed state. Use306306+ * hlist_del_init() or similar instead to unhash @n.307307+ */308308+static inline void hlist_del(struct hlist_node *n)309309+{310310+ __hlist_del(n);311311+ n->next = LIST_POISON1;312312+ n->pprev = LIST_POISON2;313313+}314314+315315+/**316316+ * hlist_del_init - Delete the specified hlist_node from its list and initialize317317+ * @n: Node to delete.318318+ *319319+ * Note that this function leaves the node in unhashed state.320320+ */321321+static inline void hlist_del_init(struct hlist_node *n)322322+{323323+ if (!hlist_unhashed(n)) {324324+ __hlist_del(n);325325+ INIT_HLIST_NODE(n);326326+ }327327+}271328272329/**273330 * hlist_add_head - add a new entry at the beginning of the hlist···362305 for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\363306 pos; \364307 pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))308308+309309+/**310310+ * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry311311+ * @pos: the type * to use as a loop cursor.312312+ * @n: a &struct hlist_node to use as temporary storage313313+ * @head: the head for your list.314314+ * @member: the name of the hlist_node within the struct.315315+ */316316+#define hlist_for_each_entry_safe(pos, n, head, member) \317317+ for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\318318+ pos && ({ n = pos->member.next; 1; }); \319319+ pos = hlist_entry_safe(n, typeof(*pos), member))365320366321#endif /* LIST_H */