From b69bfe457d51a5d0df16d26cee10b0b7180b9f19 Mon Sep 17 00:00:00 2001 From: jhb Date: Wed, 2 Aug 2006 17:41:58 +0000 Subject: [PATCH] - Use m_getcl(), m_get(), and m_gethdr() rather than the older macros for alloc'ing mbufs so that there is less error handling required. - Go ahead and account for the data space in the first mbuf before entering the loop to alloc more mbuf's. This simplifies the loop logic and avoids confusing Coverity. CID: 817 Reviewed by: sam Tested by: pjd Found by: Coverity Prevent (tm) --- sys/dev/ubsec/ubsec.c | 63 ++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/sys/dev/ubsec/ubsec.c b/sys/dev/ubsec/ubsec.c index e9a2a41dc6d2..3e06cb017d1b 100644 --- a/sys/dev/ubsec/ubsec.c +++ b/sys/dev/ubsec/ubsec.c @@ -1369,57 +1369,46 @@ ubsec_process(void *arg, struct cryptop *crp, int hint) ubsecstats.hst_unaligned++; totlen = q->q_src_mapsize; - if (q->q_src_m->m_flags & M_PKTHDR) { + if (totlen >= MINCLSIZE) { + m = m_getcl(M_DONTWAIT, MT_DATA, + q->q_src_m->m_flags & M_PKTHDR); + len = MCLBYTES; + } else if (q->q_src_m->m_flags & M_PKTHDR) { + m = m_gethdr(M_DONTWAIT, MT_DATA); len = MHLEN; - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m && !m_dup_pkthdr(m, q->q_src_m, M_DONTWAIT)) { - m_free(m); - m = NULL; - } } else { + m = m_get(M_DONTWAIT, MT_DATA); len = MLEN; - MGET(m, M_DONTWAIT, MT_DATA); + } + if (m && q->q_src_m->m_flags & M_PKTHDR && + !m_dup_pkthdr(m, q->q_src_m, M_DONTWAIT)) { + m_free(m); + m = NULL; } if (m == NULL) { ubsecstats.hst_nombuf++; err = sc->sc_nqueue ? ERESTART : ENOMEM; goto errout; } - if (totlen >= MINCLSIZE) { - MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - m_free(m); - ubsecstats.hst_nomcl++; - err = sc->sc_nqueue ? ERESTART : ENOMEM; - goto errout; - } - len = MCLBYTES; - } - m->m_len = len; - top = NULL; + m->m_len = len = min(totlen, len); + totlen -= len; + top = m; mp = ⊤ while (totlen > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == NULL) { - m_freem(top); - ubsecstats.hst_nombuf++; - err = sc->sc_nqueue ? ERESTART : ENOMEM; - goto errout; - } + if (totlen >= MINCLSIZE) { + m = m_getcl(M_DONTWAIT, + MT_DATA, 0); + len = MCLBYTES; + } else { + m = m_get(M_DONTWAIT, MT_DATA); len = MLEN; } - if (top && totlen >= MINCLSIZE) { - MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - *mp = m; - m_freem(top); - ubsecstats.hst_nomcl++; - err = sc->sc_nqueue ? ERESTART : ENOMEM; - goto errout; - } - len = MCLBYTES; + if (m == NULL) { + m_freem(top); + ubsecstats.hst_nombuf++; + err = sc->sc_nqueue ? ERESTART : ENOMEM; + goto errout; } m->m_len = len = min(totlen, len); totlen -= len;