Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Aug 2007 16:17:28 GMT
From:      Rui Paulo <rpaulo@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 124475 for review
Message-ID:  <200708011617.l71GHSRi040311@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=124475

Change 124475 by rpaulo@rpaulo_epsilon on 2007/08/01 16:16:56

	Some code refactoring:
	* asmc_attach(): call asmc_init() after initializing
	  sc_model. This is needed on the MacMini. (not tested).
	* asmc_attach(): replace the 'out' case label with labels
	  more meaningful.
	* asmc_init(): Don't try to initialize the SMS if we don't have
	  one. This is needed on the MacMini. (not tested).
	* asmc_init(): replace the 'out' case label with something
	  more meaningful.
	* asmc_temp_getvalue(): check for invalid temperatures.

Affected files ...

.. //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#28 edit

Differences ...

==== //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#28 (text+ko) ====

@@ -23,7 +23,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#27 $
+ * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#28 $
  *
  */
 
@@ -272,10 +272,9 @@
 
 	mtx_init(&sc->sc_mtx, "asmc", NULL, MTX_SPIN);
 
+	sc->sc_model = model;
 	asmc_init(dev);
 
-	sc->sc_model = model;
-
 	/*
 	 * dev.asmc.n.fan.* tree.
 	 */
@@ -345,7 +344,7 @@
 	}
 
 	if (model->smc_sms_x == NULL)
-		goto out;
+		goto nosms;
 
 	/*
 	 * dev.asmc.n.sms tree.
@@ -420,9 +419,8 @@
 	    ASMC_IRQ, ASMC_IRQ, 1, RF_ACTIVE);
 	if (sc->sc_res == NULL) {
 		device_printf(dev, "unable to allocate IRQ resource\n");
-		if (sc->sc_sms_tq)
-			taskqueue_free(sc->sc_sms_tq);
-		return (ENXIO);
+		ret = ENXIO;
+		goto err2;
 	}
 
 	ret = bus_setup_intr(dev, sc->sc_res, 
@@ -437,15 +435,21 @@
 
 	if (ret) {
 		device_printf(dev, "unable to setup SMS IRQ\n");
-		bus_release_resource(dev, SYS_RES_IRQ, sc->sc_rid, sc->sc_res);
-		if (sc->sc_sms_tq)
-			taskqueue_free(sc->sc_sms_tq);
-		return (ret);
+		goto err1;
 	}
 
 
-out:
+nosms:
 	return (0);
+
+err1:
+	bus_release_resource(dev, SYS_RES_IRQ, sc->sc_rid, sc->sc_res);
+err2:
+	mtx_destroy(&sc->sc_mtx);
+	if (sc->sc_sms_tq)
+		taskqueue_free(sc->sc_sms_tq);
+
+	return (ret);
 }
 
 static int
@@ -475,6 +479,9 @@
 	int i, error = 1;
 	uint8_t buf[4];
 
+	if (sc->sc_model->smc_sms_x == NULL)
+		goto nosms;
+
 	/*
 	 * We are ready to recieve interrupts from the SMS.
 	 */
@@ -518,7 +525,7 @@
 		if (asmc_key_read(dev, ASMC_KEY_SMS, buf, 2) == 0 && 
 		    (buf[0] != 0x00 || buf[1] != 0x00)) {
 			error = 0;
-			goto out;
+			goto nosms;
 		}
 	
 		buf[0] = ASMC_SMS_INIT1;
@@ -529,7 +536,7 @@
 
 
 	asmc_sms_calibrate(dev);
-out:
+nosms:
 	sc->sc_nfan = asmc_fan_count(dev);
 	if (sc->sc_nfan > ASMC_MAXFANS) {
 		device_printf(dev, "more than %d fans were detected. Please "
@@ -756,7 +763,10 @@
 {
 	uint8_t buf[2];
 
-	if (asmc_key_read(dev, key, buf, 2) < 0)
+	/*
+	 * Check for invalid temperatures.
+	 */
+	if ((asmc_key_read(dev, key, buf, 2) < 0) || buf[0] == 127)
 		return (-1);
 
 	return (buf[0]);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708011617.l71GHSRi040311>