Commit 87824da2 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

ACPI: utils: Rearrange in acpi_evaluate_reference()

The code in acpi_evaluate_reference() can be improved in some ways
without changing its observable behavior.  Among other things:

 * None of the local variables in that function except for buffer
   needs to be initialized.

 * The element local variable is only used in the for () loop block,
   so it can be defined there.

 * Multiple checks can be combined.

 * Code duplication related to error handling can be eliminated.

 * Redundant inner parens can be dropped.

Modify the function as per the above.

No intentional functional impact.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 38148764
...@@ -335,12 +335,10 @@ acpi_evaluate_reference(acpi_handle handle, ...@@ -335,12 +335,10 @@ acpi_evaluate_reference(acpi_handle handle,
struct acpi_object_list *arguments, struct acpi_object_list *arguments,
struct acpi_handle_list *list) struct acpi_handle_list *list)
{ {
acpi_status status = AE_OK;
union acpi_object *package = NULL;
union acpi_object *element = NULL;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
u32 i = 0; union acpi_object *package;
acpi_status status;
u32 i;
if (!list) if (!list)
return AE_BAD_PARAMETER; return AE_BAD_PARAMETER;
...@@ -353,45 +351,32 @@ acpi_evaluate_reference(acpi_handle handle, ...@@ -353,45 +351,32 @@ acpi_evaluate_reference(acpi_handle handle,
package = buffer.pointer; package = buffer.pointer;
if ((buffer.length == 0) || !package) { if (buffer.length == 0 || !package ||
status = AE_BAD_DATA; package->type != ACPI_TYPE_PACKAGE || !package->package.count) {
acpi_util_eval_error(handle, pathname, status);
goto end;
}
if (package->type != ACPI_TYPE_PACKAGE) {
status = AE_BAD_DATA; status = AE_BAD_DATA;
acpi_util_eval_error(handle, pathname, status); goto err;
goto end;
}
if (!package->package.count) {
status = AE_BAD_DATA;
acpi_util_eval_error(handle, pathname, status);
goto end;
} }
list->handles = kcalloc(package->package.count, sizeof(*list->handles), GFP_KERNEL); list->count = package->package.count;
list->handles = kcalloc(list->count, sizeof(*list->handles), GFP_KERNEL);
if (!list->handles) { if (!list->handles) {
kfree(package); status = AE_NO_MEMORY;
return AE_NO_MEMORY; goto err_clear;
} }
list->count = package->package.count;
/* Extract package data. */ /* Extract package data. */
for (i = 0; i < list->count; i++) { for (i = 0; i < list->count; i++) {
union acpi_object *element = &(package->package.elements[i]);
element = &(package->package.elements[i]);
if (element->type != ACPI_TYPE_LOCAL_REFERENCE) { if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
status = AE_BAD_DATA; status = AE_BAD_DATA;
acpi_util_eval_error(handle, pathname, status); goto err_free;
break;
} }
if (!element->reference.handle) { if (!element->reference.handle) {
status = AE_NULL_ENTRY; status = AE_NULL_ENTRY;
acpi_util_eval_error(handle, pathname, status); goto err_free;
break;
} }
/* Get the acpi_handle. */ /* Get the acpi_handle. */
...@@ -399,16 +384,21 @@ acpi_evaluate_reference(acpi_handle handle, ...@@ -399,16 +384,21 @@ acpi_evaluate_reference(acpi_handle handle,
acpi_handle_debug(list->handles[i], "Found in reference list\n"); acpi_handle_debug(list->handles[i], "Found in reference list\n");
} }
if (ACPI_FAILURE(status)) {
list->count = 0;
kfree(list->handles);
list->handles = NULL;
}
end: end:
kfree(buffer.pointer); kfree(buffer.pointer);
return status; return status;
err_free:
kfree(list->handles);
list->handles = NULL;
err_clear:
list->count = 0;
err:
acpi_util_eval_error(handle, pathname, status);
goto end;
} }
EXPORT_SYMBOL(acpi_evaluate_reference); EXPORT_SYMBOL(acpi_evaluate_reference);
......
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