Module Name: src
Committed By: jruoho
Date: Sun Oct 24 07:53:05 UTC 2010
Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/i386/i386: machdep.c
src/sys/dev/acpi: acpi.c acpi_apm.c acpivar.h
Log Message:
Simplify acpi_enter_sleep_state() and guard it against NULL pointer
dereferences. Try to avoid referencing the global acpi_softc, which should
really be static or at least internal to acpi(4).
To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.695 -r1.696 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.221 -r1.222 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/acpi/acpi_apm.c
cvs rdiff -u -r1.63 -r1.64 src/sys/dev/acpi/acpivar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.153 src/sys/arch/amd64/amd64/machdep.c:1.154
--- src/sys/arch/amd64/amd64/machdep.c:1.153 Thu Oct 21 11:28:34 2010
+++ src/sys/arch/amd64/amd64/machdep.c Sun Oct 24 07:53:05 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.153 2010/10/21 11:28:34 yamt Exp $ */
+/* $NetBSD: machdep.c,v 1.154 2010/10/24 07:53:05 jruoho Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.153 2010/10/21 11:28:34 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.154 2010/10/24 07:53:05 jruoho Exp $");
/* #define XENDEBUG_LOW */
@@ -699,10 +699,7 @@
if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
#ifndef XEN
#if NACPICA > 0
- if (acpi_softc != NULL) {
- acpi_enter_sleep_state(acpi_softc, ACPI_STATE_S5);
- printf("WARNING: ACPI powerdown failed!\n");
- }
+ acpi_enter_sleep_state(ACPI_STATE_S5);
#endif
#else /* XEN */
HYPERVISOR_shutdown();
Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.695 src/sys/arch/i386/i386/machdep.c:1.696
--- src/sys/arch/i386/i386/machdep.c:1.695 Thu Oct 21 11:17:55 2010
+++ src/sys/arch/i386/i386/machdep.c Sun Oct 24 07:53:04 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.695 2010/10/21 11:17:55 yamt Exp $ */
+/* $NetBSD: machdep.c,v 1.696 2010/10/24 07:53:04 jruoho Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.695 2010/10/21 11:17:55 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.696 2010/10/24 07:53:04 jruoho Exp $");
#include "opt_beep.h"
#include "opt_compat_ibcs2.h"
@@ -923,10 +923,7 @@
}
#endif
#if NACPICA > 0
- if (acpi_softc != NULL) {
- acpi_enter_sleep_state(acpi_softc, ACPI_STATE_S5);
- printf("WARNING: ACPI powerdown failed!\n");
- }
+ acpi_enter_sleep_state(ACPI_STATE_S5);
#endif
#if NAPMBIOS > 0 && !defined(APM_NO_POWEROFF)
/* turn off, if we can. But try to turn disk off and
Index: src/sys/dev/acpi/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.221 src/sys/dev/acpi/acpi.c:1.222
--- src/sys/dev/acpi/acpi.c:1.221 Tue Oct 12 19:10:50 2010
+++ src/sys/dev/acpi/acpi.c Sun Oct 24 07:53:04 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi.c,v 1.221 2010/10/12 19:10:50 gsutre Exp $ */
+/* $NetBSD: acpi.c,v 1.222 2010/10/24 07:53:04 jruoho Exp $ */
/*-
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.221 2010/10/12 19:10:50 gsutre Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.222 2010/10/24 07:53:04 jruoho Exp $");
#include "opt_acpi.h"
#include "opt_pcifixup.h"
@@ -262,6 +262,7 @@
once = 1;
func = NULL;
+ acpi_softc = NULL;
initialized = false;
mutex_init(&acpi_interrupt_list_mtx, MUTEX_DEFAULT, IPL_NONE);
@@ -372,6 +373,11 @@
acpi_disable(void)
{
+ if (acpi_softc == NULL)
+ return;
+
+ KASSERT(acpi_active != 0);
+
if (AcpiGbl_FADT.SmiCommand != 0)
AcpiDisable();
}
@@ -1354,14 +1360,21 @@
}
void
-acpi_enter_sleep_state(struct acpi_softc *sc, int state)
+acpi_enter_sleep_state(int state)
{
+ struct acpi_softc *sc = acpi_softc;
ACPI_STATUS rv;
int err;
+ if (acpi_softc == NULL)
+ return;
+
if (state == sc->sc_sleepstate)
return;
+ if (state < ACPI_STATE_S0 || state > ACPI_STATE_S5)
+ return;
+
aprint_normal_dev(sc->sc_dev, "entering state S%d\n", state);
switch (state) {
@@ -1608,7 +1621,7 @@
if (t < ACPI_STATE_S0 || t > ACPI_STATE_S5)
return EINVAL;
- acpi_enter_sleep_state(sc, t);
+ acpi_enter_sleep_state(t);
return 0;
}
Index: src/sys/dev/acpi/acpi_apm.c
diff -u src/sys/dev/acpi/acpi_apm.c:1.19 src/sys/dev/acpi/acpi_apm.c:1.20
--- src/sys/dev/acpi/acpi_apm.c:1.19 Tue Apr 27 08:37:07 2010
+++ src/sys/dev/acpi/acpi_apm.c Sun Oct 24 07:53:04 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_apm.c,v 1.19 2010/04/27 08:37:07 jruoho Exp $ */
+/* $NetBSD: acpi_apm.c,v 1.20 2010/10/24 07:53:04 jruoho Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_apm.c,v 1.19 2010/04/27 08:37:07 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_apm.c,v 1.20 2010/10/24 07:53:04 jruoho Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -97,7 +97,7 @@
static int acpiapm_node = CTL_EOL, standby_node = CTL_EOL;
struct acpi_softc;
-extern void acpi_enter_sleep_state(struct acpi_softc *, int);
+extern void acpi_enter_sleep_state(int);
static int acpiapm_match(device_t, cfdata_t , void *);
static void acpiapm_attach(device_t, device_t, void *);
static int sysctl_state(SYSCTLFN_PROTO);
@@ -232,7 +232,6 @@
static int
acpiapm_set_powstate(void *opaque, u_int devid, u_int powstat)
{
- struct acpi_softc *sc = device_private((device_t)opaque);
if (devid != APM_DEV_ALLDEVS)
return APM_ERR_UNRECOG_DEV;
@@ -241,11 +240,11 @@
case APM_SYS_READY:
break;
case APM_SYS_STANDBY:
- acpi_enter_sleep_state(sc, get_state_value(standby_state));
+ acpi_enter_sleep_state(get_state_value(standby_state));
resumed = 1;
break;
case APM_SYS_SUSPEND:
- acpi_enter_sleep_state(sc, get_state_value(suspend_state));
+ acpi_enter_sleep_state(get_state_value(suspend_state));
resumed = 1;
break;
case APM_SYS_OFF:
Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.63 src/sys/dev/acpi/acpivar.h:1.64
--- src/sys/dev/acpi/acpivar.h:1.63 Fri Sep 24 07:48:59 2010
+++ src/sys/dev/acpi/acpivar.h Sun Oct 24 07:53:04 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: acpivar.h,v 1.63 2010/09/24 07:48:59 gsutre Exp $ */
+/* $NetBSD: acpivar.h,v 1.64 2010/10/24 07:53:04 jruoho Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -309,7 +309,7 @@
/*
* Sleep state transition.
*/
-void acpi_enter_sleep_state(struct acpi_softc *, int);
+void acpi_enter_sleep_state(int);
/*
* MADT.