Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic avoid an infinite loop if reading data fails.



details:   https://anonhg.NetBSD.org/src/rev/7e735b643791
branches:  trunk
changeset: 1023098:7e735b643791
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Aug 23 23:55:43 2021 +0000

description:
avoid an infinite loop if reading data fails.

system hung hard on an "AMD E2-7110 APU with AMD Radeon R2 Graphics"
CPU, as the read fails continually and the loop continues.

diffstat:

 sys/dev/ic/amdccp.c |  10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diffs (38 lines):

diff -r ed52ddc89c3d -r 7e735b643791 sys/dev/ic/amdccp.c
--- a/sys/dev/ic/amdccp.c       Mon Aug 23 23:08:50 2021 +0000
+++ b/sys/dev/ic/amdccp.c       Mon Aug 23 23:55:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amdccp.c,v 1.2 2020/04/30 03:40:53 riastradh Exp $ */
+/* $NetBSD: amdccp.c,v 1.3 2021/08/23 23:55:43 mrg Exp $ */
 
 /*
  * Copyright (c) 2018 Jonathan A. Kollasch
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: amdccp.c,v 1.2 2020/04/30 03:40:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdccp.c,v 1.3 2021/08/23 23:55:43 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -77,13 +77,19 @@
        while (bytes_wanted) {
                const size_t nbytes = MIN(bytes_wanted, sizeof(buf));
                const size_t nwords = howmany(nbytes, sizeof(buf[0]));
+
                for (cnt = 0; cnt < nwords; cnt++) {
                        buf[cnt] = amdccp_rnd_read(sc);
                        if (buf[cnt] == 0) {
                                break;
                        }
                }
+               if (cnt == 0) {
+                       break;
+               }
+
                const size_t cntby = cnt * sizeof(buf[0]);
+
                rnd_add_data_sync(&sc->sc_rndsource, buf, cntby, cntby * NBBY);
                bytes_wanted -= MIN(bytes_wanted, cntby);
        }



Home | Main Index | Thread Index | Old Index