git: bf206a1db26e - main - pf: remove NULL check before uma_zfree()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 04 May 2023 16:24:02 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=bf206a1db26e44180466ea2258a2b82467ffb99e
commit bf206a1db26e44180466ea2258a2b82467ffb99e
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-05-04 15:20:02 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-05-04 16:22:54 +0000
pf: remove NULL check before uma_zfree()
uma_zfree() can be called on a NULL pointer. Simplify the pf code a
little by removing the redundant checks.
Sponsored by: Rubicon Communications, LLC ("Netgate")
---
sys/netpfil/pf/if_pfsync.c | 6 ++----
sys/netpfil/pf/pf.c | 18 ++++++------------
sys/netpfil/pf/pf_norm.c | 6 ++----
3 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c
index 2bf1146ceda8..cf9a50a7020c 100644
--- a/sys/netpfil/pf/if_pfsync.c
+++ b/sys/netpfil/pf/if_pfsync.c
@@ -649,10 +649,8 @@ cleanup:
error = ENOMEM;
if (skw == sks)
sks = NULL;
- if (skw != NULL)
- uma_zfree(V_pf_state_key_z, skw);
- if (sks != NULL)
- uma_zfree(V_pf_state_key_z, sks);
+ uma_zfree(V_pf_state_key_z, skw);
+ uma_zfree(V_pf_state_key_z, sks);
cleanup_state: /* pf_state_insert() frees the state keys. */
if (st) {
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index ee17df0c866f..1424099b1e5a 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -4541,10 +4541,8 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction,
return (action);
}
} else {
- if (sk != NULL)
- uma_zfree(V_pf_state_key_z, sk);
- if (nk != NULL)
- uma_zfree(V_pf_state_key_z, nk);
+ uma_zfree(V_pf_state_key_z, sk);
+ uma_zfree(V_pf_state_key_z, nk);
}
/* copy back packet headers if we performed NAT operations */
@@ -4570,10 +4568,8 @@ cleanup:
free(ri, M_PF_RULE_ITEM);
}
- if (sk != NULL)
- uma_zfree(V_pf_state_key_z, sk);
- if (nk != NULL)
- uma_zfree(V_pf_state_key_z, nk);
+ uma_zfree(V_pf_state_key_z, sk);
+ uma_zfree(V_pf_state_key_z, nk);
return (PF_DROP);
}
@@ -4812,10 +4808,8 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a,
return (PF_PASS);
csfailed:
- if (sk != NULL)
- uma_zfree(V_pf_state_key_z, sk);
- if (nk != NULL)
- uma_zfree(V_pf_state_key_z, nk);
+ uma_zfree(V_pf_state_key_z, sk);
+ uma_zfree(V_pf_state_key_z, nk);
if (sn != NULL) {
PF_SRC_NODE_LOCK(sn);
diff --git a/sys/netpfil/pf/pf_norm.c b/sys/netpfil/pf/pf_norm.c
index c0dd3ba60113..8b267636751a 100644
--- a/sys/netpfil/pf/pf_norm.c
+++ b/sys/netpfil/pf/pf_norm.c
@@ -1576,10 +1576,8 @@ pf_normalize_tcp_init(struct mbuf *m, int off, struct pf_pdesc *pd,
void
pf_normalize_tcp_cleanup(struct pf_kstate *state)
{
- if (state->src.scrub)
- uma_zfree(V_pf_state_scrub_z, state->src.scrub);
- if (state->dst.scrub)
- uma_zfree(V_pf_state_scrub_z, state->dst.scrub);
+ uma_zfree(V_pf_state_scrub_z, state->src.scrub);
+ uma_zfree(V_pf_state_scrub_z, state->dst.scrub);
/* Someday... flush the TCP segment reassembly descriptors. */
}