m_freem checks for NULL so the caller doesnt have to.

ml_purge and m_purge were invented after some of the mq and ml code
was written, so fix that code to use the "new" functions.

ok?

Index: uipc_mbuf.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.224
diff -u -p -r1.224 uipc_mbuf.c
--- uipc_mbuf.c 15 Apr 2016 05:05:21 -0000      1.224
+++ uipc_mbuf.c 15 Apr 2016 05:19:49 -0000
@@ -326,8 +326,7 @@ m_clget(struct mbuf *m, int how, u_int p
        }
        buf = pool_get(pp, how == M_WAIT ? PR_WAITOK : PR_NOWAIT);
        if (buf == NULL) {
-               if (m0)
-                       m_freem(m0);
+               m_freem(m0);
                return (NULL);
        }
 
@@ -983,8 +982,7 @@ m_inject(struct mbuf *m0, int len0, int 
 
        MGET(n, wait, MT_DATA);
        if (n == NULL) {
-               if (n2)
-                       m_freem(n2);
+               m_freem(n2);
                return (NULL);
        }
 
@@ -1399,15 +1397,10 @@ ml_dechain(struct mbuf_list *ml)
 unsigned int
 ml_purge(struct mbuf_list *ml)
 {
-       struct mbuf *m, *n;
        unsigned int len;
 
-       for (m = ml->ml_head; m != NULL; m = n) {
-               n = m->m_nextpkt;
-               m_freem(m);
-       }
-
        len = ml->ml_len;
+       m_purge(ml->ml_head);
        ml_init(ml);
 
        return (len);
@@ -1460,7 +1453,6 @@ mq_dequeue(struct mbuf_queue *mq)
 int
 mq_enlist(struct mbuf_queue *mq, struct mbuf_list *ml)
 {
-       struct mbuf *m;
        int dropped = 0;
 
        mtx_enter(&mq->mq_mtx);
@@ -1472,10 +1464,8 @@ mq_enlist(struct mbuf_queue *mq, struct 
        }
        mtx_leave(&mq->mq_mtx);
 
-       if (dropped) {
-               while ((m = ml_dequeue(ml)) != NULL)
-                       m_freem(m);
-       }
+       if (dropped)
+               ml_purge(ml);
 
        return (dropped);
 }

Reply via email to