Skip to content

Commit 7dbec55

Browse files
acpibobrafaeljw
authored andcommitted
ACPICA: Refactor evaluate_object to reduce nesting
ACPICA commit 599e9159f53565e4a3f3e67f6a03f81fcb10a4cf Original patch from [email protected] ACPICA BZ 1072. Link: acpica/acpica@599e9159 Link: https://bugs.acpica.org/show_bug.cgi?id=1072 Original-by: Hanjun Guo <[email protected]> Signed-off-by: Bob Moore <[email protected]> Signed-off-by: Lv Zheng <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent f5c1e1c commit 7dbec55

File tree

1 file changed

+55
-56
lines changed

1 file changed

+55
-56
lines changed

drivers/acpi/acpica/nsxfeval.c

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,12 @@ acpi_evaluate_object(acpi_handle handle,
280280
info->parameters[info->param_count] = NULL;
281281
}
282282

283-
#if 0
283+
#ifdef _FUTURE_FEATURE
284284

285285
/*
286286
* Begin incoming argument count analysis. Check for too few args
287287
* and too many args.
288288
*/
289-
290289
switch (acpi_ns_get_type(info->node)) {
291290
case ACPI_TYPE_METHOD:
292291

@@ -370,68 +369,68 @@ acpi_evaluate_object(acpi_handle handle,
370369
* If we are expecting a return value, and all went well above,
371370
* copy the return value to an external object.
372371
*/
373-
if (return_buffer) {
374-
if (!info->return_object) {
375-
return_buffer->length = 0;
376-
} else {
377-
if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) ==
378-
ACPI_DESC_TYPE_NAMED) {
379-
/*
380-
* If we received a NS Node as a return object, this means that
381-
* the object we are evaluating has nothing interesting to
382-
* return (such as a mutex, etc.) We return an error because
383-
* these types are essentially unsupported by this interface.
384-
* We don't check up front because this makes it easier to add
385-
* support for various types at a later date if necessary.
386-
*/
387-
status = AE_TYPE;
388-
info->return_object = NULL; /* No need to delete a NS Node */
389-
return_buffer->length = 0;
390-
}
372+
if (!return_buffer) {
373+
goto cleanup_return_object;
374+
}
391375

392-
if (ACPI_SUCCESS(status)) {
376+
if (!info->return_object) {
377+
return_buffer->length = 0;
378+
goto cleanup;
379+
}
393380

394-
/* Dereference Index and ref_of references */
381+
if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) ==
382+
ACPI_DESC_TYPE_NAMED) {
383+
/*
384+
* If we received a NS Node as a return object, this means that
385+
* the object we are evaluating has nothing interesting to
386+
* return (such as a mutex, etc.) We return an error because
387+
* these types are essentially unsupported by this interface.
388+
* We don't check up front because this makes it easier to add
389+
* support for various types at a later date if necessary.
390+
*/
391+
status = AE_TYPE;
392+
info->return_object = NULL; /* No need to delete a NS Node */
393+
return_buffer->length = 0;
394+
}
395395

396-
acpi_ns_resolve_references(info);
396+
if (ACPI_FAILURE(status)) {
397+
goto cleanup_return_object;
398+
}
397399

398-
/* Get the size of the returned object */
400+
/* Dereference Index and ref_of references */
399401

400-
status =
401-
acpi_ut_get_object_size(info->return_object,
402-
&buffer_space_needed);
403-
if (ACPI_SUCCESS(status)) {
404-
405-
/* Validate/Allocate/Clear caller buffer */
406-
407-
status =
408-
acpi_ut_initialize_buffer
409-
(return_buffer,
410-
buffer_space_needed);
411-
if (ACPI_FAILURE(status)) {
412-
/*
413-
* Caller's buffer is too small or a new one can't
414-
* be allocated
415-
*/
416-
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
417-
"Needed buffer size %X, %s\n",
418-
(u32)
419-
buffer_space_needed,
420-
acpi_format_exception
421-
(status)));
422-
} else {
423-
/* We have enough space for the object, build it */
424-
425-
status =
426-
acpi_ut_copy_iobject_to_eobject
427-
(info->return_object,
428-
return_buffer);
429-
}
430-
}
431-
}
402+
acpi_ns_resolve_references(info);
403+
404+
/* Get the size of the returned object */
405+
406+
status = acpi_ut_get_object_size(info->return_object,
407+
&buffer_space_needed);
408+
if (ACPI_SUCCESS(status)) {
409+
410+
/* Validate/Allocate/Clear caller buffer */
411+
412+
status = acpi_ut_initialize_buffer(return_buffer,
413+
buffer_space_needed);
414+
if (ACPI_FAILURE(status)) {
415+
/*
416+
* Caller's buffer is too small or a new one can't
417+
* be allocated
418+
*/
419+
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
420+
"Needed buffer size %X, %s\n",
421+
(u32)buffer_space_needed,
422+
acpi_format_exception(status)));
423+
} else {
424+
/* We have enough space for the object, build it */
425+
426+
status =
427+
acpi_ut_copy_iobject_to_eobject(info->return_object,
428+
return_buffer);
432429
}
433430
}
434431

432+
cleanup_return_object:
433+
435434
if (info->return_object) {
436435
/*
437436
* Delete the internal return object. NOTE: Interpreter must be

0 commit comments

Comments
 (0)