Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd/common/include/linux linux: Timeout audit -...



details:   https://anonhg.NetBSD.org/src/rev/e508e8ad852b
branches:  trunk
changeset: 1028963:e508e8ad852b
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 12:35:37 2021 +0000

description:
linux: Timeout audit -- linux/completion.h.

diffstat:

 sys/external/bsd/common/include/linux/completion.h |  51 +++++++++++----------
 1 files changed, 27 insertions(+), 24 deletions(-)

diffs (112 lines):

diff -r 7c9379929476 -r e508e8ad852b sys/external/bsd/common/include/linux/completion.h
--- a/sys/external/bsd/common/include/linux/completion.h        Sun Dec 19 12:35:28 2021 +0000
+++ b/sys/external/bsd/common/include/linux/completion.h        Sun Dec 19 12:35:37 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: completion.h,v 1.11 2021/12/19 12:22:56 riastradh Exp $        */
+/*     $NetBSD: completion.h,v 1.12 2021/12/19 12:35:37 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -198,18 +198,18 @@
 
        mutex_enter(&completion->c_lock);
 
-       /* Wait until c_done is nonzero.  */
+       /* Wait until c_done is nonzero, timeout, or signal.  */
        while (completion->c_done == 0) {
-               error = cv_timedwait_sig(&completion->c_cv,
-                   &completion->c_lock, ticks);
-               if (error)
-                       goto out;
-               now = getticks();
-               if (ticks < (now - start)) {
+               if (ticks == 0) {
                        error = EWOULDBLOCK;
                        goto out;
                }
-               ticks -= (now - start);
+               error = cv_timedwait_sig(&completion->c_cv,
+                   &completion->c_lock, MIN(ticks, INT_MAX/2));
+               now = getticks();
+               if (error)
+                       goto out;
+               ticks -= MIN(ticks, (now - start));
                start = now;
        }
 
@@ -224,7 +224,7 @@
                return -ERESTARTSYS;
        } else {
                KASSERTMSG((error == 0), "error = %d", error);
-               return ticks;
+               return MAX(1, MIN(ticks, INT_MAX/2));
        }
 }
 
@@ -232,23 +232,23 @@
 wait_for_completion_timeout(struct completion *completion, unsigned long ticks)
 {
        /* XXX Arithmetic overflow...?  */
-       unsigned int start = hardclock_ticks, now;
+       unsigned int start = getticks(), now;
        int error;
 
        mutex_enter(&completion->c_lock);
 
-       /* Wait until c_done is nonzero.  */
+       /* Wait until c_done is nonzero or timeout.  */
        while (completion->c_done == 0) {
-               error = cv_timedwait(&completion->c_cv, &completion->c_lock,
-                   ticks);
-               if (error)
-                       goto out;
-               now = hardclock_ticks;
-               if (ticks < (now - start)) {
+               if (ticks == 0) {
                        error = EWOULDBLOCK;
                        goto out;
                }
-               ticks -= (now - start);
+               error = cv_timedwait(&completion->c_cv, &completion->c_lock,
+                   MIN(ticks, INT_MAX/2));
+               now = getticks();
+               if (error)
+                       goto out;
+               ticks -= MIN(ticks, (now - start));
                start = now;
        }
 
@@ -261,7 +261,7 @@
                return 0;
        } else {
                KASSERTMSG((error == 0), "error = %d", error);
-               return ticks;
+               return MAX(1, MIN(ticks, INT_MAX/2));
        }
 }
 
@@ -275,7 +275,7 @@
 
        mutex_enter(&completion->c_lock);
 
-       /* Wait until c_done is nonzero.  */
+       /* Wait until c_done is nonzero or signal.  */
        while (completion->c_done == 0) {
                error = cv_wait_sig(&completion->c_cv, &completion->c_lock);
                if (error)
@@ -287,9 +287,12 @@
        error = 0;
 
 out:   mutex_exit(&completion->c_lock);
-       if ((error == EINTR) || (error == ERESTART))
-               error = -ERESTARTSYS;
-       return error;
+       if ((error == EINTR) || (error == ERESTART)) {
+               return -ERESTARTSYS;
+       } else {
+               KASSERTMSG((error == 0), "error = %d", error);
+               return 0;
+       }
 }
 
 /*



Home | Main Index | Thread Index | Old Index