summaryrefslogtreecommitdiffstats
path: root/net/netfilter/nfnetlink_cttimeout.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2022-03-23 14:22:06 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2022-04-08 12:08:58 +0200
commit523895e5b278b5d7f2e29323b877193fe2d1b9dc (patch)
treefd7009eb59a81ede7531b74e1c9da82acb8bf402 /net/netfilter/nfnetlink_cttimeout.c
parent49001a2e83a80f6d9c4287c46ffa41a03667bbd1 (diff)
downloadlinux-stable-523895e5b278b5d7f2e29323b877193fe2d1b9dc.tar.gz
linux-stable-523895e5b278b5d7f2e29323b877193fe2d1b9dc.tar.bz2
linux-stable-523895e5b278b5d7f2e29323b877193fe2d1b9dc.zip
netfilter: cttimeout: inc/dec module refcount per object, not per use refcount
There is no need to increment the module refcount again, its enough to obtain one reference per object, i.e. take a reference on object creation and put it on object destruction. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/netfilter/nfnetlink_cttimeout.c')
-rw-r--r--net/netfilter/nfnetlink_cttimeout.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c
index b0d8888a539b..eea486f32971 100644
--- a/net/netfilter/nfnetlink_cttimeout.c
+++ b/net/netfilter/nfnetlink_cttimeout.c
@@ -158,6 +158,7 @@ static int cttimeout_new_timeout(struct sk_buff *skb,
timeout->timeout.l3num = l3num;
timeout->timeout.l4proto = l4proto;
refcount_set(&timeout->refcnt, 1);
+ __module_get(THIS_MODULE);
list_add_tail_rcu(&timeout->head, &pernet->nfct_timeout_list);
return 0;
@@ -506,13 +507,8 @@ static struct nf_ct_timeout *ctnl_timeout_find_get(struct net *net,
if (strncmp(timeout->name, name, CTNL_TIMEOUT_NAME_MAX) != 0)
continue;
- if (!try_module_get(THIS_MODULE))
+ if (!refcount_inc_not_zero(&timeout->refcnt))
goto err;
-
- if (!refcount_inc_not_zero(&timeout->refcnt)) {
- module_put(THIS_MODULE);
- goto err;
- }
matching = timeout;
break;
}
@@ -525,10 +521,10 @@ static void ctnl_timeout_put(struct nf_ct_timeout *t)
struct ctnl_timeout *timeout =
container_of(t, struct ctnl_timeout, timeout);
- if (refcount_dec_and_test(&timeout->refcnt))
+ if (refcount_dec_and_test(&timeout->refcnt)) {
kfree_rcu(timeout, rcu_head);
-
- module_put(THIS_MODULE);
+ module_put(THIS_MODULE);
+ }
}
static const struct nfnl_callback cttimeout_cb[IPCTNL_MSG_TIMEOUT_MAX] = {