svn commit: r232430 - stable/9/sys/powerpc/powermac

Nathan Whitehorn nwhitehorn at FreeBSD.org
Sat Mar 3 02:16:45 UTC 2012


Author: nwhitehorn
Date: Sat Mar  3 02:16:45 2012
New Revision: 232430
URL: http://svn.freebsd.org/changeset/base/232430

Log:
  MFC r231770:
  Improve error handling in smusat(4).

Modified:
  stable/9/sys/powerpc/powermac/smusat.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/powerpc/powermac/smusat.c
==============================================================================
--- stable/9/sys/powerpc/powermac/smusat.c	Sat Mar  3 02:15:52 2012	(r232429)
+++ stable/9/sys/powerpc/powermac/smusat.c	Sat Mar  3 02:16:45 2012	(r232430)
@@ -202,33 +202,46 @@ static int
 smusat_updatecache(device_t dev)
 {
 	uint8_t reg = 0x3f;
+	uint8_t	value[16];
 	struct smusat_softc *sc = device_get_softc(dev);
+	int error;
 	struct iic_msg msgs[2] = {
 	    {0, IIC_M_WR | IIC_M_NOSTOP, 1, &reg},
-	    {0, IIC_M_RD, 16, sc->sc_cache},
+	    {0, IIC_M_RD, 16, value},
 	};
 
 	msgs[0].slave = msgs[1].slave = iicbus_get_addr(dev);
-	sc->sc_last_update = time_uptime;
+	error = iicbus_transfer(dev, msgs, 2);
+	if (error)
+		return (error);
 
-	return (iicbus_transfer(dev, msgs, 2));
+	sc->sc_last_update = time_uptime;
+	memcpy(sc->sc_cache, value, sizeof(value));
+	return (0);
 }
 
 static int
 smusat_sensor_read(struct smu_sensor *sens)
 {
-	int value;
+	int value, error;
 	device_t dev;
 	struct smusat_softc *sc;
 
 	dev = sens->dev;
 	sc = device_get_softc(dev);
+	error = 0;
 
 	if (time_uptime - sc->sc_last_update > 1)
-		smusat_updatecache(dev);
+		error = smusat_updatecache(dev);
+	if (error)
+		return (-error);
 
 	value = (sc->sc_cache[sens->reg*2] << 8) +
 	    sc->sc_cache[sens->reg*2 + 1];
+	if (value == 0xffff) {
+		sc->sc_last_update = 0; /* Result was bad, don't cache */
+		return (-EINVAL);
+	}
 
 	switch (sens->type) {
 	case SMU_TEMP_SENSOR:


More information about the svn-src-stable-9 mailing list