DRY - Use a helper function to check and log failures.
This commit is contained in:
parent
0842eba04e
commit
c5baf46055
@ -44,12 +44,22 @@ extern dpc_module_info* gDPC;
|
||||
void* gDPCHandle = NULL;
|
||||
|
||||
|
||||
static bool
|
||||
checkAndLogFailure(const ACPI_STATUS status, const char* msg)
|
||||
{
|
||||
bool failure = ACPI_FAILURE(status);
|
||||
if (failure)
|
||||
dprintf("acpi: %s %s\n", msg, AcpiFormatException(status));
|
||||
|
||||
return failure;
|
||||
}
|
||||
|
||||
|
||||
static ACPI_STATUS
|
||||
get_device_by_hid_callback(ACPI_HANDLE object, UINT32 depth, void* context,
|
||||
void** _returnValue)
|
||||
{
|
||||
uint32* counter = (uint32*)context;
|
||||
ACPI_STATUS status;
|
||||
ACPI_BUFFER buffer;
|
||||
|
||||
TRACE("get_device_by_hid_callback %p, %d, %p\n", object, depth, context);
|
||||
@ -60,8 +70,8 @@ get_device_by_hid_callback(ACPI_HANDLE object, UINT32 depth, void* context,
|
||||
buffer.Length = 254;
|
||||
buffer.Pointer = malloc(255);
|
||||
|
||||
status = AcpiGetName(object, ACPI_FULL_PATHNAME, &buffer);
|
||||
if (status != AE_OK) {
|
||||
if (checkAndLogFailure(AcpiGetName(object, ACPI_FULL_PATHNAME, &buffer),
|
||||
"Failed to find device")) {
|
||||
free(buffer.Pointer);
|
||||
return AE_CTRL_TERMINATE;
|
||||
}
|
||||
@ -85,7 +95,6 @@ acpi_std_ops(int32 op,...)
|
||||
switch (op) {
|
||||
case B_MODULE_INIT:
|
||||
{
|
||||
ACPI_STATUS status;
|
||||
ACPI_OBJECT arg;
|
||||
ACPI_OBJECT_LIST parameter;
|
||||
void *settings;
|
||||
@ -125,51 +134,36 @@ acpi_std_ops(int32 op,...)
|
||||
AcpiDbgLayer = ACPI_ALL_COMPONENTS;
|
||||
#endif
|
||||
|
||||
status = AcpiInitializeSubsystem();
|
||||
if (ACPI_FAILURE(status)) {
|
||||
ERROR("AcpiInitializeSubsystem failed (%s)\n",
|
||||
AcpiFormatException(status));
|
||||
if (checkAndLogFailure(AcpiInitializeSubsystem(),
|
||||
"AcpiInitializeSubsystem failed"))
|
||||
goto err;
|
||||
}
|
||||
|
||||
status = AcpiInitializeTables(NULL, 0, TRUE);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
ERROR("AcpiInitializeTables failed (%s)\n",
|
||||
AcpiFormatException(status));
|
||||
if (checkAndLogFailure(AcpiInitializeTables(NULL, 0, TRUE),
|
||||
"AcpiInitializeTables failed"))
|
||||
goto err;
|
||||
}
|
||||
|
||||
status = AcpiLoadTables();
|
||||
if (ACPI_FAILURE(status)) {
|
||||
ERROR("AcpiLoadTables failed (%s)\n",
|
||||
AcpiFormatException(status));
|
||||
if (checkAndLogFailure(AcpiLoadTables(),
|
||||
"AcpiLoadTables failed"))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Install the default address space handlers. */
|
||||
status = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
||||
ACPI_ADR_SPACE_SYSTEM_MEMORY, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
ERROR("Could not initialise SystemMemory handler: %s\n",
|
||||
AcpiFormatException(status));
|
||||
if (checkAndLogFailure(AcpiInstallAddressSpaceHandler(
|
||||
ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_SYSTEM_MEMORY,
|
||||
ACPI_DEFAULT_HANDLER, NULL, NULL),
|
||||
"Could not initialise SystemMemory handler:"))
|
||||
goto err;
|
||||
}
|
||||
|
||||
status = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
||||
ACPI_ADR_SPACE_SYSTEM_IO, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
ERROR("Could not initialise SystemIO handler: %s\n",
|
||||
AcpiFormatException(status));
|
||||
if (checkAndLogFailure(AcpiInstallAddressSpaceHandler(
|
||||
ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_SYSTEM_IO,
|
||||
ACPI_DEFAULT_HANDLER, NULL, NULL),
|
||||
"Could not initialise SystemIO handler:"))
|
||||
goto err;
|
||||
}
|
||||
|
||||
status = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
||||
ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
ERROR("Could not initialise PciConfig handler: %s\n",
|
||||
AcpiFormatException(status));
|
||||
if (checkAndLogFailure(AcpiInstallAddressSpaceHandler(
|
||||
ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_PCI_CONFIG,
|
||||
ACPI_DEFAULT_HANDLER, NULL, NULL),
|
||||
"Could not initialise PciConfig handler:"))
|
||||
goto err;
|
||||
}
|
||||
|
||||
arg.Integer.Type = ACPI_TYPE_INTEGER;
|
||||
arg.Integer.Value = 0;
|
||||
@ -179,22 +173,15 @@ acpi_std_ops(int32 op,...)
|
||||
|
||||
AcpiEvaluateObject(NULL, "\\_PIC", ¶meter, NULL);
|
||||
|
||||
// FreeBSD seems to pass in the above flags here as
|
||||
// well but specs don't define ACPI_NO_DEVICE_INIT
|
||||
// and ACPI_NO_OBJECT_INIT here.
|
||||
status = AcpiEnableSubsystem(ACPI_FULL_INITIALIZATION);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
ERROR("AcpiEnableSubsystem failed (%s)\n",
|
||||
AcpiFormatException(status));
|
||||
if (checkAndLogFailure(AcpiEnableSubsystem(
|
||||
ACPI_FULL_INITIALIZATION),
|
||||
"AcpiEnableSubsystem failed"))
|
||||
goto err;
|
||||
}
|
||||
|
||||
status = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
ERROR("AcpiInitializeObjects failed (%s)\n",
|
||||
AcpiFormatException(status));
|
||||
if (checkAndLogFailure(AcpiInitializeObjects(
|
||||
ACPI_FULL_INITIALIZATION),
|
||||
"AcpiInitializeObjects failed"))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Phew. Now in ACPI mode */
|
||||
TRACE("ACPI initialized\n");
|
||||
@ -206,8 +193,8 @@ acpi_std_ops(int32 op,...)
|
||||
|
||||
case B_MODULE_UNINIT:
|
||||
{
|
||||
if (AcpiTerminate() != AE_OK)
|
||||
ERROR("Could not bring system out of ACPI mode. Oh well.\n");
|
||||
if (checkAndLogFailure(AcpiTerminate(),
|
||||
"Could not bring system out of ACPI mode. Oh well."));
|
||||
|
||||
gDPC->delete_dpc_queue(gDPCHandle);
|
||||
gDPCHandle = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user