Module Name: src Committed By: pgoyette Date: Thu Feb 18 12:30:53 UTC 2010
Modified Files: src/sys/dev/sysmon: sysmon_envsys_events.c Log Message: If we're going to valdate things, at least do it correctly. To generate a diff of this commit: cvs rdiff -u -r1.84 -r1.85 src/sys/dev/sysmon/sysmon_envsys_events.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/sysmon/sysmon_envsys_events.c diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.84 src/sys/dev/sysmon/sysmon_envsys_events.c:1.85 --- src/sys/dev/sysmon/sysmon_envsys_events.c:1.84 Mon Feb 15 22:32:04 2010 +++ src/sys/dev/sysmon/sysmon_envsys_events.c Thu Feb 18 12:30:53 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: sysmon_envsys_events.c,v 1.84 2010/02/15 22:32:04 pgoyette Exp $ */ +/* $NetBSD: sysmon_envsys_events.c,v 1.85 2010/02/18 12:30:53 pgoyette Exp $ */ /*- * Copyright (c) 2007, 2008 Juan Romero Pardines. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.84 2010/02/15 22:32:04 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.85 2010/02/18 12:30:53 pgoyette Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -101,21 +101,32 @@ /* * Some validation first for limit-checking events * - * Capacity limits are permitted only if the sensor has the - * ENVSYS_FPERCENT flag set. - * Value limits are permitted only if the ENVSYS_FPERCENT - * flag is not set and the units is not ENVSYS_INDICATOR. + * 1. Limits are not permitted if the units is ENVSYS_INDICATOR. + * + * 2. Capacity limits are permitted only if the sensor has the + * ENVSYS_FPERCENT flag set and value_max is set. + * + * 3. It is not permissible for both capacity and value limits + * to coexist. + * + * Note that it permissible for a sensor to have value limits + * even if its ENVSYS_FPERCENT flag and value_max are set. */ DPRINTF(("%s: units %d props 0x%04x edata-flags 0x%04x\n", __func__, edata->units, props, edata->flags)); - if ((props & PROP_VAL_LIMITS) && - ((edata->flags & ENVSYS_FPERCENT) || - (edata->units == ENVSYS_INDICATOR))) + if (props && edata->units == ENVSYS_INDICATOR) return ENOTSUP; + if ((props & PROP_CAP_LIMITS) && - !(edata->flags & ENVSYS_FPERCENT)) + ((edata->value_max == 0) || + !(edata->flags & ENVSYS_FPERCENT) || + (props & PROP_VAL_LIMITS) || + (edata->upropset & PROP_VAL_LIMITS))) + return ENOTSUP; + + if ((props & PROP_VAL_LIMITS) && (edata->upropset & PROP_CAP_LIMITS)) return ENOTSUP; /*