Subject: mbuf warning cleanup
To: None <tech-net@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-net
Date: 11/09/2002 20:17:35
--5QAgd0e35j3NYeGe
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
This patch is a big step towards cleaning up signed/unsigned comparison
warnings related to mbuf usage. Cleaning up these warnings is required
for the upgrade to GCC 3.3, which is very picky about this sort of thing
(as is our in-tree lint(1)). And, well, if you think about it, it doesn't
make any sense to have a -ve length mbuf :-)
I would like a few other sets of eyes to look over this patch before
I check it in.
Thanks.
--
-- Jason R. Thorpe <thorpej@wasabisystems.com>
--5QAgd0e35j3NYeGe
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=mbuf-warn-patch
Index: kern/uipc_mbuf.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/uipc_mbuf.c,v
retrieving revision 1.61
diff -c -r1.61 uipc_mbuf.c
*** kern/uipc_mbuf.c 2002/09/25 22:21:45 1.61
--- kern/uipc_mbuf.c 2002/11/10 04:12:33
***************
*** 113,119 ****
mclpool_alloc, mclpool_release, 0,
};
! static struct mbuf *m_copym0 __P((struct mbuf *, int, int, int, int));
const char mclpool_warnmsg[] =
"WARNING: mclpool limit reached; increase NMBCLUSTERS";
--- 113,119 ----
mclpool_alloc, mclpool_release, 0,
};
! static struct mbuf *m_copym0 __P((struct mbuf *, u_int, u_int, int, int));
const char mclpool_warnmsg[] =
"WARNING: mclpool limit reached; increase NMBCLUSTERS";
***************
*** 122,128 ****
* Initialize the mbuf allcator.
*/
void
! mbinit()
{
pool_init(&mbpool, msize, 0, 0, 0, "mbpl", NULL);
--- 122,128 ----
* Initialize the mbuf allcator.
*/
void
! mbinit(void)
{
pool_init(&mbpool, msize, 0, 0, 0, "mbpl", NULL);
***************
*** 152,164 ****
}
int
! sysctl_dombuf(name, namelen, oldp, oldlenp, newp, newlen)
! int *name;
! u_int namelen;
! void *oldp;
! size_t *oldlenp;
! void *newp;
! size_t newlen;
{
int error, newval;
--- 152,159 ----
}
int
! sysctl_dombuf(int *name, u_int namelen, void *oldp, size_t *oldlenp,
! void *newp, size_t newlen)
{
int error, newval;
***************
*** 224,232 ****
}
void *
! mclpool_alloc(pp, flags)
! struct pool *pp;
! int flags;
{
boolean_t waitok = (flags & PR_WAITOK) ? TRUE : FALSE;
--- 219,225 ----
}
void *
! mclpool_alloc(struct pool *pp, int flags)
{
boolean_t waitok = (flags & PR_WAITOK) ? TRUE : FALSE;
***************
*** 234,242 ****
}
void
! mclpool_release(pp, v)
! struct pool *pp;
! void *v;
{
uvm_km_free_poolpage1(mb_map, (vaddr_t)v);
--- 227,233 ----
}
void
! mclpool_release(struct pool *pp, void *v)
{
uvm_km_free_poolpage1(mb_map, (vaddr_t)v);
***************
*** 268,275 ****
* for critical paths.
*/
struct mbuf *
! m_get(nowait, type)
! int nowait, type;
{
struct mbuf *m;
--- 259,265 ----
* for critical paths.
*/
struct mbuf *
! m_get(int nowait, int type)
{
struct mbuf *m;
***************
*** 278,285 ****
}
struct mbuf *
! m_gethdr(nowait, type)
! int nowait, type;
{
struct mbuf *m;
--- 268,274 ----
}
struct mbuf *
! m_gethdr(int nowait, int type)
{
struct mbuf *m;
***************
*** 288,295 ****
}
struct mbuf *
! m_getclr(nowait, type)
! int nowait, type;
{
struct mbuf *m;
--- 277,283 ----
}
struct mbuf *
! m_getclr(int nowait, int type)
{
struct mbuf *m;
***************
*** 301,308 ****
}
struct mbuf *
! m_free(m)
! struct mbuf *m;
{
struct mbuf *n;
--- 289,295 ----
}
struct mbuf *
! m_free(struct mbuf *m)
{
struct mbuf *n;
***************
*** 311,318 ****
}
void
! m_freem(m)
! struct mbuf *m;
{
struct mbuf *n;
--- 298,304 ----
}
void
! m_freem(struct mbuf *m)
{
struct mbuf *n;
***************
*** 334,342 ****
* copy junk along.
*/
struct mbuf *
! m_prepend(m, len, how)
! struct mbuf *m;
! int len, how;
{
struct mbuf *mn;
--- 320,326 ----
* copy junk along.
*/
struct mbuf *
! m_prepend(struct mbuf *m, u_int len, int how)
{
struct mbuf *mn;
***************
*** 365,401 ****
int MCFail;
struct mbuf *
! m_copym(m, off0, len, wait)
! struct mbuf *m;
! int off0, wait;
! int len;
{
return m_copym0(m, off0, len, wait, 0); /* shallow copy on M_EXT */
}
struct mbuf *
! m_dup(m, off0, len, wait)
! struct mbuf *m;
! int off0, wait;
! int len;
{
return m_copym0(m, off0, len, wait, 1); /* deep copy */
}
static struct mbuf *
! m_copym0(m, off0, len, wait, deep)
! struct mbuf *m;
! int off0, wait;
! int len;
! int deep; /* deep copy */
{
struct mbuf *n, **np;
! int off = off0;
struct mbuf *top;
int copyhdr = 0;
- if (off < 0 || len < 0)
- panic("m_copym: off %d, len %d", off, len);
if (off == 0 && m->m_flags & M_PKTHDR)
copyhdr = 1;
while (off > 0) {
--- 349,375 ----
int MCFail;
struct mbuf *
! m_copym(struct mbuf *m, u_int off0, u_int len, int wait)
{
+
return m_copym0(m, off0, len, wait, 0); /* shallow copy on M_EXT */
}
struct mbuf *
! m_dup(struct mbuf *m, u_int off0, u_int len, int wait)
{
+
return m_copym0(m, off0, len, wait, 1); /* deep copy */
}
static struct mbuf *
! m_copym0(struct mbuf *m, u_int off0, u_int len, int wait, int deep)
{
struct mbuf *n, **np;
! u_int off = off0;
struct mbuf *top;
int copyhdr = 0;
if (off == 0 && m->m_flags & M_PKTHDR)
copyhdr = 1;
while (off > 0) {
***************
*** 447,453 ****
}
} else
memcpy(mtod(n, caddr_t), mtod(m, caddr_t)+off,
! (unsigned)n->m_len);
if (len != M_COPYALL)
len -= n->m_len;
off += n->m_len;
--- 421,427 ----
}
} else
memcpy(mtod(n, caddr_t), mtod(m, caddr_t)+off,
! n->m_len);
if (len != M_COPYALL)
len -= n->m_len;
off += n->m_len;
***************
*** 475,483 ****
* An optimization of the common case `m_copym(m, 0, M_COPYALL, how)'.
*/
struct mbuf *
! m_copypacket(m, how)
! struct mbuf *m;
! int how;
{
struct mbuf *top, *n, *o;
--- 449,455 ----
* An optimization of the common case `m_copym(m, 0, M_COPYALL, how)'.
*/
struct mbuf *
! m_copypacket(struct mbuf *m, int how)
{
struct mbuf *top, *n, *o;
***************
*** 528,543 ****
* continuing for "len" bytes, into the indicated buffer.
*/
void
! m_copydata(m, off, len, cp)
! struct mbuf *m;
! int off;
! int len;
! caddr_t cp;
{
unsigned count;
- if (off < 0 || len < 0)
- panic("m_copydata");
while (off > 0) {
if (m == 0)
panic("m_copydata");
--- 500,509 ----
* continuing for "len" bytes, into the indicated buffer.
*/
void
! m_copydata(struct mbuf *m, u_int off, u_int len, caddr_t cp)
{
unsigned count;
while (off > 0) {
if (m == 0)
panic("m_copydata");
***************
*** 564,571 ****
* Any m_pkthdr is not updated.
*/
void
! m_cat(m, n)
! struct mbuf *m, *n;
{
while (m->m_next)
m = m->m_next;
--- 530,536 ----
* Any m_pkthdr is not updated.
*/
void
! m_cat(struct mbuf *m, struct mbuf *n)
{
while (m->m_next)
m = m->m_next;
***************
*** 585,604 ****
}
void
! m_adj(mp, req_len)
! struct mbuf *mp;
! int req_len;
{
- int len = req_len;
struct mbuf *m;
! int count;
if ((m = mp) == NULL)
return;
! if (len >= 0) {
/*
* Trim from head.
*/
while (m != NULL && len > 0) {
if (m->m_len <= len) {
len -= m->m_len;
--- 550,567 ----
}
void
! m_adj(struct mbuf *mp, int req_len)
{
struct mbuf *m;
! u_int len, count;
if ((m = mp) == NULL)
return;
! if (req_len >= 0) {
/*
* Trim from head.
*/
+ len = req_len;
while (m != NULL && len > 0) {
if (m->m_len <= len) {
len -= m->m_len;
***************
*** 621,627 ****
* adjust and return. Otherwise, rescan and truncate
* after the remaining size.
*/
! len = -len;
count = 0;
for (;;) {
count += m->m_len;
--- 584,590 ----
* adjust and return. Otherwise, rescan and truncate
* after the remaining size.
*/
! len = -req_len;
count = 0;
for (;;) {
count += m->m_len;
***************
*** 635,643 ****
mp->m_pkthdr.len -= len;
return;
}
! count -= len;
! if (count < 0)
count = 0;
/*
* Correct length for chain is "count".
* Find the mbuf with last data, adjust its length,
--- 598,607 ----
mp->m_pkthdr.len -= len;
return;
}
! if (count <= len)
count = 0;
+ else
+ count -= len;
/*
* Correct length for chain is "count".
* Find the mbuf with last data, adjust its length,
***************
*** 669,681 ****
int MPFail;
struct mbuf *
! m_pullup(n, len)
! struct mbuf *n;
! int len;
{
struct mbuf *m;
! int count;
! int space;
/*
* If first mbuf has no cluster, and has room for len bytes
--- 633,642 ----
int MPFail;
struct mbuf *
! m_pullup(struct mbuf *n, u_int len)
{
struct mbuf *m;
! u_int count, space;
/*
* If first mbuf has no cluster, and has room for len bytes
***************
*** 701,711 ****
n->m_flags &= ~M_PKTHDR;
}
}
! space = &m->m_dat[MLEN] - (m->m_data + m->m_len);
do {
count = min(min(max(len, max_protohdr), space), n->m_len);
! memcpy(mtod(m, caddr_t) + m->m_len, mtod(n, caddr_t),
! (unsigned)count);
len -= count;
m->m_len += count;
n->m_len -= count;
--- 662,671 ----
n->m_flags &= ~M_PKTHDR;
}
}
! space = (u_int) (&m->m_dat[MLEN] - (m->m_data + m->m_len));
do {
count = min(min(max(len, max_protohdr), space), n->m_len);
! memcpy(mtod(m, caddr_t) + m->m_len, mtod(n, caddr_t), count);
len -= count;
m->m_len += count;
n->m_len -= count;
***************
*** 735,744 ****
int MSFail;
struct mbuf *
! m_copyup(struct mbuf *n, int len, int dstoff)
{
struct mbuf *m;
! int count, space;
if (len > (MHLEN - dstoff))
goto bad;
--- 695,704 ----
int MSFail;
struct mbuf *
! m_copyup(struct mbuf *n, u_int len, u_int dstoff)
{
struct mbuf *m;
! u_int count, space;
if (len > (MHLEN - dstoff))
goto bad;
***************
*** 751,757 ****
n->m_flags &= ~M_PKTHDR;
}
m->m_data += dstoff;
! space = &m->m_dat[MLEN] - (m->m_data + m->m_len);
do {
count = min(min(max(len, max_protohdr), space), n->m_len);
memcpy(mtod(m, caddr_t) + m->m_len, mtod(n, caddr_t),
--- 711,717 ----
n->m_flags &= ~M_PKTHDR;
}
m->m_data += dstoff;
! space = (u_int) (&m->m_dat[MLEN] - (m->m_data + m->m_len));
do {
count = min(min(max(len, max_protohdr), space), n->m_len);
memcpy(mtod(m, caddr_t) + m->m_len, mtod(n, caddr_t),
***************
*** 783,794 ****
* attempts to restore the chain to its original state.
*/
struct mbuf *
! m_split(m0, len0, wait)
! struct mbuf *m0;
! int len0, wait;
{
struct mbuf *m, *n;
! unsigned len = len0, remain, len_save;
for (m = m0; m && len > m->m_len; m = m->m_next)
len -= m->m_len;
--- 743,752 ----
* attempts to restore the chain to its original state.
*/
struct mbuf *
! m_split(struct mbuf *m0, u_int len0, int wait)
{
struct mbuf *m, *n;
! u_int len = len0, remain, len_save;
for (m = m0; m && len > m->m_len; m = m->m_next)
len -= m->m_len;
***************
*** 845,859 ****
* Routine to copy from device local memory into mbufs.
*/
struct mbuf *
! m_devget(buf, totlen, off0, ifp, copy)
! char *buf;
! int totlen, off0;
! struct ifnet *ifp;
! void (*copy) __P((const void *from, void *to, size_t len));
{
struct mbuf *m;
struct mbuf *top = 0, **mp = ⊤
! int off = off0, len;
char *cp;
char *epkt;
--- 803,814 ----
* Routine to copy from device local memory into mbufs.
*/
struct mbuf *
! m_devget(char *buf, u_int totlen, u_int off0, struct ifnet *ifp,
! void (*copy)(const void *, void *, size_t))
{
struct mbuf *m;
struct mbuf *top = 0, **mp = ⊤
! u_int off = off0, len;
char *cp;
char *epkt;
***************
*** 883,889 ****
}
m->m_len = MLEN;
}
! len = min(totlen, epkt - cp);
if (len >= MINCLSIZE) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
--- 838,844 ----
}
m->m_len = MLEN;
}
! len = min(totlen, (u_int)(epkt - cp));
if (len >= MINCLSIZE) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
***************
*** 923,937 ****
* chain if necessary.
*/
void
! m_copyback(m0, off, len, cp)
! struct mbuf *m0;
! int off;
! int len;
! caddr_t cp;
{
- int mlen;
struct mbuf *m = m0, *n;
! int totlen = 0;
if (m0 == 0)
return;
--- 878,887 ----
* chain if necessary.
*/
void
! m_copyback(struct mbuf *m0, u_int off, u_int len, caddr_t cp)
{
struct mbuf *m = m0, *n;
! u_int mlen, totlen = 0;
if (m0 == 0)
return;
Index: kern/uipc_mbuf2.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/uipc_mbuf2.c,v
retrieving revision 1.11
diff -c -r1.11 uipc_mbuf2.c
*** kern/uipc_mbuf2.c 2002/10/22 03:29:51 1.11
--- kern/uipc_mbuf2.c 2002/11/10 04:12:33
***************
*** 85,97 ****
* XXX M_TRAILINGSPACE/M_LEADINGSPACE on shared cluster (sharedcluster)
*/
struct mbuf *
! m_pulldown(m, off, len, offp)
! struct mbuf *m;
! int off, len;
! int *offp;
{
struct mbuf *n, *o;
! int hlen, tlen, olen;
int sharedcluster;
/* check invalid arguments. */
--- 85,94 ----
* XXX M_TRAILINGSPACE/M_LEADINGSPACE on shared cluster (sharedcluster)
*/
struct mbuf *
! m_pulldown(struct mbuf *m, u_int off, u_int len, u_int *offp)
{
struct mbuf *n, *o;
! u_int hlen, tlen, olen;
int sharedcluster;
/* check invalid arguments. */
***************
*** 228,236 ****
* we don't allow clusters at this moment.
*/
struct mbuf *
! m_aux_add(m, af, type)
! struct mbuf *m;
! int af, type;
{
struct mbuf *n;
struct mauxtag *t;
--- 225,231 ----
* we don't allow clusters at this moment.
*/
struct mbuf *
! m_aux_add(struct mbuf *m, int af, int type)
{
struct mbuf *n;
struct mauxtag *t;
***************
*** 257,265 ****
}
struct mbuf *
! m_aux_find(m, af, type)
! struct mbuf *m;
! int af, type;
{
struct mbuf *n;
struct mauxtag *t;
--- 252,258 ----
}
struct mbuf *
! m_aux_find(struct mbuf *m, int af, int type)
{
struct mbuf *n;
struct mauxtag *t;
***************
*** 276,284 ****
}
void
! m_aux_delete(m, victim)
! struct mbuf *m;
! struct mbuf *victim;
{
struct mbuf *n, *prev, *next;
--- 269,275 ----
}
void
! m_aux_delete(struct mbuf *m, struct mbuf *victim)
{
struct mbuf *n, *prev, *next;
Index: sys/mbuf.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/mbuf.h,v
retrieving revision 1.67
diff -c -r1.67 mbuf.h
*** sys/mbuf.h 2002/06/30 22:40:40 1.67
--- sys/mbuf.h 2002/11/10 04:12:34
***************
*** 106,112 ****
struct mbuf *mh_next; /* next buffer in chain */
struct mbuf *mh_nextpkt; /* next chain in queue/record */
caddr_t mh_data; /* location of data */
! int mh_len; /* amount of data in this mbuf */
short mh_type; /* type of data in this mbuf */
short mh_flags; /* flags; see below */
};
--- 106,112 ----
struct mbuf *mh_next; /* next buffer in chain */
struct mbuf *mh_nextpkt; /* next chain in queue/record */
caddr_t mh_data; /* location of data */
! u_int mh_len; /* amount of data in this mbuf */
short mh_type; /* type of data in this mbuf */
short mh_flags; /* flags; see below */
};
***************
*** 127,133 ****
*/
struct pkthdr {
struct ifnet *rcvif; /* rcv interface */
! int len; /* total packet length */
int csum_flags; /* checksum flags */
u_int32_t csum_data; /* checksum data */
struct mbuf *aux; /* extra data buffer; ipsec/others */
--- 127,133 ----
*/
struct pkthdr {
struct ifnet *rcvif; /* rcv interface */
! u_int len; /* total packet length */
int csum_flags; /* checksum flags */
u_int32_t csum_data; /* checksum data */
struct mbuf *aux; /* extra data buffer; ipsec/others */
***************
*** 520,540 ****
* before the current start of data in an mbuf.
*/
#define _M_LEADINGSPACE(m) \
! ((m)->m_flags & M_EXT ? (m)->m_data - (m)->m_ext.ext_buf : \
! (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
! (m)->m_data - (m)->m_dat)
#define M_LEADINGSPACE(m) \
! (M_READONLY((m)) ? 0 : _M_LEADINGSPACE((m)))
/*
* Compute the amount of space available
* after the end of data in an mbuf.
*/
#define _M_TRAILINGSPACE(m) \
! ((m)->m_flags & M_EXT ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size - \
! ((m)->m_data + (m)->m_len) : \
! &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
#define M_TRAILINGSPACE(m) \
(M_READONLY((m)) ? 0 : _M_TRAILINGSPACE((m)))
--- 520,543 ----
* before the current start of data in an mbuf.
*/
#define _M_LEADINGSPACE(m) \
! ((m)->m_flags & M_EXT ? \
! (u_int)((m)->m_data - (m)->m_ext.ext_buf) : \
! (m)->m_flags & M_PKTHDR ? \
! (u_int)((m)->m_data - (m)->m_pktdat) : \
! (u_int)((m)->m_data - (m)->m_dat))
#define M_LEADINGSPACE(m) \
! (M_READONLY((m)) ? 0 : (size_t)_M_LEADINGSPACE((m)))
/*
* Compute the amount of space available
* after the end of data in an mbuf.
*/
#define _M_TRAILINGSPACE(m) \
! ((m)->m_flags & M_EXT ? \
! (u_int)(((m)->m_ext.ext_buf + (m)->m_ext.ext_size) - \
! ((m)->m_data + (m)->m_len)) : \
! (u_int)(&(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len)))
#define M_TRAILINGSPACE(m) \
(M_READONLY((m)) ? 0 : _M_TRAILINGSPACE((m)))
***************
*** 564,570 ****
} while (/* CONSTCOND */ 0)
/* length to m_copy to copy all */
! #define M_COPYALL 1000000000
/* compatibility with 4.3 */
#define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
--- 567,573 ----
} while (/* CONSTCOND */ 0)
/* length to m_copy to copy all */
! #define M_COPYALL ((u_int) 1000000000)
/* compatibility with 4.3 */
#define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
***************
*** 639,663 ****
extern struct pool_cache mbpool_cache;
extern struct pool_cache mclpool_cache;
! struct mbuf *m_copym __P((struct mbuf *, int, int, int));
struct mbuf *m_copypacket __P((struct mbuf *, int));
! struct mbuf *m_devget __P((char *, int, int, struct ifnet *,
void (*copy)(const void *, void *, size_t)));
! struct mbuf *m_dup __P((struct mbuf *, int, int, int));
struct mbuf *m_free __P((struct mbuf *));
struct mbuf *m_get __P((int, int));
struct mbuf *m_getclr __P((int, int));
struct mbuf *m_gethdr __P((int, int));
! struct mbuf *m_prepend __P((struct mbuf *,int,int));
! struct mbuf *m_pulldown __P((struct mbuf *, int, int, int *));
! struct mbuf *m_pullup __P((struct mbuf *, int));
! struct mbuf *m_copyup __P((struct mbuf *, int, int));
! struct mbuf *m_split __P((struct mbuf *,int,int));
void m_adj __P((struct mbuf *, int));
void m_cat __P((struct mbuf *,struct mbuf *));
int m_mballoc __P((int, int));
! void m_copyback __P((struct mbuf *, int, int, caddr_t));
! void m_copydata __P((struct mbuf *, int, int, caddr_t));
void m_freem __P((struct mbuf *));
void m_reclaim __P((void *, int));
void mbinit __P((void));
--- 642,666 ----
extern struct pool_cache mbpool_cache;
extern struct pool_cache mclpool_cache;
! struct mbuf *m_copym __P((struct mbuf *, u_int, u_int, int));
struct mbuf *m_copypacket __P((struct mbuf *, int));
! struct mbuf *m_devget __P((char *, u_int, u_int, struct ifnet *,
void (*copy)(const void *, void *, size_t)));
! struct mbuf *m_dup __P((struct mbuf *, u_int, u_int, int));
struct mbuf *m_free __P((struct mbuf *));
struct mbuf *m_get __P((int, int));
struct mbuf *m_getclr __P((int, int));
struct mbuf *m_gethdr __P((int, int));
! struct mbuf *m_prepend __P((struct mbuf *, u_int, int));
! struct mbuf *m_pulldown __P((struct mbuf *, u_int, u_int, u_int *));
! struct mbuf *m_pullup __P((struct mbuf *, u_int));
! struct mbuf *m_copyup __P((struct mbuf *, u_int, u_int));
! struct mbuf *m_split __P((struct mbuf *, u_int, int));
void m_adj __P((struct mbuf *, int));
void m_cat __P((struct mbuf *,struct mbuf *));
int m_mballoc __P((int, int));
! void m_copyback __P((struct mbuf *, u_int, u_int, caddr_t));
! void m_copydata __P((struct mbuf *, u_int, u_int, caddr_t));
void m_freem __P((struct mbuf *));
void m_reclaim __P((void *, int));
void mbinit __P((void));
--5QAgd0e35j3NYeGe--