This is a discussion on subtraction of known zero in uipc_mbuf.c within the mailing.openbsd.tech forums, part of the OpenBSD category; --> Greetings tech@- Taking a look at the mbuf code, I noticed something odd. The only time that the variable ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Greetings tech@- Taking a look at the mbuf code, I noticed something odd. The only time that the variable off0 is used (after copying the value to off) is in the if (copyhdr) block. copyhdr, however, is only set when off0 is zero, making n->m_pkthdr.len -= off0 the subtraction of a known zero. After removing this, we have no more need for a second offset variable, so this diff removes that as well, replacing all occurences with off0. I've been running a similar diff for several weeks, and haven't had any problems of yet. - Bret --- uipc_mbuf.c.orig Sat Aug 12 13:35:17 2006 +++ uipc_mbuf.c Sat Aug 12 13:42:36 2006 @@ -265,25 +265,24 @@ m_copym0(struct mbuf *m, int off0, int len, int wait, int deep) { struct mbuf *n, **np; - int off = off0; struct mbuf *top; int copyhdr = 0; - if (off < 0 || len < 0) - panic("m_copym0: off %d, len %d", off, len); - if (off == 0 && m->m_flags & M_PKTHDR) + if (off0 < 0 || len < 0) + panic("m_copym0: off %d, len %d", off0, len); + if (off0 == 0 && m->m_flags & M_PKTHDR) copyhdr = 1; - while (off > 0) { + while (off0 > 0) { if (m == NULL) panic("m_copym0: null mbuf"); - if (off < m->m_len) + if (off0 < m->m_len) break; - off -= m->m_len; + off0 -= m->m_len; m = m->m_next; } np = ⊤ top = NULL; - while (len > 0) { + while (len0 > 0) { if (m == NULL) { if (len != M_COPYALL) panic("m_copym0: m == NULL and not COPYALL"); @@ -295,16 +294,14 @@ goto nospace; if (copyhdr) { M_DUP_PKTHDR(n, m); - if (len == M_COPYALL) - n->m_pkthdr.len -= off0; - else + if (len != M_COPYALL) n->m_pkthdr.len = len; copyhdr = 0; } - n->m_len = min(len, m->m_len - off); + n->m_len = min(len, m->m_len - off0); if (m->m_flags & M_EXT) { if (!deep) { - n->m_data = m->m_data + off; + n->m_data = m->m_data + off0; n->m_ext = m->m_ext; MCLADDREFERENCE(m, n); } else { @@ -316,23 +313,23 @@ n->m_len = 0; n->m_len = M_TRAILINGSPACE(n); n->m_len = min(n->m_len, len); - n->m_len = min(n->m_len, m->m_len - off); - memcpy(mtod(n, caddr_t), mtod(m, caddr_t) + off, + n->m_len = min(n->m_len, m->m_len - off0); + memcpy(mtod(n, caddr_t), mtod(m, caddr_t)+off0, (unsigned)n->m_len); } } else - memcpy(mtod(n, caddr_t), mtod(m, caddr_t)+off, + memcpy(mtod(n, caddr_t), mtod(m, caddr_t)+off0, (unsigned)n->m_len); if (len != M_COPYALL) len -= n->m_len; - off += n->m_len; + off0 += n->m_len; #ifdef DIAGNOSTIC - if (off > m->m_len) + if (off0 > m->m_len) panic("m_copym0 overrun"); #endif - if (off == m->m_len) { + if (off0 == m->m_len) { m = m->m_next; - off = 0; + off0 = 0; } np = &n->m_next; } |