summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBret Lambert <blambert@cvs.openbsd.org>2010-06-07 19:47:26 +0000
committerBret Lambert <blambert@cvs.openbsd.org>2010-06-07 19:47:26 +0000
commit00951d740eadb77cbcb38a4902228b97fb4b6d92 (patch)
treee92d4bcca758149184882ef54103b26cc7e78a3a
parent1830b21e0cbfa30cb3004ba8d485766c5e635007 (diff)
Replace some handrolled instances of m_getptr() with that function, which
also gets a bit of a KNF scrubbing at claudio@'s insistence. Shaves some bytes from the kernel as well. tested by phessler@ and zinovnik@, thanks ok claudio@
-rw-r--r--sys/kern/uipc_mbuf.c32
-rw-r--r--sys/kern/uipc_mbuf2.c14
2 files changed, 12 insertions, 34 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index 38608e579d2..a7033c1ddb4 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf.c,v 1.136 2010/01/14 23:12:11 schwarze Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.137 2010/06/07 19:47:25 blambert Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
@@ -628,14 +628,8 @@ m_copym0(struct mbuf *m, int off, int len, int wait, int deep)
panic("m_copym0: off %d, len %d", off, len);
if (off == 0 && m->m_flags & M_PKTHDR)
copyhdr = 1;
- while (off > 0) {
- if (m == NULL)
- panic("m_copym0: null mbuf");
- if (off < m->m_len)
- break;
- off -= m->m_len;
- m = m->m_next;
- }
+ if ((m = m_getptr(m, off, &off)) == NULL)
+ panic("m_copym0: short mbuf chain");
np = &top;
top = NULL;
while (len > 0) {
@@ -709,14 +703,8 @@ m_copydata(struct mbuf *m, int off, int len, caddr_t cp)
panic("m_copydata: off %d < 0", off);
if (len < 0)
panic("m_copydata: len %d < 0", len);
- while (off > 0) {
- if (m == NULL)
- panic("m_copydata: null mbuf in skip");
- if (off < m->m_len)
- break;
- off -= m->m_len;
- m = m->m_next;
- }
+ if ((m = m_getptr(m, off, &off)) == NULL)
+ panic("m_copydata: short mbuf chain");
while (len > 0) {
if (m == NULL)
panic("m_copydata: null mbuf");
@@ -1044,8 +1032,7 @@ m_getptr(struct mbuf *m, int loc, int *off)
if (m->m_len > loc) {
*off = loc;
return (m);
- }
- else {
+ } else {
loc -= m->m_len;
if (m->m_next == NULL) {
@@ -1053,11 +1040,12 @@ m_getptr(struct mbuf *m, int loc, int *off)
/* Point at the end of valid data */
*off = m->m_len;
return (m);
- }
- else
+ } else {
return (NULL);
- } else
+ }
+ } else {
m = m->m_next;
+ }
}
}
diff --git a/sys/kern/uipc_mbuf2.c b/sys/kern/uipc_mbuf2.c
index f6d1407a844..15e4f0f4b18 100644
--- a/sys/kern/uipc_mbuf2.c
+++ b/sys/kern/uipc_mbuf2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf2.c,v 1.31 2009/09/13 14:42:52 krw Exp $ */
+/* $OpenBSD: uipc_mbuf2.c,v 1.32 2010/06/07 19:47:25 blambert Exp $ */
/* $KAME: uipc_mbuf2.c,v 1.29 2001/02/14 13:42:10 itojun Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.40 1999/04/01 00:23:25 thorpej Exp $ */
@@ -96,17 +96,7 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp)
return (NULL); /* impossible */
}
- n = m;
- while (n != NULL && off > 0) {
- if (n->m_len > off)
- break;
- off -= n->m_len;
- n = n->m_next;
- }
- /* be sure to point non-empty mbuf */
- while (n != NULL && n->m_len == 0)
- n = n->m_next;
- if (!n) {
+ if ((n = m_getptr(m, off, &off)) == NULL) {
m_freem(m);
return (NULL); /* mbuf chain too short */
}