Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/sysmon simplify and don't deref NULL.
details: https://anonhg.NetBSD.org/src/rev/5bc8a4b8e1a4
branches: trunk
changeset: 766236:5bc8a4b8e1a4
user: christos <christos%NetBSD.org@localhost>
date: Sun Jun 19 04:23:18 2011 +0000
description:
simplify and don't deref NULL.
diffstat:
sys/dev/sysmon/sysmon_envsys_tables.c | 79 +++++++++++++++-------------------
1 files changed, 36 insertions(+), 43 deletions(-)
diffs (111 lines):
diff -r 14c13ae34a54 -r 5bc8a4b8e1a4 sys/dev/sysmon/sysmon_envsys_tables.c
--- a/sys/dev/sysmon/sysmon_envsys_tables.c Sun Jun 19 04:08:48 2011 +0000
+++ b/sys/dev/sysmon/sysmon_envsys_tables.c Sun Jun 19 04:23:18 2011 +0000
@@ -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 @@
{ -1, -1, "UNKNOWN" }
};
+static const struct sme_desc_entry *
+sme_find_table(enum sme_descr_type table_id)
+{
+ switch (table_id) {
+ case SME_DESC_UNITS:
+ return sme_units_description;
+ break;
+ case SME_DESC_STATES:
+ return sme_state_description;
+ break;
+ case SME_DESC_DRIVE_STATES:
+ return sme_drivestate_description;
+ break;
+ case SME_DESC_BATTERY_CAPACITY:
+ 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 = 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;
- }
+ if (table != NULL)
+ for (; table->type != -1; table++)
+ if (table->type == key)
+ return table;
- for (; table->type != -1; table++)
- if (table->type == key)
- break;
+ return NULL;
+}
- return table;
-}
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;
}
-
Home |
Main Index |
Thread Index |
Old Index