diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2020-01-23 23:43:50 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2020-01-23 23:43:50 +0000 |
commit | dda975ab70c6afd5b4406a72f736283b62b0633f (patch) | |
tree | 043368ff0f8cb9124d651df01b753e6f73059cc3 /sys/net | |
parent | d8378502e684de36169ffbdd851fcd1b1dd6b955 (diff) |
simplify the uiomove loop in tun_dev_read.
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/if_tun.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 700f1e50bbd..a091fa60ab8 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_tun.c,v 1.205 2020/01/23 23:36:18 dlg Exp $ */ +/* $OpenBSD: if_tun.c,v 1.206 2020/01/23 23:43:49 dlg Exp $ */ /* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */ /* @@ -724,7 +724,6 @@ tun_dev_read(struct tun_softc *sc, struct uio *uio, int ioflag) struct mbuf *m, *m0; unsigned int ifidx; int error = 0; - size_t len; if ((sc->sc_flags & TUN_READY) != TUN_READY) return (EHOSTDOWN); @@ -769,20 +768,21 @@ tun_dev_read(struct tun_softc *sc, struct uio *uio, int ioflag) bpf_mtap(ifp->if_bpf, m0, BPF_DIRECTION_OUT); #endif - while (m0 != NULL && uio->uio_resid > 0 && error == 0) { - len = ulmin(uio->uio_resid, m0->m_len); - if (len != 0) - error = uiomove(mtod(m0, caddr_t), len, uio); - m = m_free(m0); - m0 = m; - } + m = m0; + while (uio->uio_resid > 0) { + size_t len = ulmin(uio->uio_resid, m->m_len); + if (len > 0) { + error = uiomove(mtod(m, void *), len, uio); + if (error != 0) + break; + } - if (m0 != NULL) { - TUNDEBUG(("Dropping mbuf\n")); - m_freem(m0); + m = m->m_next; + if (m == NULL) + break; } - if (error) - ifp->if_oerrors++; + + m_freem(m0); return (error); } |