- 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)
This commit is contained in:
jhb 2006-08-02 17:41:58 +00:00
parent 0cae7b2fc7
commit b69bfe457d

View File

@ -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;