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).
This commit is contained in:
parent
e7043d3268
commit
c99562cb83
@ -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 @@ haltsys:
|
||||
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();
|
||||
|
@ -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 @@ haltsys:
|
||||
}
|
||||
#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
|
||||
|
@ -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 @@ acpi_probe(void)
|
||||
|
||||
once = 1;
|
||||
func = NULL;
|
||||
acpi_softc = NULL;
|
||||
initialized = false;
|
||||
|
||||
mutex_init(&acpi_interrupt_list_mtx, MUTEX_DEFAULT, IPL_NONE);
|
||||
@ -372,6 +373,11 @@ void
|
||||
acpi_disable(void)
|
||||
{
|
||||
|
||||
if (acpi_softc == NULL)
|
||||
return;
|
||||
|
||||
KASSERT(acpi_active != 0);
|
||||
|
||||
if (AcpiGbl_FADT.SmiCommand != 0)
|
||||
AcpiDisable();
|
||||
}
|
||||
@ -1354,14 +1360,21 @@ acpi_sleep_init(struct acpi_softc *sc)
|
||||
}
|
||||
|
||||
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 @@ sysctl_hw_acpi_sleepstate(SYSCTLFN_ARGS)
|
||||
if (t < ACPI_STATE_S0 || t > ACPI_STATE_S5)
|
||||
return EINVAL;
|
||||
|
||||
acpi_enter_sleep_state(sc, t);
|
||||
acpi_enter_sleep_state(t);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -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 capabilities = ACPI_APM_DEFAULT_CAP;
|
||||
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 @@ acpiapm_enable(void *opaque, int onoff)
|
||||
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 @@ acpiapm_set_powstate(void *opaque, u_int devid, u_int powstat)
|
||||
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:
|
||||
|
@ -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 @@ struct acpi_drq *acpi_res_drq(struct acpi_resources *, int);
|
||||
/*
|
||||
* Sleep state transition.
|
||||
*/
|
||||
void acpi_enter_sleep_state(struct acpi_softc *, int);
|
||||
void acpi_enter_sleep_state(int);
|
||||
|
||||
/*
|
||||
* MADT.
|
||||
|
Loading…
Reference in New Issue
Block a user