Commit 3aa3e7d9 authored by Andy Grover's avatar Andy Grover

Removed no longer needed acpi_evaluate (a wrapper function)

Use acpi_os_free instead of kfree directly
Fix possible memory leaks
Fix possible divide by 0 (Dominik Brodowski)
parent 329158f8
/*
* acpi_bus.h - ACPI Bus Driver ($Revision: 21 $)
* acpi_bus.h - ACPI Bus Driver ($Revision: 22 $)
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
......@@ -46,7 +46,6 @@ struct acpi_handle_list {
/* acpi_utils.h */
acpi_status acpi_extract_package (acpi_object *, acpi_buffer *, acpi_buffer *);
acpi_status acpi_evaluate (acpi_handle, acpi_string, acpi_object_list *, acpi_buffer *);
acpi_status acpi_evaluate_integer (acpi_handle, acpi_string, acpi_object_list *, unsigned long *);
acpi_status acpi_evaluate_reference (acpi_handle, acpi_string, acpi_object_list *, struct acpi_handle_list *);
......
/*
* acpi_ksyms.c - ACPI Kernel Symbols ($Revision: 15 $)
* acpi_ksyms.c - ACPI Kernel Symbols ($Revision: 16 $)
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
......@@ -102,7 +102,6 @@ EXPORT_SYMBOL(acpi_os_wait_semaphore);
/* ACPI Utilities (acpi_utils.c) */
EXPORT_SYMBOL(acpi_extract_package);
EXPORT_SYMBOL(acpi_evaluate);
EXPORT_SYMBOL(acpi_evaluate_integer);
EXPORT_SYMBOL(acpi_evaluate_reference);
......
/*
* acpi_battery.c - ACPI Battery Driver ($Revision: 35 $)
* acpi_battery.c - ACPI Battery Driver ($Revision: 36 $)
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
......@@ -251,7 +251,7 @@ acpi_battery_set_alarm (
arg0.integer.value = alarm;
status = acpi_evaluate(battery->handle, "_BTP", &arg_list, NULL);
status = acpi_evaluate_object(battery->handle, "_BTP", &arg_list, NULL);
if (ACPI_FAILURE(status))
return_VALUE(-ENODEV);
......
/*
* pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 31 $)
* pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 33 $)
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
......@@ -110,6 +110,10 @@ acpi_pci_link_get_possible (
resource = (acpi_resource *) buffer.pointer;
/* skip past dependent function resource (if present) */
if (resource->id == ACPI_RSTYPE_START_DPF)
resource = ACPI_NEXT_RESOURCE(resource);
switch (resource->id) {
case ACPI_RSTYPE_IRQ:
{
......@@ -160,7 +164,7 @@ acpi_pci_link_get_possible (
"Found %d possible IRQs\n", link->irq.possible_count));
end:
kfree(buffer.pointer);
acpi_os_free(buffer.pointer);
return_VALUE(result);
}
......@@ -255,7 +259,7 @@ acpi_pci_link_get_current (
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active));
end:
kfree(buffer.pointer);
acpi_os_free(buffer.pointer);
return_VALUE(result);
}
......@@ -393,7 +397,7 @@ acpi_pci_link_check (void)
if (link->irq.active)
acpi_irq_penalty[link->irq.active] += 100;
else {
else if (link->irq.possible_count) {
int penalty = 100 / link->irq.possible_count;
for (i=0; i<link->irq.possible_count; i++) {
if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ)
......@@ -410,7 +414,7 @@ acpi_pci_link_check (void)
int i = 0;
link = list_entry(node, struct acpi_pci_link, node);
if (!link) {
if (!link || !link->irq.possible_count) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n"));
continue;
}
......@@ -435,8 +439,8 @@ acpi_pci_link_check (void)
acpi_irq_penalty[link->irq.active] += 100;
printk(PREFIX "%s [%s] enabled at IRQ %d\n",
acpi_device_name(link->device),
acpi_device_bid(link->device), irq);
acpi_device_name(link->device),
acpi_device_bid(link->device), link->irq.active);
}
return_VALUE(0);
......
/*
* pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 38 $)
* pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 39 $)
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
......@@ -154,7 +154,7 @@ acpi_pci_evaluate_crs (
root->mem_tra = acpi_pci_root_bus_tra ((acpi_resource *)
buffer.pointer, ACPI_MEMORY_RANGE);
kfree(buffer.pointer);
acpi_os_free(buffer.pointer);
return_VALUE(0);
}
......
/*
* acpi_power.c - ACPI Bus Power Management ($Revision: 37 $)
* acpi_power.c - ACPI Bus Power Management ($Revision: 38 $)
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
......@@ -186,7 +186,7 @@ acpi_power_on (
return_VALUE(0);
}
status = acpi_evaluate(resource->handle, "_ON", NULL, NULL);
status = acpi_evaluate_object(resource->handle, "_ON", NULL, NULL);
if (ACPI_FAILURE(status))
return_VALUE(-ENODEV);
......@@ -240,7 +240,7 @@ acpi_power_off (
return_VALUE(0);
}
status = acpi_evaluate(resource->handle, "_OFF", NULL, NULL);
status = acpi_evaluate_object(resource->handle, "_OFF", NULL, NULL);
if (ACPI_FAILURE(status))
return_VALUE(-ENODEV);
......
/*
* acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 39 $)
* acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 40 $)
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
......@@ -231,7 +231,7 @@ acpi_thermal_set_cooling_mode (
arg0.integer.value = mode;
status = acpi_evaluate(handle, NULL, &arg_list, NULL);
status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
if (ACPI_FAILURE(status))
return_VALUE(-ENODEV);
......
/*
* acpi_utils.c - ACPI Utility Functions ($Revision: 7 $)
* acpi_utils.c - ACPI Utility Functions ($Revision: 10 $)
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
......@@ -235,59 +235,6 @@ acpi_extract_package (
}
acpi_status
acpi_evaluate (
acpi_handle handle,
acpi_string pathname,
acpi_object_list *arguments,
acpi_buffer *buffer)
{
acpi_status status = AE_OK;
ACPI_FUNCTION_TRACE("acpi_evaluate");
/* If caller provided a buffer it must be unallocated/zero'd. */
if (buffer && (buffer->length != 0 || buffer->pointer))
return_ACPI_STATUS(AE_BAD_PARAMETER);
/*
* Evalute object. The first attempt is just to get the size of the
* object data (that is unless there's no return data); the second
* gets the data.
*/
status = acpi_evaluate_object(handle, pathname, arguments, buffer);
if (ACPI_SUCCESS(status)) {
return_ACPI_STATUS(status);
}
else if (buffer && (status == AE_BUFFER_OVERFLOW)) {
/* Gotta allocate - CALLER MUST FREE! */
buffer->pointer = kmalloc(buffer->length, GFP_KERNEL);
if (!buffer->pointer) {
return_ACPI_STATUS(AE_NO_MEMORY);
}
memset(buffer->pointer, 0, buffer->length);
/* Re-evaluate - this time it should work. */
status = acpi_evaluate_object(handle, pathname, arguments,
buffer);
}
if (ACPI_FAILURE(status)) {
if (status != AE_NOT_FOUND)
acpi_util_eval_error(handle, pathname, status);
if (buffer && buffer->pointer) {
kfree(buffer->pointer);
buffer->length = 0;
}
}
return_ACPI_STATUS(status);
}
acpi_status
acpi_evaluate_integer (
acpi_handle handle,
......@@ -366,6 +313,8 @@ acpi_evaluate_string (
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data));
acpi_os_free(buffer.pointer);
return_ACPI_STATUS(AE_OK);
}
#endif
......@@ -381,7 +330,7 @@ acpi_evaluate_reference (
acpi_status status = AE_OK;
acpi_object *package = NULL;
acpi_object *element = NULL;
acpi_buffer buffer = {0, NULL};
acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
u32 i = 0;
ACPI_FUNCTION_TRACE("acpi_evaluate_reference");
......@@ -392,42 +341,53 @@ acpi_evaluate_reference (
/* Evaluate object. */
status = acpi_evaluate(handle, pathname, arguments, &buffer);
status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
if (ACPI_FAILURE(status))
goto end;
package = (acpi_object *) buffer.pointer;
if (!package || (package->type != ACPI_TYPE_PACKAGE)
|| (package->package.count == 0)) {
if ((buffer.length == 0) || !package) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"No return object (len %X ptr %p)\n",
buffer.length, package));
status = AE_BAD_DATA;
acpi_util_eval_error(handle, pathname, status);
goto end;
}
if (package->type != ACPI_TYPE_PACKAGE) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Expecting a [Package], found type %X\n",
package->type));
status = AE_BAD_DATA;
acpi_util_eval_error(handle, pathname, status);
goto end;
}
if (!package->package.count) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"[Package] has zero elements (%p)\n",
package));
status = AE_BAD_DATA;
acpi_util_eval_error(handle, pathname, status);
goto end;
}
/* Allocate list - CALLER MUST FREE! */
list->count = package->package.count;
if (list->count > 10) {
if (package->package.count > ACPI_MAX_HANDLES) {
return AE_NO_MEMORY;
}
/* TBD: dynamically allocate */
/*
list->handles = kmalloc(sizeof(acpi_handle)*(list->count), GFP_KERNEL);
if (!list->handles) {
return_ACPI_STATUS(AE_NO_MEMORY);
}
memset(list->handles, 0, sizeof(acpi_handle)*(list->count));
*/
list->count = package->package.count;
/* Parse package data. */
/* Extract package data. */
for (i = 0; i < list->count; i++) {
element = &(package->package.elements[i]);
if (!element || (element->type != ACPI_TYPE_ANY)) {
if (element->type != ACPI_TYPE_ANY) {
status = AE_BAD_DATA;
ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid element in package (not a device reference)\n"));
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Expecting a [Reference] package element, found type %X\n",
element->type));
acpi_util_eval_error(handle, pathname, status);
break;
}
......@@ -435,7 +395,8 @@ acpi_evaluate_reference (
/* Get the acpi_handle. */
list->handles[i] = element->reference.handle;
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resolved reference [%s]->[%p]\n", element->string.pointer, list->handles[i]));
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found reference [%p]\n",
list->handles[i]));
}
end:
......@@ -444,7 +405,7 @@ acpi_evaluate_reference (
//kfree(list->handles);
}
kfree(buffer.pointer);
acpi_os_free(buffer.pointer);
return_ACPI_STATUS(status);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment