diff options
author | glebius <glebius@FreeBSD.org> | 2013-03-12 12:12:16 +0000 |
---|---|---|
committer | glebius <glebius@FreeBSD.org> | 2013-03-12 12:12:16 +0000 |
commit | ce515e6007c76b0ec23c6cce28f5d22c61219656 (patch) | |
tree | 0d024cc422747189d0a97cceae932de9cca805aa | |
parent | 8be88fc42e7a1965a9adae2c9b231d96639abd20 (diff) | |
download | FreeBSD-src-ce515e6007c76b0ec23c6cce28f5d22c61219656.zip FreeBSD-src-ce515e6007c76b0ec23c6cce28f5d22c61219656.tar.gz |
The m_extadd() can fail due to memory allocation failure, thus:
- Make it return int, not void.
- Add wait parameter.
- Update MEXTADD() macro appropriately, defaults to M_NOWAIT, as
before this change.
Sponsored by: Nginx, Inc.
-rw-r--r-- | sys/kern/uipc_mbuf.c | 33 | ||||
-rw-r--r-- | sys/sys/mbuf.h | 7 |
2 files changed, 23 insertions, 17 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 4606f37..13c9b52 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -255,25 +255,30 @@ m_freem(struct mbuf *mb) * Returns: * Nothing. */ -void +int m_extadd(struct mbuf *mb, caddr_t buf, u_int size, - void (*freef)(void *, void *), void *arg1, void *arg2, int flags, int type) + void (*freef)(void *, void *), void *arg1, void *arg2, int flags, int type, + int wait) { KASSERT(type != EXT_CLUSTER, ("%s: EXT_CLUSTER not allowed", __func__)); if (type != EXT_EXTREF) - mb->m_ext.ref_cnt = (u_int *)uma_zalloc(zone_ext_refcnt, M_NOWAIT); - if (mb->m_ext.ref_cnt != NULL) { - *(mb->m_ext.ref_cnt) = 1; - mb->m_flags |= (M_EXT | flags); - mb->m_ext.ext_buf = buf; - mb->m_data = mb->m_ext.ext_buf; - mb->m_ext.ext_size = size; - mb->m_ext.ext_free = freef; - mb->m_ext.ext_arg1 = arg1; - mb->m_ext.ext_arg2 = arg2; - mb->m_ext.ext_type = type; - } + mb->m_ext.ref_cnt = uma_zalloc(zone_ext_refcnt, wait); + + if (mb->m_ext.ref_cnt == NULL) + return (ENOMEM); + + *(mb->m_ext.ref_cnt) = 1; + mb->m_flags |= (M_EXT | flags); + mb->m_ext.ext_buf = buf; + mb->m_data = mb->m_ext.ext_buf; + mb->m_ext.ext_size = size; + mb->m_ext.ext_free = freef; + mb->m_ext.ext_arg1 = arg1; + mb->m_ext.ext_arg2 = arg2; + mb->m_ext.ext_type = type; + + return (0); } /* diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index af7f92b..9960f53 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -655,7 +655,8 @@ m_last(struct mbuf *m) #define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) #define MCLGET(m, how) m_clget((m), (how)) #define MEXTADD(m, buf, size, free, arg1, arg2, flags, type) \ - m_extadd((m), (caddr_t)(buf), (size), (free),(arg1),(arg2),(flags), (type)) + (void )m_extadd((m), (caddr_t)(buf), (size), (free), (arg1), (arg2),\ + (flags), (type), M_NOWAIT) #define m_getm(m, len, how, type) \ m_getm2((m), (len), (how), (type), M_PKTHDR) @@ -780,8 +781,8 @@ int m_apply(struct mbuf *, int, int, int (*)(void *, void *, u_int), void *); int m_append(struct mbuf *, int, c_caddr_t); void m_cat(struct mbuf *, struct mbuf *); -void m_extadd(struct mbuf *, caddr_t, u_int, - void (*)(void *, void *), void *, void *, int, int); +int m_extadd(struct mbuf *, caddr_t, u_int, + void (*)(void *, void *), void *, void *, int, int, int); struct mbuf *m_collapse(struct mbuf *, int, int); void m_copyback(struct mbuf *, int, int, c_caddr_t); void m_copydata(const struct mbuf *, int, int, caddr_t); |