summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/sparc64/dev/tda.c17
-rw-r--r--sys/kern/kern_sensors.c41
-rw-r--r--sys/kern/kern_sysctl.c14
-rw-r--r--sys/sys/sensors.h8
4 files changed, 43 insertions, 37 deletions
diff --git a/sys/arch/sparc64/dev/tda.c b/sys/arch/sparc64/dev/tda.c
index 6de04c4eae2..f856b971f85 100644
--- a/sys/arch/sparc64/dev/tda.c
+++ b/sys/arch/sparc64/dev/tda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tda.c,v 1.4 2008/02/27 17:25:00 robert Exp $ */
+/* $OpenBSD: tda.c,v 1.5 2010/04/20 20:49:34 deraadt Exp $ */
/*
* Copyright (c) 2008 Robert Nagy <robert@openbsd.org>
@@ -99,6 +99,7 @@ tda_attach(struct device *parent, struct device *self, void *aux)
{
struct tda_softc *sc = (struct tda_softc *)self;
struct i2c_attach_args *ia = aux;
+ struct ksensordev *ksens;
int i;
sc->sc_tag = ia->ia_tag;
@@ -114,8 +115,8 @@ tda_attach(struct device *parent, struct device *self, void *aux)
tda_setspeed(sc);
/* Get the number of sensor devices. */
- for (i = 0; i < MAXSENSORDEVICES; i++) {
- if (sensordev_get(i) == NULL)
+ for (i = 0; ; i++) {
+ if (sensordev_get(i, &ksens) == ENOENT)
break;
}
sc->sc_nsensors = i;
@@ -184,23 +185,23 @@ tda_adjust(void *v)
struct tda_softc *sc = v;
struct ksensor *ks;
u_int64_t ctemp, stemp;
- int i;
+ int i, err;
/* Default to running the fans at maximum speed. */
sc->sc_cfan_speed = sc->sc_sfan_speed = TDA_FANSPEED_MAX;
ctemp = stemp = 0;
for (i = 0; i < sc->sc_nsensors; i++) {
- ks = sensor_find(i, SENSOR_TEMP, SENSOR_TEMP_EXT);
- if (ks == NULL) {
+ err = sensor_find(i, SENSOR_TEMP, SENSOR_TEMP_EXT, &ks);
+ if (err) {
printf("%s: failed to get external sensor\n",
DEVNAME(sc));
goto out;
}
ctemp = MAX(ctemp, ks->value);
- ks = sensor_find(i, SENSOR_TEMP, SENSOR_TEMP_INT);
- if (ks == NULL) {
+ err = sensor_find(i, SENSOR_TEMP, SENSOR_TEMP_INT, &ks);
+ if (err) {
printf("%s: failed to get internal sensors\n",
DEVNAME(sc));
goto out;
diff --git a/sys/kern/kern_sensors.c b/sys/kern/kern_sensors.c
index a1d0453bf94..224e3c3b2f4 100644
--- a/sys/kern/kern_sensors.c
+++ b/sys/kern/kern_sensors.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sensors.c,v 1.23 2009/08/03 07:08:33 blambert Exp $ */
+/* $OpenBSD: kern_sensors.c,v 1.24 2010/04/20 20:49:33 deraadt Exp $ */
/*
* Copyright (c) 2005 David Gwynne <dlg@openbsd.org>
@@ -32,7 +32,7 @@
#include <sys/sensors.h>
#include "hotplug.h"
-int sensordev_count = 0;
+int sensordev_count;
SLIST_HEAD(, ksensordev) sensordev_list =
SLIST_HEAD_INITIALIZER(sensordev_list);
@@ -131,35 +131,42 @@ sensor_detach(struct ksensordev *sensdev, struct ksensor *sens)
splx(s);
}
-struct ksensordev *
-sensordev_get(int num)
+int
+sensordev_get(int num, struct ksensordev **sensdev)
{
struct ksensordev *sd;
- SLIST_FOREACH(sd, &sensordev_list, list)
- if (sd->num == num)
- return (sd);
-
- return (NULL);
+ SLIST_FOREACH(sd, &sensordev_list, list) {
+ if (sd->num == num) {
+ *sensdev = sd;
+ return (0);
+ }
+ if (sd->num > num)
+ return (ENXIO);
+ }
+ return (ENOENT);
}
-struct ksensor *
-sensor_find(int dev, enum sensor_type type, int numt)
+int
+sensor_find(int dev, enum sensor_type type, int numt, struct ksensor **ksensorp)
{
struct ksensor *s;
struct ksensordev *sensdev;
struct ksensors_head *sh;
+ int ret;
- sensdev = sensordev_get(dev);
- if (sensdev == NULL)
- return (NULL);
+ ret = sensordev_get(dev, &sensdev);
+ if (ret)
+ return (ret);
sh = &sensdev->sensors_list;
SLIST_FOREACH(s, sh, list)
- if (s->type == type && s->numt == numt)
- return (s);
+ if (s->type == type && s->numt == numt) {
+ *ksensorp = s;
+ return (0);
+ }
- return (NULL);
+ return (ENOENT);
}
struct sensor_task {
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index a446a07e24d..35fe3238fad 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.181 2010/03/24 23:18:17 tedu Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.182 2010/04/20 20:49:33 deraadt Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -2008,9 +2008,9 @@ sysctl_sensors(int *name, u_int namelen, void *oldp, size_t *oldlenp,
dev = name[0];
if (namelen == 1) {
- ksd = sensordev_get(dev);
- if (ksd == NULL)
- return (ENOENT);
+ ret = sensordev_get(dev, &ksd);
+ if (ret)
+ return (ret);
/* Grab a copy, to clear the kernel pointers */
usd = malloc(sizeof(*usd), M_TEMP, M_WAITOK|M_ZERO);
@@ -2029,9 +2029,9 @@ sysctl_sensors(int *name, u_int namelen, void *oldp, size_t *oldlenp,
type = name[1];
numt = name[2];
- ks = sensor_find(dev, type, numt);
- if (ks == NULL)
- return (ENOENT);
+ ret = sensor_find(dev, type, numt, &ks);
+ if (ret)
+ return (ret);
/* Grab a copy, to clear the kernel pointers */
us = malloc(sizeof(*us), M_TEMP, M_WAITOK|M_ZERO);
diff --git a/sys/sys/sensors.h b/sys/sys/sensors.h
index 9f8aaed5ad8..b53e9771cff 100644
--- a/sys/sys/sensors.h
+++ b/sys/sys/sensors.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sensors.h,v 1.27 2010/04/20 19:44:07 oga Exp $ */
+/* $OpenBSD: sensors.h,v 1.28 2010/04/20 20:49:35 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org>
@@ -119,8 +119,6 @@ struct sensordev {
int sensors_count;
};
-#define MAXSENSORDEVICES 32
-
#ifdef _KERNEL
/* Sensor data */
@@ -149,12 +147,12 @@ struct ksensordev {
/* struct ksensordev */
void sensordev_install(struct ksensordev *);
void sensordev_deinstall(struct ksensordev *);
-struct ksensordev *sensordev_get(int);
+int sensordev_get(int, struct ksensordev **);
/* struct ksensor */
void sensor_attach(struct ksensordev *, struct ksensor *);
void sensor_detach(struct ksensordev *, struct ksensor *);
-struct ksensor *sensor_find(int, enum sensor_type, int);
+int sensor_find(int, enum sensor_type, int, struct ksensor **);
/* task scheduling */
struct sensor_task;