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.
This commit is contained in:
Gleb Smirnoff 2013-03-12 12:12:16 +00:00
parent 9ccde34069
commit 8c629bdf05
2 changed files with 23 additions and 17 deletions

View File

@ -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);
}
/*

View File

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