Source-Changes-HG archive

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

[src/netbsd-9]: src/sys/dev/i2c Pull up following revision(s) (requested by m...



details:   https://anonhg.NetBSD.org/src/rev/bed63623f897
branches:  netbsd-9
changeset: 963990:bed63623f897
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Jul 10 10:33:38 2020 +0000

description:
Pull up following revision(s) (requested by msaitoh in ticket #992):

        sys/dev/i2c/sdtemp.c: revision 1.37
        sys/dev/i2c/sdtemp.c: revision 1.38
        sys/dev/i2c/sdtemp.c: revision 1.39

KNF. No functional change.

  Check the return value of iic_acquire_bus(). This function may fail.

  One of the case is driver's detaching phase on shutdown. mutex_tryenter()
might fail and return with EBUSY. To avoid calling iic_release_bus() without
taking lock, check the return value of iic_acquire_bus().

  If an error occurred in sme_refresh function, pass ENVSYS_SINVALID.
OK'd by pgoyette.

diffstat:

 sys/dev/i2c/sdtemp.c |  49 ++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 36 insertions(+), 13 deletions(-)

diffs (126 lines):

diff -r 4f37f812c4d7 -r bed63623f897 sys/dev/i2c/sdtemp.c
--- a/sys/dev/i2c/sdtemp.c      Fri Jul 10 10:25:11 2020 +0000
+++ b/sys/dev/i2c/sdtemp.c      Fri Jul 10 10:33:38 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: sdtemp.c,v 1.35 2019/02/28 16:56:35 khorben Exp $        */
+/*      $NetBSD: sdtemp.c,v 1.35.4.1 2020/07/10 10:33:38 martin Exp $        */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.35 2019/02/28 16:56:35 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.35.4.1 2020/07/10 10:33:38 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -214,8 +214,13 @@
        if ((ia->ia_addr & SDTEMP_ADDRMASK) != SDTEMP_ADDR)
                return 0;
 
-       /* Verify that we can read the manufacturer ID, Device ID and the capability */
-       iic_acquire_bus(sc.sc_tag, 0);
+       /*
+        * Verify that we can read the manufacturer ID, Device ID and the
+        * capability
+        */
+       error = iic_acquire_bus(sc.sc_tag, 0);
+       if (error)
+               return 0;
        error = sdtemp_read_16(&sc, SDTEMP_REG_MFG_ID,  &mfgid) |
                sdtemp_read_16(&sc, SDTEMP_REG_DEV_REV, &devid) |
                sdtemp_read_16(&sc, SDTEMP_REG_CAPABILITY, &cap);
@@ -234,8 +239,8 @@
        }
 
        /*
-        * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the alarm
-        * capability, too.
+        * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the
+        * alarm capability, too.
         */
        if ((cap & SDTEMP_CAP_HAS_ALARM) == 0)
                return 0;
@@ -255,7 +260,10 @@
        sc->sc_address = ia->ia_addr;
        sc->sc_dev = self;
 
-       iic_acquire_bus(sc->sc_tag, 0);
+       error = iic_acquire_bus(sc->sc_tag, 0);
+       if (error)
+               return;
+
        if ((error = sdtemp_read_16(sc, SDTEMP_REG_MFG_ID,  &mfgid)) != 0 ||
            (error = sdtemp_read_16(sc, SDTEMP_REG_DEV_REV, &devid)) != 0) {
                iic_release_bus(sc->sc_tag, 0);
@@ -428,7 +436,9 @@
        uint16_t lim;
 
        *props = 0;
-       iic_acquire_bus(sc->sc_tag, 0);
+       if (iic_acquire_bus(sc->sc_tag, 0) != 0)
+               return;
+
        if (sdtemp_read_16(sc, SDTEMP_REG_LOWER_LIM, &lim) == 0 && lim != 0) {
                limits->sel_warnmin = sdtemp_decode_temp(sc, lim);
                *props |= PROP_WARNMIN;
@@ -458,7 +468,9 @@
                limits = &sc->sc_deflims;
                props  = &sc->sc_defprops;
        }
-       iic_acquire_bus(sc->sc_tag, 0);
+       if (iic_acquire_bus(sc->sc_tag, 0) != 0)
+               return;
+
        if (*props & PROP_WARNMIN) {
                val = __UK2C(limits->sel_warnmin);
                (void)sdtemp_write_16(sc, SDTEMP_REG_LOWER_LIM,
@@ -570,7 +582,12 @@
        uint16_t val;
        int error;
 
-       iic_acquire_bus(sc->sc_tag, 0);
+       error = iic_acquire_bus(sc->sc_tag, 0);
+       if (error) {
+               edata->state = ENVSYS_SINVALID;
+               return;
+       }
+
        error = sdtemp_read_16(sc, SDTEMP_REG_AMBIENT_TEMP, &val);
        iic_release_bus(sc->sc_tag, 0);
 
@@ -598,7 +615,7 @@
 }
 
 /*
- * power management functions
+ * Power management functions
  *
  * We go into "shutdown" mode at suspend time, and return to normal
  * mode upon resume.  This reduces power consumption by disabling
@@ -612,7 +629,10 @@
        int error;
        uint16_t config;
 
-       iic_acquire_bus(sc->sc_tag, 0);
+       error = iic_acquire_bus(sc->sc_tag, 0);
+       if (error != 0)
+               return false;
+
        error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, &config);
        if (error == 0) {
                config |= SDTEMP_CONFIG_SHUTDOWN_MODE;
@@ -629,7 +649,10 @@
        int error;
        uint16_t config;
 
-       iic_acquire_bus(sc->sc_tag, 0);
+       error = iic_acquire_bus(sc->sc_tag, 0);
+       if (error != 0)
+               return false;
+
        error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, &config);
        if (error == 0) {
                config &= ~SDTEMP_CONFIG_SHUTDOWN_MODE;



Home | Main Index | Thread Index | Old Index