Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Sep 2023 02:22:30 GMT
From:      Cy Schubert <cy@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: b083794291d2 - stable/12 - ipfilter: Avoid allocating a new ipf token when not needed
Message-ID:  <202309270222.38R2MUPm078873@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by cy:

URL: https://cgit.FreeBSD.org/src/commit/?id=b083794291d245f05940552a37f7d5c5badc2d17

commit b083794291d245f05940552a37f7d5c5badc2d17
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2023-09-12 20:29:29 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-09-27 02:22:26 +0000

    ipfilter: Avoid allocating a new ipf token when not needed
    
    Only allocate a new ipftoken_t if one cannot be found. This eliminates
    allocating unnecessary token structures that will never be used when
    performing simple lookups for existing token structures.
    
    (cherry picked from commit 7f5e3b9fa3d159b7f061b4d01a767cbe5d0527f3)
---
 sys/netpfil/ipfilter/netinet/fil.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/sys/netpfil/ipfilter/netinet/fil.c b/sys/netpfil/ipfilter/netinet/fil.c
index 3cf9111340a3..455da5d6fa71 100644
--- a/sys/netpfil/ipfilter/netinet/fil.c
+++ b/sys/netpfil/ipfilter/netinet/fil.c
@@ -7461,10 +7461,6 @@ ipf_token_find(ipf_main_softc_t *softc, int type, int uid, void *ptr)
 {
 	ipftoken_t *it, *new;
 
-	KMALLOC(new, ipftoken_t *);
-	if (new != NULL)
-		bzero((char *)new, sizeof(*new));
-
 	WRITE_ENTER(&softc->ipf_tokens);
 	for (it = softc->ipf_token_head; it != NULL; it = it->ipt_next) {
 		if ((ptr == it->ipt_ctx) && (type == it->ipt_type) &&
@@ -7473,6 +7469,10 @@ ipf_token_find(ipf_main_softc_t *softc, int type, int uid, void *ptr)
 	}
 
 	if (it == NULL) {
+		KMALLOC(new, ipftoken_t *);
+		if (new != NULL)
+			bzero((char *)new, sizeof(*new));
+
 		it = new;
 		new = NULL;
 		if (it == NULL) {
@@ -7484,11 +7484,6 @@ ipf_token_find(ipf_main_softc_t *softc, int type, int uid, void *ptr)
 		it->ipt_type = type;
 		it->ipt_ref = 1;
 	} else {
-		if (new != NULL) {
-			KFREE(new);
-			new = NULL;
-		}
-
 		if (it->ipt_complete > 0)
 			it = NULL;
 		else



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202309270222.38R2MUPm078873>