Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 May 2008 03:28:02 GMT
From:      KOIE Hidetaka <hide@koie.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/123542: dev.cpu.0.temperature: -49 using k8temp
Message-ID:  <200805090328.m493S2Xn079015@www.freebsd.org>
Resent-Message-ID: <200805090330.m493U0Ic096396@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         123542
>Category:       kern
>Synopsis:       dev.cpu.0.temperature: -49 using k8temp
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 09 03:30:00 UTC 2008
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



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