Skip to content

Commit 8053238

Browse files
jpirkodavem330
authored andcommitted
net: sched: fix memleak for chain zero
There's a memleak happening for chain 0. The thing is, chain 0 needs to be always present, not created on demand. Therefore tcf_block_get upon creation of block calls the tcf_chain_create function directly. The chain is created with refcnt == 1, which is not correct in this case and causes the memleak. So move the refcnt increment into tcf_chain_get function even for the case when chain needs to be created. Reported-by: Jakub Kicinski <kubakici@wp.pl> Fixes: 5bc1701 ("net: sched: introduce multichain support for filters") Signed-off-by: Jiri Pirko <jiri@mellanox.com> Tested-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0f2be42 commit 8053238

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

net/sched/cls_api.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static struct tcf_chain *tcf_chain_create(struct tcf_block *block,
182182
list_add_tail(&chain->list, &block->chain_list);
183183
chain->block = block;
184184
chain->index = chain_index;
185-
chain->refcnt = 1;
185+
chain->refcnt = 0;
186186
return chain;
187187
}
188188

@@ -217,15 +217,15 @@ struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
217217
struct tcf_chain *chain;
218218

219219
list_for_each_entry(chain, &block->chain_list, list) {
220-
if (chain->index == chain_index) {
221-
chain->refcnt++;
222-
return chain;
223-
}
220+
if (chain->index == chain_index)
221+
goto incref;
224222
}
225-
if (create)
226-
return tcf_chain_create(block, chain_index);
227-
else
228-
return NULL;
223+
chain = create ? tcf_chain_create(block, chain_index) : NULL;
224+
225+
incref:
226+
if (chain)
227+
chain->refcnt++;
228+
return chain;
229229
}
230230
EXPORT_SYMBOL(tcf_chain_get);
231231

0 commit comments

Comments
 (0)