Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Check the return value of iic_acquire_bus(). Thi...



details:   https://anonhg.NetBSD.org/src/rev/68a69a31a60b
branches:  trunk
changeset: 935288:68a69a31a60b
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon Jun 29 09:24:07 2020 +0000

description:
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().

diffstat:

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

diffs (99 lines):

diff -r 37d4ebba02e1 -r 68a69a31a60b sys/dev/i2c/sdtemp.c
--- a/sys/dev/i2c/sdtemp.c      Mon Jun 29 08:54:58 2020 +0000
+++ b/sys/dev/i2c/sdtemp.c      Mon Jun 29 09:24:07 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $        */
+/*      $NetBSD: sdtemp.c,v 1.38 2020/06/29 09:24:07 msaitoh Exp $        */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.38 2020/06/29 09:24:07 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -218,7 +218,9 @@
         * Verify that we can read the manufacturer ID, Device ID and the
         * capability
         */
-       iic_acquire_bus(sc.sc_tag, 0);
+       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);
@@ -258,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);
@@ -426,7 +431,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;
@@ -456,7 +463,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,
@@ -568,7 +577,10 @@
        uint16_t val;
        int error;
 
-       iic_acquire_bus(sc->sc_tag, 0);
+       error = iic_acquire_bus(sc->sc_tag, 0);
+       if (error)
+               return;
+
        error = sdtemp_read_16(sc, SDTEMP_REG_AMBIENT_TEMP, &val);
        iic_release_bus(sc->sc_tag, 0);
 
@@ -610,7 +622,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;
@@ -627,7 +642,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