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 can fail.



details:   https://anonhg.NetBSD.org/src/rev/41d50b9927a8
branches:  trunk
changeset: 983893:41d50b9927a8
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun Jun 13 09:46:04 2021 +0000

description:
iic_acquire_bus can fail.

diffstat:

 sys/dev/i2c/lm75.c |  28 +++++++++++++++++++---------
 sys/dev/i2c/lm87.c |   7 ++++---
 2 files changed, 23 insertions(+), 12 deletions(-)

diffs (119 lines):

diff -r b3fac6e78e59 -r 41d50b9927a8 sys/dev/i2c/lm75.c
--- a/sys/dev/i2c/lm75.c        Sun Jun 13 09:32:01 2021 +0000
+++ b/sys/dev/i2c/lm75.c        Sun Jun 13 09:46:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lm75.c,v 1.43 2021/05/21 20:42:05 macallan Exp $       */
+/*     $NetBSD: lm75.c,v 1.44 2021/06/13 09:46:04 mlelstv Exp $        */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.43 2021/05/21 20:42:05 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.44 2021/06/13 09:46:04 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -230,7 +230,11 @@
        sc->sc_lmtemp_decode = lmtemptbl[i].lmtemp_decode;
        sc->sc_lmtemp_encode = lmtemptbl[i].lmtemp_encode;
 
-       iic_acquire_bus(sc->sc_tag, 0);
+       if (iic_acquire_bus(sc->sc_tag, 0)) {
+               aprint_error_dev(self,
+                   "unable to acquire I2C bus\n");
+               return;
+       }
 
        /* Read temperature limit(s) and remember initial value(s). */
        if (i == lmtemp_lm77) {
@@ -378,7 +382,8 @@
 {
        struct lmtemp_softc *sc = sme->sme_cookie;
 
-       iic_acquire_bus(sc->sc_tag, 0); /* also locks our instance */
+       if (iic_acquire_bus(sc->sc_tag, 0))     /* also locks our instance */
+               return;
        lmtemp_refresh_sensor_data(sc);
        iic_release_bus(sc->sc_tag, 0); /* also unlocks our instance */
 }
@@ -392,7 +397,8 @@
 
        *props &= ~(PROP_CRITMAX);
 
-       iic_acquire_bus(sc->sc_tag, 0);
+       if (iic_acquire_bus(sc->sc_tag, 0))
+               return;
        if (lmtemp_temp_read(sc, LM75_REG_TOS_SET_POINT, &val, 0) == 0) {
                limits->sel_critmax = val;
                *props |= PROP_CRITMAX;
@@ -409,7 +415,8 @@
 
        *props &= ~(PROP_CRITMAX | PROP_WARNMAX | PROP_WARNMIN);
 
-       iic_acquire_bus(sc->sc_tag, 0);
+       if (iic_acquire_bus(sc->sc_tag, 0))
+               return;
        if (lmtemp_temp_read(sc, LM77_REG_TCRIT_SET_POINT, &val, 0) == 0) {
                limits->sel_critmax = val;
                *props |= PROP_CRITMAX;
@@ -437,7 +444,8 @@
                        limit = sc->sc_smax;
                else
                        limit = limits->sel_critmax;
-               iic_acquire_bus(sc->sc_tag, 0);
+               if (iic_acquire_bus(sc->sc_tag, 0))
+                       return;
                lmtemp_temp_write(sc, LM75_REG_THYST_SET_POINT,
                    limit - 5000000, 0);
                lmtemp_temp_write(sc, LM75_REG_TOS_SET_POINT, limit, 0);
@@ -608,7 +616,7 @@
 {
        struct sysctlnode node = *rnode;
        struct lmtemp_softc *sc = node.sysctl_data;
-       int temp;
+       int temp, error;
 
        if (newp) {
 
@@ -618,7 +626,9 @@
 
                        temp = *(int *)node.sysctl_data;
                        sc->sc_tmax = temp;
-                       iic_acquire_bus(sc->sc_tag, 0);
+                       error = iic_acquire_bus(sc->sc_tag, 0);
+                       if (error)
+                               return error;
                        lmtemp_temp_write(sc, LM75_REG_THYST_SET_POINT,
                            sc->sc_tmax - 5, 1);
                        lmtemp_temp_write(sc, LM75_REG_TOS_SET_POINT,
diff -r b3fac6e78e59 -r 41d50b9927a8 sys/dev/i2c/lm87.c
--- a/sys/dev/i2c/lm87.c        Sun Jun 13 09:32:01 2021 +0000
+++ b/sys/dev/i2c/lm87.c        Sun Jun 13 09:46:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lm87.c,v 1.14 2021/01/27 02:29:48 thorpej Exp $        */
+/*     $NetBSD: lm87.c,v 1.15 2021/06/13 09:46:04 mlelstv Exp $        */
 /*     $OpenBSD: lm87.c,v 1.20 2008/11/10 05:19:48 cnst Exp $  */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.14 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lm87.c,v 1.15 2021/06/13 09:46:04 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -162,7 +162,8 @@
                return 0;
 
        cmd = LM87_COMPANY_ID;
-       iic_acquire_bus(ia->ia_tag, 0);
+       if (iic_acquire_bus(ia->ia_tag, 0))
+               return 0;
        error = iic_exec(ia->ia_tag, I2C_OP_READ_WITH_STOP, ia->ia_addr,
            &cmd, 1, &val, 1, 0);
        iic_release_bus(ia->ia_tag, 0);



Home | Main Index | Thread Index | Old Index