Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/dev/i2c Pull up the following revisions, requested by...



details:   https://anonhg.NetBSD.org/src/rev/fa831e92594e
branches:  netbsd-8
changeset: 936197:fa831e92594e
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Jul 20 19:00:40 2020 +0000

description:
Pull up the following revisions, requested by msaitoh in ticket #1580:

        sys/dev/i2c/sdtemp.c                    1.35, 1.37-1.39

- Check the return value of iic_acquire_bus() because this function
  may fail.
- Fix typo in comment.
- KNF.

diffstat:

 sys/dev/i2c/sdtemp.c |  51 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 37 insertions(+), 14 deletions(-)

diffs (135 lines):

diff -r 151c9d28766c -r fa831e92594e sys/dev/i2c/sdtemp.c
--- a/sys/dev/i2c/sdtemp.c      Mon Jul 20 18:55:14 2020 +0000
+++ b/sys/dev/i2c/sdtemp.c      Mon Jul 20 19:00:40 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: sdtemp.c,v 1.32.8.1 2018/03/08 14:29:12 martin Exp $        */
+/*      $NetBSD: sdtemp.c,v 1.32.8.2 2020/07/20 19:00:40 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.32.8.1 2018/03/08 14:29:12 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.32.8.2 2020/07/20 19:00:40 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);
@@ -297,7 +305,7 @@
         * IDT's devices and some Microchip's devices have the resolution
         * register in the vendor specific registers area. The devices'
         * resolution bits in the capability register are not the maximum
-        * resolution but the current vaule of the setting.
+        * resolution but the current value of the setting.
         */
        if (sdtemp_dev_table[i].sdtemp_config != NULL)
                sdtemp_dev_table[i].sdtemp_config(sc);
@@ -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