Module Name:    src
Committed By:   martin
Date:           Fri Jul 10 10:33:38 UTC 2020

Modified Files:
        src/sys/dev/i2c [netbsd-9]: sdtemp.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.35.4.1 src/sys/dev/i2c/sdtemp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/sdtemp.c
diff -u src/sys/dev/i2c/sdtemp.c:1.35 src/sys/dev/i2c/sdtemp.c:1.35.4.1
--- src/sys/dev/i2c/sdtemp.c:1.35	Thu Feb 28 16:56:35 2019
+++ src/sys/dev/i2c/sdtemp.c	Fri Jul 10 10:33:38 2020
@@ -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 @@ sdtemp_match(device_t parent, cfdata_t c
 	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 @@ sdtemp_match(device_t parent, cfdata_t c
 	}
 
 	/*
-	 * 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 @@ sdtemp_attach(device_t parent, device_t 
 	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 @@ sdtemp_get_limits(struct sysmon_envsys *
 	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 @@ sdtemp_set_limits(struct sysmon_envsys *
 		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 @@ sdtemp_refresh(struct sysmon_envsys *sme
 	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 @@ sdtemp_refresh(struct sysmon_envsys *sme
 }
 
 /*
- * 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 @@ sdtemp_pmf_suspend(device_t dev, const p
 	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 @@ sdtemp_pmf_resume(device_t dev, const pm
 	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;

Reply via email to