diff options
author | John Baldwin <jhb@FreeBSD.org> | 2021-11-10 16:38:22 -0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2022-06-14 00:54:37 +0200 |
commit | b7441e315429e65c5b60c4ebcf05282a8c53456d (patch) | |
tree | 3bea3ea032c9d05e5aed03f2b2459fea79d59534 /src/if_wg.c | |
parent | build: include compat.h for all files (diff) | |
download | wireguard-freebsd-b7441e315429e65c5b60c4ebcf05282a8c53456d.tar.xz wireguard-freebsd-b7441e315429e65c5b60c4ebcf05282a8c53456d.zip |
if_wg: wg_peer_alloc and wg_aip_add: Use M_WAITOK with malloc
Signed-off-by: John Baldwin <jhb@FreeBSD.org>
Diffstat (limited to 'src/if_wg.c')
-rw-r--r-- | src/if_wg.c | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/src/if_wg.c b/src/if_wg.c index bbcaafe..a368d15 100644 --- a/src/if_wg.c +++ b/src/if_wg.c @@ -409,18 +409,10 @@ wg_peer_alloc(struct wg_softc *sc, const uint8_t pub_key[WG_KEY_SIZE]) sx_assert(&sc->sc_lock, SX_XLOCKED); - if ((peer = malloc(sizeof(*peer), M_WG, M_NOWAIT | M_ZERO)) == NULL) - goto free_none; - - if ((peer->p_remote = noise_remote_alloc(sc->sc_local, peer, pub_key)) == NULL) - goto free_peer; - - if ((peer->p_tx_bytes = counter_u64_alloc(M_NOWAIT)) == NULL) - goto free_remote; - - if ((peer->p_rx_bytes = counter_u64_alloc(M_NOWAIT)) == NULL) - goto free_tx_bytes; - + peer = malloc(sizeof(*peer), M_WG, M_WAITOK | M_ZERO); + peer->p_remote = noise_remote_alloc(sc->sc_local, peer, pub_key); + peer->p_tx_bytes = counter_u64_alloc(M_WAITOK); + peer->p_rx_bytes = counter_u64_alloc(M_WAITOK); peer->p_id = peer_counter++; peer->p_sc = sc; @@ -454,14 +446,6 @@ wg_peer_alloc(struct wg_softc *sc, const uint8_t pub_key[WG_KEY_SIZE]) peer->p_aips_num = 0; return (peer); -free_tx_bytes: - counter_u64_free(peer->p_tx_bytes); -free_remote: - noise_remote_free(peer->p_remote, NULL); -free_peer: - free(peer, M_WG); -free_none: - return NULL; } static void @@ -560,8 +544,7 @@ wg_aip_add(struct wg_softc *sc, struct wg_peer *peer, sa_family_t af, const void struct wg_aip *aip; int i, ret = 0; - if ((aip = malloc(sizeof(*aip), M_WG, M_NOWAIT | M_ZERO)) == NULL) - return (ENOBUFS); + aip = malloc(sizeof(*aip), M_WG, M_WAITOK | M_ZERO); aip->a_peer = peer; aip->a_af = af; @@ -2279,10 +2262,7 @@ wg_peer_add(struct wg_softc *sc, const nvlist_t *nvl) wg_aip_remove_all(sc, peer); } if (peer == NULL) { - if ((peer = wg_peer_alloc(sc, pub_key)) == NULL) { - err = ENOMEM; - goto out; - } + peer = wg_peer_alloc(sc, pub_key); need_insert = true; } if (nvlist_exists_binary(nvl, "endpoint")) { |