From nobody@FreeBSD.org  Fri May  9 03:29:03 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id BDC2C1065733
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 May 2008 03:29:00 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 3E3E28FC18
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 May 2008 03:29:00 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m493S2Fq079016
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 9 May 2008 03:28:02 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m493S2Xn079015;
	Fri, 9 May 2008 03:28:02 GMT
	(envelope-from nobody)
Message-Id: <200805090328.m493S2Xn079015@www.freebsd.org>
Date: Fri, 9 May 2008 03:28:02 GMT
From: KOIE Hidetaka <hide@koie.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: dev.cpu.0.temperature: -49 using k8temp
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         123542
>Category:       kern
>Synopsis:       [k8temp] [patch] dev.cpu.0.temperature: -49 using k8temp
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    rpaulo
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 09 03:30:00 UTC 2008
>Closed-Date:    Sun May 11 23:15:19 UTC 2008
>Last-Modified:  Wed May 14 10:00:11 UTC 2008
>Originator:     KOIE Hidetaka
>Release:        FreeBSD 8.0-CURRENT amd64
>Organization:
surigiken
>Environment:
reeBSD guriandgura 8.0-CURRENT FreeBSD 8.0-CURRENT #1: Thu May  8 20:42:22 JST 2008     root@guriandgura:/usr/obj/usr/src/sys/GURIANDGURA  amd64
>Description:
sysctl dev.cpu.0.temperature returns -49.
-49 is K8TEMP_MINTEMP.
>How-To-Repeat:
guriandgura# sysctl dev.cpu.0.temperature
dev.cpu.0.temperature: -49

>Fix:
k8temp_sysctl() uses max(uint) that is defined:
static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
But, the arguments are int32_t, so -49 is interpreted 4294967247.
Use imax() instead of max().
#In k8temp, we assume sizeof (int32_t) == sizeof (int).


Patch attached with submission follows:

Index: k8temp.c
===================================================================
RCS file: /museum/freebsd/repo/usr/src/sys/dev/k8temp/k8temp.c,v
retrieving revision 1.2
diff -u -p -r1.2 k8temp.c
--- k8temp.c	21 Apr 2008 22:00:01 -0000	1.2
+++ k8temp.c	9 May 2008 03:21:55 -0000
@@ -226,13 +226,13 @@ k8temp_attach(device_t dev)
 	SYSCTL_ADD_PROC(sysctlctx,
 	    SYSCTL_CHILDREN(sysctlnode),
 	    OID_AUTO, "core0", CTLTYPE_INT | CTLFLAG_RD,
-	    dev, SENSOR0_CORE0, k8temp_sysctl, "I",
+	    dev, SENSOR1_CORE0, k8temp_sysctl, "I",
 	    "Sensor 1 / Core 0 temperature");
 	
 	SYSCTL_ADD_PROC(sysctlctx,
 	    SYSCTL_CHILDREN(sysctlnode),
 	    OID_AUTO, "core1", CTLTYPE_INT | CTLFLAG_RD,
-	    dev, SENSOR0_CORE0, k8temp_sysctl, "I",
+	    dev, SENSOR1_CORE1, k8temp_sysctl, "I",
 	    "Sensor 1 / Core 1 temperature");
 
 	return (0);
@@ -265,12 +265,12 @@ k8temp_sysctl(SYSCTL_HANDLER_ARGS)
 	case CORE0:
 		auxtemp[0] = k8temp_gettemp(dev, SENSOR0_CORE0);
 		auxtemp[1] = k8temp_gettemp(dev, SENSOR1_CORE0);
-		temp = max(auxtemp[0], auxtemp[1]);
+		temp = imax(auxtemp[0], auxtemp[1]);
 		break;
 	case CORE1:
 		auxtemp[0] = k8temp_gettemp(dev, SENSOR0_CORE1);
 		auxtemp[1] = k8temp_gettemp(dev, SENSOR1_CORE1);
-		temp = max(auxtemp[0], auxtemp[1]);
+		temp = imax(auxtemp[0], auxtemp[1]);
 		break;
 	default:
 		temp = k8temp_gettemp(dev, arg2);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->rpaulo 
Responsible-Changed-By: matteo 
Responsible-Changed-When: Dom 11 Mag 2008 16:42:44 UTC 
Responsible-Changed-Why:  
Rui is k8temp's author and can probably handle this issue. Rui, thank you in advance 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123542 
State-Changed-From-To: open->closed 
State-Changed-By: rpaulo 
State-Changed-When: Sun May 11 23:14:49 UTC 2008 
State-Changed-Why:  
I committed a fix similar to yours. Thanks a lot for finding the 
problem! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123542 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/123542: commit references a PR
Date: Sun, 11 May 2008 23:14:13 +0000 (UTC)

 rpaulo      2008-05-11 23:14:07 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/dev/k8temp       k8temp.c 
   Log:
   Don't use libkern's max() function as that's for unsigned numbers only.
   Instead use the worldwide known MAX() function.
   This should fix problems with negative values showing up on
   dev.cpu.%d.temperature.
   This is slightly different from the fix in the PR.
   
   Submitted by:   KOIE Hidetaka <hide at koie.org>
   PR:             123542
   
   Revision  Changes    Path
   1.3       +2 -2      src/sys/dev/k8temp/k8temp.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/123542: commit references a PR
Date: Wed, 14 May 2008 09:57:27 +0000 (UTC)

 rpaulo      2008-05-14 09:57:21 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/dev/k8temp       k8temp.c 
   Log:
   Actually, don't rely on the unsafe MAX() macro. Use imax() as provided
   in the PR patch.
   
   Pointed out by:         bde
   PR:                     123542
   
   Revision  Changes    Path
   1.4       +2 -2      src/sys/dev/k8temp/k8temp.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
