Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern style



details:   https://anonhg.NetBSD.org/src/rev/10e8068f4da7
branches:  trunk
changeset: 997420:10e8068f4da7
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Mar 07 12:22:43 2019 +0000

description:
style

diffstat:

 sys/kern/uipc_socket.c |  202 +++++++++++++++++++++++-------------------------
 1 files changed, 96 insertions(+), 106 deletions(-)

diffs (truncated from 600 to 300 lines):

diff -r 29eacaa56b07 -r 10e8068f4da7 sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c    Thu Mar 07 12:07:42 2019 +0000
+++ b/sys/kern/uipc_socket.c    Thu Mar 07 12:22:43 2019 +0000
@@ -1,6 +1,6 @@
-/*     $NetBSD: uipc_socket.c,v 1.269 2019/02/04 04:18:27 mrg Exp $    */
+/*     $NetBSD: uipc_socket.c,v 1.270 2019/03/07 12:22:43 maxv Exp $   */
 
-/*-
+/*
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.269 2019/02/04 04:18:27 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.270 2019/03/07 12:22:43 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -206,28 +206,19 @@
 /*
  * sokvaalloc: allocate kva for loan.
  */
-
 vaddr_t
 sokvaalloc(vaddr_t sva, vsize_t len, struct socket *so)
 {
        vaddr_t lva;
 
-       /*
-        * reserve kva.
-        */
-
        if (sokvareserve(so, len) == 0)
                return 0;
 
-       /*
-        * allocate kva.
-        */
-
        lva = uvm_km_alloc(kernel_map, len, atop(sva) & uvmexp.colormask,
            UVM_KMF_COLORMATCH | UVM_KMF_VAONLY | UVM_KMF_WAITVA);
        if (lva == 0) {
                sokvaunreserve(len);
-               return (0);
+               return 0;
        }
 
        return lva;
@@ -236,21 +227,11 @@
 /*
  * sokvafree: free kva for loan.
  */
-
 void
 sokvafree(vaddr_t sva, vsize_t len)
 {
 
-       /*
-        * free kva.
-        */
-
        uvm_km_free(kernel_map, sva, len, UVM_KMF_VAONLY);
-
-       /*
-        * unreserve kva.
-        */
-
        sokvaunreserve(len);
 }
 
@@ -275,10 +256,9 @@
 }
 
 /*
- * sopendfree_thread: free mbufs on "pendfree" list.
- * unlock and relock so_pendfree_lock when freeing mbufs.
+ * sopendfree_thread: free mbufs on "pendfree" list. Unlock and relock
+ * so_pendfree_lock when freeing mbufs.
  */
-
 static void
 sopendfree_thread(void *v)
 {
@@ -348,7 +328,7 @@
        int i;
 
        if (VMSPACE_IS_KERNEL_P(uio->uio_vmspace))
-               return (0);
+               return 0;
 
        if (iov->iov_len < (size_t) space)
                space = iov->iov_len;
@@ -370,7 +350,7 @@
            m->m_ext.ext_pgs, UVM_LOAN_TOPAGE);
        if (error) {
                sokvafree(lva, len);
-               return (0);
+               return 0;
        }
 
        for (i = 0, va = lva; i < npgs; i++, va += PAGE_SIZE)
@@ -392,7 +372,7 @@
                uio->uio_iovcnt--;
        }
 
-       return (space);
+       return space;
 }
 
 struct mbuf *
@@ -501,13 +481,13 @@
  */
 int
 socreate(int dom, struct socket **aso, int type, int proto, struct lwp *l,
-        struct socket *lockso)
+    struct socket *lockso)
 {
-       const struct protosw    *prp;
-       struct socket   *so;
-       uid_t           uid;
-       int             error;
-       kmutex_t        *lock;
+       const struct protosw *prp;
+       struct socket *so;
+       uid_t uid;
+       int error;
+       kmutex_t *lock;
 
        error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET,
            KAUTH_REQ_NETWORK_SOCKET_OPEN, KAUTH_ARG(dom), KAUTH_ARG(type),
@@ -635,7 +615,7 @@
 int
 sobind(struct socket *so, struct sockaddr *nam, struct lwp *l)
 {
-       int     error;
+       int error;
 
        solock(so);
        if (nam->sa_family != so->so_proto->pr_domain->dom_family) {
@@ -650,8 +630,8 @@
 int
 solisten(struct socket *so, int backlog, struct lwp *l)
 {
-       int     error;
-       short   oldopt, oldqlimit;
+       int error;
+       short oldopt, oldqlimit;
 
        solock(so);
        if ((so->so_state & (SS_ISCONNECTED | SS_ISCONNECTING |
@@ -865,7 +845,7 @@
 int
 sodisconnect(struct socket *so)
 {
-       int     error;
+       int error;
 
        KASSERT(solocked(so));
 
@@ -876,7 +856,7 @@
        } else {
                error = (*so->so_proto->pr_usrreqs->pr_disconnect)(so);
        }
-       return (error);
+       return error;
 }
 
 #define        SBLOCKWAIT(f)   (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK)
@@ -901,10 +881,10 @@
 sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
        struct mbuf *top, struct mbuf *control, int flags, struct lwp *l)
 {
-       struct mbuf     **mp, *m;
-       long            space, len, resid, clen, mlen;
-       int             error, s, dontroute, atomic;
-       short           wakeup_state = 0;
+       struct mbuf **mp, *m;
+       long space, len, resid, clen, mlen;
+       int error, s, dontroute, atomic;
+       short wakeup_state = 0;
 
        clen = 0;
 
@@ -1099,14 +1079,14 @@
                m_freem(top);
        if (control)
                m_freem(control);
-       return (error);
+       return error;
 }
 
 /*
  * Following replacement or removal of the first mbuf on the first
  * mbuf chain of a socket buffer, push necessary state changes back
  * into the socket buffer so that other consumers see the values
- * consistently.  'nextrecord' is the callers locally stored value of
+ * consistently.  'nextrecord' is the caller's locally stored value of
  * the original value of sb->sb_mb->m_nextpkt which must be restored
  * when the lead mbuf changes.  NOTE: 'nextrecord' may be NULL.
  */
@@ -1141,33 +1121,34 @@
 
 /*
  * Implement receive operations on a socket.
- * We depend on the way that records are added to the sockbuf
- * by sbappend*.  In particular, each record (mbufs linked through m_next)
- * must begin with an address if the protocol so specifies,
- * followed by an optional mbuf or mbufs containing ancillary data,
- * and then zero or more mbufs of data.
- * In order to avoid blocking network interrupts for the entire time here,
- * we splx() while doing the actual copy to user space.
- * Although the sockbuf is locked, new data may still be appended,
- * and thus we must maintain consistency of the sockbuf during that time.
+ *
+ * We depend on the way that records are added to the sockbuf by sbappend*. In
+ * particular, each record (mbufs linked through m_next) must begin with an
+ * address if the protocol so specifies, followed by an optional mbuf or mbufs
+ * containing ancillary data, and then zero or more mbufs of data.
  *
- * The caller may receive the data as a single mbuf chain by supplying
- * an mbuf **mp0 for use in returning the chain.  The uio is then used
- * only for the count in uio_resid.
+ * In order to avoid blocking network interrupts for the entire time here, we
+ * splx() while doing the actual copy to user space. Although the sockbuf is
+ * locked, new data may still be appended, and thus we must maintain
+ * consistency of the sockbuf during that time.
+ *
+ * The caller may receive the data as a single mbuf chain by supplying an mbuf
+ * **mp0 for use in returning the chain. The uio is then used only for the
+ * count in uio_resid.
  */
 int
 soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio,
-       struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
+    struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
 {
        struct lwp *l = curlwp;
-       struct mbuf     *m, **mp, *mt;
+       struct mbuf *m, **mp, *mt;
        size_t len, offset, moff, orig_resid;
        int atomic, flags, error, s, type;
-       const struct protosw    *pr;
-       struct mbuf     *nextrecord;
-       int             mbuf_removed = 0;
+       const struct protosw *pr;
+       struct mbuf *nextrecord;
+       int mbuf_removed = 0;
        const struct domain *dom;
-       short           wakeup_state = 0;
+       short wakeup_state = 0;
 
        pr = so->so_proto;
        atomic = pr->pr_flags & PR_ATOMIC;
@@ -1197,7 +1178,7 @@
                            MIN(uio->uio_resid, m->m_len), uio);
                        m = m_free(m);
                } while (uio->uio_resid > 0 && error == 0 && m);
- bad:
+bad:
                if (m != NULL)
                        m_freem(m);
                return error;
@@ -1212,14 +1193,14 @@
         */
        s = splsoftnet();
        solock(so);
- restart:
+restart:
        if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0) {
                sounlock(so);
                splx(s);
                return error;
        }
+       m = so->so_rcv.sb_mb;
 
-       m = so->so_rcv.sb_mb;
        /*
         * If we have less data than requested, block awaiting more
         * (subject to any timeout) if:
@@ -1292,7 +1273,8 @@
                wakeup_state = so->so_state;
                goto restart;
        }
- dontblock:
+
+dontblock:
        /*
         * On entry here, m points to the first record of the socket buffer.
         * From this point onward, we maintain 'nextrecord' as a cache of the
@@ -1315,11 +1297,9 @@
        SBLASTRECORDCHK(&so->so_rcv, "soreceive 1");
        SBLASTMBUFCHK(&so->so_rcv, "soreceive 1");
        nextrecord = m->m_nextpkt;
+
        if (pr->pr_flags & PR_ADDR) {
-#ifdef DIAGNOSTIC
-               if (m->m_type != MT_SONAME)



Home | Main Index | Thread Index | Old Index