Skip to content

Commit 87824da

Browse files
committed
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: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 3814876 commit 87824da

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

drivers/acpi/utils.c

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,10 @@ acpi_evaluate_reference(acpi_handle handle,
335335
struct acpi_object_list *arguments,
336336
struct acpi_handle_list *list)
337337
{
338-
acpi_status status = AE_OK;
339-
union acpi_object *package = NULL;
340-
union acpi_object *element = NULL;
341338
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
342-
u32 i = 0;
343-
339+
union acpi_object *package;
340+
acpi_status status;
341+
u32 i;
344342

345343
if (!list)
346344
return AE_BAD_PARAMETER;
@@ -353,62 +351,54 @@ acpi_evaluate_reference(acpi_handle handle,
353351

354352
package = buffer.pointer;
355353

356-
if ((buffer.length == 0) || !package) {
357-
status = AE_BAD_DATA;
358-
acpi_util_eval_error(handle, pathname, status);
359-
goto end;
360-
}
361-
if (package->type != ACPI_TYPE_PACKAGE) {
354+
if (buffer.length == 0 || !package ||
355+
package->type != ACPI_TYPE_PACKAGE || !package->package.count) {
362356
status = AE_BAD_DATA;
363-
acpi_util_eval_error(handle, pathname, status);
364-
goto end;
365-
}
366-
if (!package->package.count) {
367-
status = AE_BAD_DATA;
368-
acpi_util_eval_error(handle, pathname, status);
369-
goto end;
357+
goto err;
370358
}
371359

372-
list->handles = kcalloc(package->package.count, sizeof(*list->handles), GFP_KERNEL);
360+
list->count = package->package.count;
361+
list->handles = kcalloc(list->count, sizeof(*list->handles), GFP_KERNEL);
373362
if (!list->handles) {
374-
kfree(package);
375-
return AE_NO_MEMORY;
363+
status = AE_NO_MEMORY;
364+
goto err_clear;
376365
}
377-
list->count = package->package.count;
378366

379367
/* Extract package data. */
380368

381369
for (i = 0; i < list->count; i++) {
382-
383-
element = &(package->package.elements[i]);
370+
union acpi_object *element = &(package->package.elements[i]);
384371

385372
if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
386373
status = AE_BAD_DATA;
387-
acpi_util_eval_error(handle, pathname, status);
388-
break;
374+
goto err_free;
389375
}
390376

391377
if (!element->reference.handle) {
392378
status = AE_NULL_ENTRY;
393-
acpi_util_eval_error(handle, pathname, status);
394-
break;
379+
goto err_free;
395380
}
396381
/* Get the acpi_handle. */
397382

398383
list->handles[i] = element->reference.handle;
399384
acpi_handle_debug(list->handles[i], "Found in reference list\n");
400385
}
401386

402-
if (ACPI_FAILURE(status)) {
403-
list->count = 0;
404-
kfree(list->handles);
405-
list->handles = NULL;
406-
}
407-
408387
end:
409388
kfree(buffer.pointer);
410389

411390
return status;
391+
392+
err_free:
393+
kfree(list->handles);
394+
list->handles = NULL;
395+
396+
err_clear:
397+
list->count = 0;
398+
399+
err:
400+
acpi_util_eval_error(handle, pathname, status);
401+
goto end;
412402
}
413403

414404
EXPORT_SYMBOL(acpi_evaluate_reference);

0 commit comments

Comments
 (0)