Module Name: src
Committed By: pgoyette
Date: Sat Apr 25 23:40:09 UTC 2015
Modified Files:
src/sys/dev/sysmon: sysmon.c sysmon_envsys.c sysmon_power.c
sysmon_wdog.c
Log Message:
Correctly check return status when registering with pmf
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/sysmon/sysmon.c
cvs rdiff -u -r1.136 -r1.137 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/sysmon/sysmon_power.c
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/sysmon/sysmon_wdog.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.c
diff -u src/sys/dev/sysmon/sysmon.c:1.23 src/sys/dev/sysmon/sysmon.c:1.24
--- src/sys/dev/sysmon/sysmon.c:1.23 Sat Apr 25 23:16:37 2015
+++ src/sys/dev/sysmon/sysmon.c Sat Apr 25 23:40:09 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon.c,v 1.23 2015/04/25 23:16:37 pgoyette Exp $ */
+/* $NetBSD: sysmon.c,v 1.24 2015/04/25 23:40:09 pgoyette Exp $ */
/*-
* Copyright (c) 2000 Zembu Labs, Inc.
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.23 2015/04/25 23:16:37 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.24 2015/04/25 23:40:09 pgoyette Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@@ -397,7 +397,7 @@ sysmon_init(void)
error = ENODEV;
}
- if (pmf_device_register(sysmon_dev, NULL, NULL))
+ if (!pmf_device_register(sysmon_dev, NULL, NULL))
aprint_error("%s: failed to register with pmf\n",
sysmon_cd.cd_name);
Index: src/sys/dev/sysmon/sysmon_envsys.c
diff -u src/sys/dev/sysmon/sysmon_envsys.c:1.136 src/sys/dev/sysmon/sysmon_envsys.c:1.137
--- src/sys/dev/sysmon/sysmon_envsys.c:1.136 Sat Apr 25 14:06:58 2015
+++ src/sys/dev/sysmon/sysmon_envsys.c Sat Apr 25 23:40:09 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys.c,v 1.136 2015/04/25 14:06:58 christos Exp $ */
+/* $NetBSD: sysmon_envsys.c,v 1.137 2015/04/25 23:40:09 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.136 2015/04/25 14:06:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.137 2015/04/25 23:40:09 pgoyette Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -78,6 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_envsy
#include <sys/kmem.h>
#include <sys/rndsource.h>
#include <sys/module.h>
+#include <sys/once.h>
#include <dev/sysmon/sysmonvar.h>
#include <dev/sysmon/sysmon_envsysvar.h>
@@ -109,18 +110,17 @@ static struct sysmon_opvec sysmon_envsys
NULL, NULL, NULL
};
-static void
+ONCE_DECL(once_envsys);
+
+static int
sme_preinit(void)
{
- static bool passed = false;
- if (passed)
- return;
-
- passed = true;
LIST_INIT(&sysmon_envsys_list);
mutex_init(&sme_global_mtx, MUTEX_DEFAULT, IPL_NONE);
sme_propd = prop_dictionary_create();
+
+ return 0;
}
/*
@@ -133,7 +133,7 @@ sysmon_envsys_init(void)
{
int error;
- sme_preinit();
+ (void)RUN_ONCE(&once_envsys, sme_preinit);
error = sysmon_attach_minor(SYSMON_MINOR_ENVSYS, &sysmon_envsys_opvec);
@@ -694,7 +694,7 @@ sysmon_envsys_register(struct sysmon_env
KASSERT(sme != NULL);
KASSERT(sme->sme_name != NULL);
- sme_preinit();
+ (void)RUN_ONCE(&once_envsys, sme_preinit);
/*
* Check if requested sysmon_envsys device is valid
Index: src/sys/dev/sysmon/sysmon_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.54 src/sys/dev/sysmon/sysmon_power.c:1.55
--- src/sys/dev/sysmon/sysmon_power.c:1.54 Thu Apr 23 23:22:03 2015
+++ src/sys/dev/sysmon/sysmon_power.c Sat Apr 25 23:40:09 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_power.c,v 1.54 2015/04/23 23:22:03 pgoyette Exp $ */
+/* $NetBSD: sysmon_power.c,v 1.55 2015/04/25 23:40:09 pgoyette Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.54 2015/04/23 23:22:03 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.55 2015/04/25 23:40:09 pgoyette Exp $");
#ifndef _LKM
#include "opt_compat_netbsd.h"
@@ -88,6 +88,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_power
#include <sys/device.h>
#include <sys/rndsource.h>
#include <sys/module.h>
+#include <sys/once.h>
#include <dev/sysmon/sysmonvar.h>
#include <prop/proplib.h>
@@ -199,6 +200,18 @@ static struct sysmon_opvec sysmon_power_
#define SYSMON_NEXT_EVENT(x) (((x) + 1) % SYSMON_MAX_POWER_EVENTS)
+ONCE_DECL(once_power);
+
+static int
+power_preinit(void)
+{
+
+ mutex_init(&sysmon_power_event_queue_mtx, MUTEX_DEFAULT, IPL_NONE);
+ cv_init(&sysmon_power_event_queue_cv, "smpower");
+
+ return 0;
+}
+
/*
* sysmon_power_init:
*
@@ -210,8 +223,8 @@ sysmon_power_init(void)
{
int error;
- mutex_init(&sysmon_power_event_queue_mtx, MUTEX_DEFAULT, IPL_NONE);
- cv_init(&sysmon_power_event_queue_cv, "smpower");
+ (void)RUN_ONCE(&once_power, power_preinit);
+
selinit(&sysmon_power_event_queue_selinfo);
rnd_attach_source(&sysmon_rndsource, "system-power",
@@ -938,7 +951,8 @@ sysmon_penvsys_event(struct penvsys_stat
int
sysmon_pswitch_register(struct sysmon_pswitch *smpsw)
{
- /* nada */
+ (void)RUN_ONCE(&once_power, power_preinit);
+
return 0;
}
Index: src/sys/dev/sysmon/sysmon_wdog.c
diff -u src/sys/dev/sysmon/sysmon_wdog.c:1.26 src/sys/dev/sysmon/sysmon_wdog.c:1.27
--- src/sys/dev/sysmon/sysmon_wdog.c:1.26 Thu Apr 23 23:22:03 2015
+++ src/sys/dev/sysmon/sysmon_wdog.c Sat Apr 25 23:40:09 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_wdog.c,v 1.26 2015/04/23 23:22:03 pgoyette Exp $ */
+/* $NetBSD: sysmon_wdog.c,v 1.27 2015/04/25 23:40:09 pgoyette Exp $ */
/*-
* Copyright (c) 2000 Zembu Labs, Inc.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_wdog.c,v 1.26 2015/04/23 23:22:03 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_wdog.c,v 1.27 2015/04/25 23:40:09 pgoyette Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_wdog.
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/module.h>
+#include <sys/once.h>
#include <dev/sysmon/sysmonvar.h>
@@ -82,14 +83,26 @@ static struct sysmon_opvec sysmon_wdog_o
MODULE(MODULE_CLASS_MISC, sysmon_wdog, "sysmon");
-int
-sysmon_wdog_init(void)
+ONCE_DECL(once_wdog);
+
+static int
+wdog_preinit(void)
{
- int error;
mutex_init(&sysmon_wdog_list_mtx, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&sysmon_wdog_mtx, MUTEX_DEFAULT, IPL_SOFTCLOCK);
cv_init(&sysmon_wdog_cv, "wdogref");
+
+ return 0;
+}
+
+int
+sysmon_wdog_init(void)
+{
+ int error;
+
+ (void)RUN_ONCE(&once_wdog, wdog_preinit);
+
sysmon_wdog_sdhook = shutdownhook_establish(sysmon_wdog_shutdown, NULL);
if (sysmon_wdog_sdhook == NULL)
printf("WARNING: unable to register watchdog shutdown hook\n");
@@ -312,6 +325,8 @@ sysmon_wdog_register(struct sysmon_wdog
struct sysmon_wdog *lsmw;
int error = 0;
+ (void)RUN_ONCE(&once_wdog, wdog_preinit);
+
mutex_enter(&sysmon_wdog_list_mtx);
LIST_FOREACH(lsmw, &sysmon_wdog_list, smw_list) {