summaryrefslogtreecommitdiff
path: root/backport/compat
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2016-07-10 16:50:27 +0200
committerHauke Mehrtens <hauke@hauke-m.de>2016-07-13 19:16:30 +0200
commit0b879b047cd07cdde5bea835493d64c9f214c938 (patch)
tree02a5d037df06d59df21e6b044281e5891f86a370 /backport/compat
parent1405680d47ca6e04fee4200d7c6097f7b7b8bfcd (diff)
backports: add rhashtable_walk_init()
Since commit 1068c678f "rhashtable: accept GFP flags in rhashtable_walk_init" rhashtable_walk_init() takes an additional parameter which is also used by the mac80211 code, so backport the function. For kernel < 4.1 this is not needed, because we already ship a recent version of rhashtable. Add rhashtable_walk_init() instead of adding the complete rhashtable to same some space on recent kernel versions. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Diffstat (limited to 'backport/compat')
-rw-r--r--backport/compat/Makefile1
-rw-r--r--backport/compat/backport-4.7.c62
2 files changed, 63 insertions, 0 deletions
diff --git a/backport/compat/Makefile b/backport/compat/Makefile
index 7651f83d..6013083e 100644
--- a/backport/compat/Makefile
+++ b/backport/compat/Makefile
@@ -32,6 +32,7 @@ compat-$(CPTCFG_KERNEL_4_3) += backport-4.3.o
compat-$(CPTCFG_KERNEL_4_4) += backport-4.4.o
compat-$(CPTCFG_KERNEL_4_5) += backport-4.5.o
compat-$(CPTCFG_KERNEL_4_6) += backport-4.6.o
+compat-$(CPTCFG_KERNEL_4_7) += backport-4.7.o
compat-$(CPTCFG_BPAUTO_BUILD_CRYPTO_CCM) += crypto-ccm.o
compat-$(CPTCFG_BPAUTO_CRYPTO_SKCIPHER) += crypto-skcipher.o
diff --git a/backport/compat/backport-4.7.c b/backport/compat/backport-4.7.c
new file mode 100644
index 00000000..04737b04
--- /dev/null
+++ b/backport/compat/backport-4.7.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright(c) 2016 Hauke Mehrtens <hauke@hauke-m.de>
+ *
+ * Backport functionality introduced in Linux 4.7.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/export.h>
+#include <linux/list.h>
+#include <linux/rcupdate.h>
+#include <linux/rhashtable.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
+/**
+ * rhashtable_walk_init - Initialise an iterator
+ * @ht: Table to walk over
+ * @iter: Hash table Iterator
+ * @gfp: GFP flags for allocations
+ *
+ * This function prepares a hash table walk.
+ *
+ * Note that if you restart a walk after rhashtable_walk_stop you
+ * may see the same object twice. Also, you may miss objects if
+ * there are removals in between rhashtable_walk_stop and the next
+ * call to rhashtable_walk_start.
+ *
+ * For a completely stable walk you should construct your own data
+ * structure outside the hash table.
+ *
+ * This function may sleep so you must not call it from interrupt
+ * context or with spin locks held.
+ *
+ * You must call rhashtable_walk_exit if this function returns
+ * successfully.
+ */
+int rhashtable_walk_init(struct rhashtable *ht, struct rhashtable_iter *iter,
+ gfp_t gfp)
+{
+ iter->ht = ht;
+ iter->p = NULL;
+ iter->slot = 0;
+ iter->skip = 0;
+
+ iter->walker = kmalloc(sizeof(*iter->walker), gfp);
+ if (!iter->walker)
+ return -ENOMEM;
+
+ spin_lock(&ht->lock);
+ iter->walker->tbl =
+ rcu_dereference_protected(ht->tbl, lockdep_is_held(&ht->lock));
+ list_add(&iter->walker->list, &iter->walker->tbl->walkers);
+ spin_unlock(&ht->lock);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(rhashtable_walk_init);
+#endif /* >= 4.1 */