Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c iic_acquire_bus may fail.



details:   https://anonhg.NetBSD.org/src/rev/210a58181eca
branches:  trunk
changeset: 1021725:210a58181eca
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Tue Jun 15 04:41:01 2021 +0000

description:
iic_acquire_bus may fail.

diffstat:

 sys/dev/i2c/adm1021.c |  14 ++++++++------
 sys/dev/i2c/dstemp.c  |  17 ++++++++++-------
 2 files changed, 18 insertions(+), 13 deletions(-)

diffs (88 lines):

diff -r e0292abef807 -r 210a58181eca sys/dev/i2c/adm1021.c
--- a/sys/dev/i2c/adm1021.c     Tue Jun 15 04:39:49 2021 +0000
+++ b/sys/dev/i2c/adm1021.c     Tue Jun 15 04:41:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: adm1021.c,v 1.27 2021/01/30 01:22:06 thorpej Exp $ */
+/*     $NetBSD: adm1021.c,v 1.28 2021/06/15 04:41:01 mlelstv Exp $ */
 /*     $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $        */
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.27 2021/01/30 01:22:06 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.28 2021/06/15 04:41:01 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -344,7 +344,11 @@
        sc->sc_prop = ia->ia_prop;
        prop_object_retain(sc->sc_prop);
 
-       iic_acquire_bus(sc->sc_tag, 0);
+       if (iic_acquire_bus(sc->sc_tag, 0)) {
+               aprint_error_dev(self, "cannot acquire iic bus\n");
+               return;
+       }
+
        cmd = ADM1021_CONFIG_READ;
        if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &data) != 0) {
                iic_release_bus(sc->sc_tag, 0);
@@ -466,10 +470,8 @@
        uint8_t cmd, xdata;
        int8_t sdata;
 
-       if (iic_acquire_bus(sc->sc_tag, 0)) {
-               edata->state = ENVSYS_SINVALID;
+       if (iic_acquire_bus(sc->sc_tag, 0) != 0)
                return;
-       }
 
        if (edata->sensor == ADMTEMP_INT)
                cmd = ADM1021_INT_TEMP;
diff -r e0292abef807 -r 210a58181eca sys/dev/i2c/dstemp.c
--- a/sys/dev/i2c/dstemp.c      Tue Jun 15 04:39:49 2021 +0000
+++ b/sys/dev/i2c/dstemp.c      Tue Jun 15 04:41:01 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dstemp.c,v 1.12 2021/03/01 04:39:45 rin Exp $ */
+/* $NetBSD: dstemp.c,v 1.13 2021/06/15 04:41:01 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2018 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.12 2021/03/01 04:39:45 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dstemp.c,v 1.13 2021/06/15 04:41:01 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -145,7 +145,8 @@
        int error;
        uint8_t cmd[2], data;
 
-       iic_acquire_bus(sc->sc_i2c, 0);
+       if (iic_acquire_bus(sc->sc_i2c, 0))
+               return;
        cmd[0] = DSTEMP_CONFIG;
        data = 0;
        error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP,
@@ -171,10 +172,12 @@
        int error;
 
                
-       iic_acquire_bus(sc->sc_i2c, 0);
-       error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP,
-           sc->sc_addr, &cmd, 1, &data, 2, 0);
-       iic_release_bus(sc->sc_i2c, 0);
+       error = iic_acquire_bus(sc->sc_i2c, 0);
+       if (error == 0) {
+               error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP,
+                   sc->sc_addr, &cmd, 1, &data, 2, 0);
+               iic_release_bus(sc->sc_i2c, 0);
+       }
 
        if (error) {
                edata->state = ENVSYS_SINVALID;



Home | Main Index | Thread Index | Old Index