diff options
| author | christos <christos@NetBSD.org> | 2011-06-19 04:23:18 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2011-06-19 04:23:18 +0000 |
| commit | c8ffcea3c95cf1ac0dae5aee8a7469ed0a91239f (patch) | |
| tree | 2c4c15e5ac7244c488c1cd53cb2de87d621be18b /sys/dev | |
| parent | 6aadb3f34cfa1eb0c5a56521d25b11f020714310 (diff) | |
simplify and don't deref NULL.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/sysmon/sysmon_envsys_tables.c | 69 |
1 files changed, 31 insertions, 38 deletions
diff --git a/sys/dev/sysmon/sysmon_envsys_tables.c b/sys/dev/sysmon/sysmon_envsys_tables.c index ed4d823e4d8..ca18811c3f1 100644 --- a/sys/dev/sysmon/sysmon_envsys_tables.c +++ b/sys/dev/sysmon/sysmon_envsys_tables.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysmon_envsys_tables.c,v 1.7 2011/06/19 03:09:43 pgoyette Exp $ */ +/* $NetBSD: sysmon_envsys_tables.c,v 1.8 2011/06/19 04:23:18 christos Exp $ */ /*- * Copyright (c) 2007 Juan Romero Pardines. @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.7 2011/06/19 03:09:43 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.8 2011/06/19 04:23:18 christos Exp $"); #include <sys/types.h> @@ -100,58 +100,51 @@ static const struct sme_descr_entry sme_batterycap_description[] = { { -1, -1, "UNKNOWN" } }; -/* - * Returns the entry from specified table with type == key - */ -const struct sme_descr_entry * -sme_find_table_entry(enum sme_descr_type table_id, int key) +static const struct sme_desc_entry * +sme_find_table(enum sme_descr_type table_id) { - const struct sme_descr_entry *table = NULL; - switch (table_id) { case SME_DESC_UNITS: - table = sme_units_description; + return sme_units_description; break; case SME_DESC_STATES: - table = sme_state_description; + return sme_state_description; break; case SME_DESC_DRIVE_STATES: - table = sme_drivestate_description; + return sme_drivestate_description; break; case SME_DESC_BATTERY_CAPACITY: - table = sme_batterycap_description; + return sme_batterycap_description; break; + default: + return NULL; } +} + +/* + * Returns the entry from specified table with type == key + */ +const struct sme_descr_entry * +sme_find_table_entry(enum sme_descr_type table_id, int key) +{ + const struct sme_descr_entry *table = sme_find_table(); - for (; table->type != -1; table++) - if (table->type == key) - break; + if (table != NULL) + for (; table->type != -1; table++) + if (table->type == key) + return table; - return table; + return NULL; } + const struct sme_descr_entry * sme_find_table_desc(enum sme_descr_type table_id, const char *str) { - const struct sme_descr_entry *table = NULL; + const struct sme_descr_entry *table = sme_find_table(); - switch (table_id) { - case SME_DESC_UNITS: - table = sme_units_description; - break; - case SME_DESC_STATES: - table = sme_state_description; - break; - case SME_DESC_DRIVE_STATES: - table = sme_drivestate_description; - break; - case SME_DESC_BATTERY_CAPACITY: - table = sme_batterycap_description; - break; - } - - for (; table->type != -1; table++) - if (strcmp(table->desc, str) == 0) - break; - return table; + if (table != NULL) + for (; table->type != -1; table++) + if (strcmp(table->desc, str) == 0) + return table; + return NULL; } - |
