Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Fix some regressions that were introduced.



details:   https://anonhg.NetBSD.org/src/rev/3f4f15ff65d9
branches:  trunk
changeset: 1026254:3f4f15ff65d9
user:      brad <brad%NetBSD.org@localhost>
date:      Sun Nov 14 18:36:13 2021 +0000

description:
Fix some regressions that were introduced.

One must make sure that you release the i2c bus if you acquire.

One must not try to release the i2c bus if you failed to acquire it.

One can't leave too early from the single-shot refresh without
checking the status register as there may have been a reset
and releasing the i2c bus.

diffstat:

 sys/dev/i2c/sht3x.c |  30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diffs (95 lines):

diff -r b29b2c29f520 -r 3f4f15ff65d9 sys/dev/i2c/sht3x.c
--- a/sys/dev/i2c/sht3x.c       Sun Nov 14 16:56:32 2021 +0000
+++ b/sys/dev/i2c/sht3x.c       Sun Nov 14 18:36:13 2021 +0000
@@ -1,4 +1,5 @@
-/*     $NetBSD: sht3x.c,v 1.3 2021/11/13 13:36:42 christos Exp $       */
+
+/*     $NetBSD: sht3x.c,v 1.4 2021/11/14 18:36:13 brad Exp $   */
 
 /*
  * Copyright (c) 2021 Brad Spencer <brad%anduin.eldar.org@localhost>
@@ -17,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sht3x.c,v 1.3 2021/11/13 13:36:42 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sht3x.c,v 1.4 2021/11/14 18:36:13 brad Exp $");
 
 /*
   Driver for the Sensirion SHT30/SHT31/SHT35
@@ -487,7 +488,7 @@
        if (error) {
                DPRINTF(sc, 2, ("%s: Could not acquire iic bus for initing: "
                    " %d\n", device_xname(sc->sc_dev), error));
-               goto out;
+               goto outm;
        }
 
        error = sht3x_take_break(sc, true);
@@ -510,6 +511,7 @@
 
 out:
        iic_release_bus(sc->sc_tag, 0);
+outm:
        mutex_exit(&sc->sc_mutex);
        return error;
 }
@@ -605,7 +607,9 @@
            "%x%x - %x -- %d\n", device_xname(sc->sc_dev), rawbuf[0], rawbuf[1],
            rawbuf[2], rawbuf[3], rawbuf[4], rawbuf[5], error));
        iic_release_bus(sc->sc_tag, 0);
-       memcpy(sc->sc_pbuffer, "dedbef", sizeof(sc->sc_pbuffer));
+       if (error != 0) {
+               memcpy(sc->sc_pbuffer, "dedbef", sizeof(sc->sc_pbuffer));
+       }
        mutex_exit(&sc->sc_mutex);
 }
 
@@ -1427,14 +1431,11 @@
 
        measurement_command_ss = sht3x_compute_measure_command_ss(
            sc->sc_repeatability);
-       DPRINTF(sc, 2, ("%s: Measurement command: %04x\n",
-           device_xname(sc->sc_dev), measurement_command_ss));
        error = sht3x_cmdr(sc, measurement_command_ss, rawdata, sizeof(rawdata));
+       DPRINTF(sc, 2, ("%s: Status for single-shot measurement cmd %04x "
+           "Error %d\n", device_xname(sc->sc_dev), measurement_command_ss, error));
        if (error == 0) {
-               DPRINTF(sc, 2, ("%s: Failed to get new status in refresh for "
-                   "single-shot %d\n", device_xname(sc->sc_dev), error));
-               if ((error = sht3x_parse_data(sc, edata, rawdata)) == 0)
-                       return 0;
+               error = sht3x_parse_data(sc, edata, rawdata);
        }
 
        uint16_t sbuf;
@@ -1455,7 +1456,8 @@
        }
 
        iic_release_bus(sc->sc_tag, 0);
-       return 0;
+
+       return error;
 }
 
 static void
@@ -1875,7 +1877,7 @@
                rawlimitslow = (rawlimitslow & 0x1FF) | limitlow;
                DPRINTF(sc, 2, ("%s: RH new raw limits high/low "
                    "%04x %04x from %x %x\n",
-                   device_xname(sc->sc_dev), rawlimitshigh, rawlimitslow, 
+                   device_xname(sc->sc_dev), rawlimitshigh, rawlimitslow,
                    limithigh, limitlow));
                sht3x_set_alert_limits(sc, rawlimitshigh, rawlimitslow, true);
                break;
@@ -2036,6 +2038,10 @@
                mutex_exit(&sc->sc_read_mutex);
                DPRINTF(sc, 2, ("%s: Will wait for anything to exit\n",
                    device_xname(sc->sc_dev)));
+               /* In the worst case this will time out after 5 seconds.
+                * It really should not take that long for the drain / whatever
+                * to happen
+                */
                cv_timedwait_sig(&sc->sc_cond_dying,
                    &sc->sc_dying_mutex, mstohz(5000));
                mutex_exit(&sc->sc_dying_mutex);



Home | Main Index | Thread Index | Old Index