Source-Changes-HG archive

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

[src/trunk]: src/sys - Convert sb_lowat to unsigned for consistency. There ar...



details:   https://anonhg.NetBSD.org/src/rev/300af0175950
branches:  trunk
changeset: 831261:300af0175950
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 18 15:32:48 2018 +0000

description:
- Convert sb_lowat to unsigned for consistency. There are no negative value
  uses
- Check for overflow as mentioned in the comment
- Sprinkle const

diffstat:

 sys/kern/uipc_socket2.c |  10 +++++-----
 sys/sys/socketvar.h     |  26 +++++++++++++-------------
 2 files changed, 18 insertions(+), 18 deletions(-)

diffs (122 lines):

diff -r 4f194b43a621 -r 300af0175950 sys/kern/uipc_socket2.c
--- a/sys/kern/uipc_socket2.c   Sun Mar 18 13:18:39 2018 +0000
+++ b/sys/kern/uipc_socket2.c   Sun Mar 18 15:32:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket2.c,v 1.126 2017/07/06 17:42:39 christos Exp $      */
+/*     $NetBSD: uipc_socket2.c,v 1.127 2018/03/18 15:32:48 christos Exp $      */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.126 2017/07/06 17:42:39 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.127 2018/03/18 15:32:48 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mbuftrace.h"
@@ -1427,16 +1427,16 @@
 }
 
 bool
-solocked(struct socket *so)
+solocked(const struct socket *so)
 {
 
        return mutex_owned(so->so_lock);
 }
 
 bool
-solocked2(struct socket *so1, struct socket *so2)
+solocked2(const struct socket *so1, const struct socket *so2)
 {
-       kmutex_t *lock;
+       const kmutex_t *lock;
 
        lock = so1->so_lock;
        if (lock != so2->so_lock)
diff -r 4f194b43a621 -r 300af0175950 sys/sys/socketvar.h
--- a/sys/sys/socketvar.h       Sun Mar 18 13:18:39 2018 +0000
+++ b/sys/sys/socketvar.h       Sun Mar 18 15:32:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: socketvar.h,v 1.148 2018/03/16 17:35:13 christos Exp $ */
+/*     $NetBSD: socketvar.h,v 1.149 2018/03/18 15:32:48 christos Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -93,7 +93,7 @@
        u_long  sb_hiwat;               /* max actual char count */
        u_long  sb_mbcnt;               /* chars of mbufs used */
        u_long  sb_mbmax;               /* max chars of mbufs to use */
-       long    sb_lowat;               /* low water mark */
+       u_long  sb_lowat;               /* low water mark */
        struct mbuf *sb_mb;             /* the mbuf chain */
        struct mbuf *sb_mbtail;         /* the last mbuf in the chain */
        struct mbuf *sb_lastrecord;     /* first mbuf of last record in
@@ -301,6 +301,7 @@
 int    sobind(struct socket *, struct sockaddr *, struct lwp *);
 void   socantrcvmore(struct socket *);
 void   socantsendmore(struct socket *);
+void   soroverflow(struct socket *);
 int    soclose(struct socket *);
 int    soconnect(struct socket *, struct sockaddr *, struct lwp *);
 int    soconnect2(struct socket *, struct socket *);
@@ -335,8 +336,8 @@
 int    sopoll(struct socket *, int);
 struct socket *soget(bool);
 void   soput(struct socket *);
-bool   solocked(struct socket *);
-bool   solocked2(struct socket *, struct socket *);
+bool   solocked(const struct socket *);
+bool   solocked2(const struct socket *, const struct socket *);
 int    sblock(struct sockbuf *, int);
 void   sbunlock(struct sockbuf *);
 int    sowait(struct socket *, bool, int);
@@ -399,22 +400,21 @@
 
 /*
  * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
- * This is problematical if the fields are unsigned, as the space might
- * still be negative (cc > hiwat or mbcnt > mbmax).  Should detect
- * overflow and return 0.
+ * Since the fields are unsigned, detect overflow and return 0.
  */
-static inline long
-sbspace(struct sockbuf *sb)
+static inline u_long
+sbspace(const struct sockbuf *sb)
 {
 
        KASSERT(solocked(sb->sb_so));
-
+       if (sb->sb_hiwat <= sb->sb_cc || sb->sb_mbmax <= sb->sb_mbcnt)
+               return 0;
        return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
 }
 
 /* do we have to send all at once on a socket? */
 static inline int
-sosendallatonce(struct socket *so)
+sosendallatonce(const struct socket *so)
 {
 
        return so->so_proto->pr_flags & PR_ATOMIC;
@@ -422,7 +422,7 @@
 
 /* can we read something from so? */
 static inline int
-soreadable(struct socket *so)
+soreadable(const struct socket *so)
 {
 
        KASSERT(solocked(so));
@@ -434,7 +434,7 @@
 
 /* can we write something to so? */
 static inline int
-sowritable(struct socket *so)
+sowritable(const struct socket *so)
 {
 
        KASSERT(solocked(so));



Home | Main Index | Thread Index | Old Index