]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - net/netfilter/nft_hash.c
rhashtable: Add rhashtable_free_and_destroy()
[karo-tx-linux.git] / net / netfilter / nft_hash.c
index ad3966976cf598572653c7a030281d148c1a7698..f9ce2195fd63e30e725fd96088e55cd2d8743160 100644 (file)
@@ -172,6 +172,7 @@ static const struct rhashtable_params nft_hash_params = {
        .head_offset = offsetof(struct nft_hash_elem, node),
        .key_offset = offsetof(struct nft_hash_elem, key),
        .hashfn = jhash,
+       .automatic_shrinking = true,
 };
 
 static int nft_hash_init(const struct nft_set *set,
@@ -187,26 +188,15 @@ static int nft_hash_init(const struct nft_set *set,
        return rhashtable_init(priv, &params);
 }
 
-static void nft_hash_destroy(const struct nft_set *set)
+static void nft_free_element(void *ptr, void *arg)
 {
-       struct rhashtable *priv = nft_set_priv(set);
-       const struct bucket_table *tbl;
-       struct nft_hash_elem *he;
-       struct rhash_head *pos, *next;
-       unsigned int i;
-
-       /* Stop an eventual async resizing */
-       priv->being_destroyed = true;
-       mutex_lock(&priv->mutex);
-
-       tbl = rht_dereference(priv->tbl, priv);
-       for (i = 0; i < tbl->size; i++) {
-               rht_for_each_entry_safe(he, pos, next, tbl, i, node)
-                       nft_hash_elem_destroy(set, he);
-       }
-       mutex_unlock(&priv->mutex);
+       nft_hash_elem_destroy((const struct nft_set *)arg, ptr);
+}
 
-       rhashtable_destroy(priv);
+static void nft_hash_destroy(const struct nft_set *set)
+{
+       rhashtable_free_and_destroy(nft_set_priv(set), nft_free_element,
+                                   (void *)set);
 }
 
 static bool nft_hash_estimate(const struct nft_set_desc *desc, u32 features,