svn commit: r248193 - in head/sys: kern sys

Gleb Smirnoff glebius at FreeBSD.org
Tue Mar 12 12:12:17 UTC 2013


Author: glebius
Date: Tue Mar 12 12:12:16 2013
New Revision: 248193
URL: http://svnweb.freebsd.org/changeset/base/248193

Log:
  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.

Modified:
  head/sys/kern/uipc_mbuf.c
  head/sys/sys/mbuf.h

Modified: head/sys/kern/uipc_mbuf.c
==============================================================================
--- head/sys/kern/uipc_mbuf.c	Tue Mar 12 12:10:32 2013	(r248192)
+++ head/sys/kern/uipc_mbuf.c	Tue Mar 12 12:12:16 2013	(r248193)
@@ -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);
 }
 
 /*

Modified: head/sys/sys/mbuf.h
==============================================================================
--- head/sys/sys/mbuf.h	Tue Mar 12 12:10:32 2013	(r248192)
+++ head/sys/sys/mbuf.h	Tue Mar 12 12:12:16 2013	(r248193)
@@ -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);


More information about the svn-src-all mailing list