Commit 47b1c03c authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

netfilter: nft_set_pipapo: add helper to release pcpu scratch area

After next patch simple kfree() is not enough anymore, so add
a helper for it.
Reviewed-by: default avatarStefano Brivio <sbrivio@redhat.com>
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 76313d1a
...@@ -1110,6 +1110,24 @@ static void pipapo_map(struct nft_pipapo_match *m, ...@@ -1110,6 +1110,24 @@ static void pipapo_map(struct nft_pipapo_match *m,
f->mt[map[i].to + j].e = e; f->mt[map[i].to + j].e = e;
} }
/**
* pipapo_free_scratch() - Free per-CPU map at original (not aligned) address
* @m: Matching data
* @cpu: CPU number
*/
static void pipapo_free_scratch(const struct nft_pipapo_match *m, unsigned int cpu)
{
struct nft_pipapo_scratch *s;
void *mem;
s = *per_cpu_ptr(m->scratch, cpu);
if (!s)
return;
mem = s;
kfree(mem);
}
/** /**
* pipapo_realloc_scratch() - Reallocate scratch maps for partial match results * pipapo_realloc_scratch() - Reallocate scratch maps for partial match results
* @clone: Copy of matching data with pending insertions and deletions * @clone: Copy of matching data with pending insertions and deletions
...@@ -1142,7 +1160,7 @@ static int pipapo_realloc_scratch(struct nft_pipapo_match *clone, ...@@ -1142,7 +1160,7 @@ static int pipapo_realloc_scratch(struct nft_pipapo_match *clone,
return -ENOMEM; return -ENOMEM;
} }
kfree(*per_cpu_ptr(clone->scratch, i)); pipapo_free_scratch(clone, i);
*per_cpu_ptr(clone->scratch, i) = scratch; *per_cpu_ptr(clone->scratch, i) = scratch;
...@@ -1369,7 +1387,7 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old) ...@@ -1369,7 +1387,7 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)
} }
out_scratch_realloc: out_scratch_realloc:
for_each_possible_cpu(i) for_each_possible_cpu(i)
kfree(*per_cpu_ptr(new->scratch, i)); pipapo_free_scratch(new, i);
#ifdef NFT_PIPAPO_ALIGN #ifdef NFT_PIPAPO_ALIGN
free_percpu(new->scratch_aligned); free_percpu(new->scratch_aligned);
#endif #endif
...@@ -1653,7 +1671,7 @@ static void pipapo_free_match(struct nft_pipapo_match *m) ...@@ -1653,7 +1671,7 @@ static void pipapo_free_match(struct nft_pipapo_match *m)
int i; int i;
for_each_possible_cpu(i) for_each_possible_cpu(i)
kfree(*per_cpu_ptr(m->scratch, i)); pipapo_free_scratch(m, i);
#ifdef NFT_PIPAPO_ALIGN #ifdef NFT_PIPAPO_ALIGN
free_percpu(m->scratch_aligned); free_percpu(m->scratch_aligned);
...@@ -2253,7 +2271,7 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, ...@@ -2253,7 +2271,7 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx,
free_percpu(m->scratch_aligned); free_percpu(m->scratch_aligned);
#endif #endif
for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
kfree(*per_cpu_ptr(m->scratch, cpu)); pipapo_free_scratch(m, cpu);
free_percpu(m->scratch); free_percpu(m->scratch);
pipapo_free_fields(m); pipapo_free_fields(m);
kfree(m); kfree(m);
...@@ -2270,7 +2288,7 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, ...@@ -2270,7 +2288,7 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx,
free_percpu(priv->clone->scratch_aligned); free_percpu(priv->clone->scratch_aligned);
#endif #endif
for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
kfree(*per_cpu_ptr(priv->clone->scratch, cpu)); pipapo_free_scratch(priv->clone, cpu);
free_percpu(priv->clone->scratch); free_percpu(priv->clone->scratch);
pipapo_free_fields(priv->clone); pipapo_free_fields(priv->clone);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment