From patchwork Fri Jan 24 16:20:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 3535311 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8E1D09F1C3 for ; Fri, 24 Jan 2014 16:21:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 09F6E2016C for ; Fri, 24 Jan 2014 16:21:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB00120131 for ; Fri, 24 Jan 2014 16:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752843AbaAXQUr (ORCPT ); Fri, 24 Jan 2014 11:20:47 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:52662 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751815AbaAXQUq (ORCPT ); Fri, 24 Jan 2014 11:20:46 -0500 Received: by mail-pa0-f50.google.com with SMTP id kp14so3434258pab.23 for ; Fri, 24 Jan 2014 08:20:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NCqnfI5wTa7H0fo+meFR+zcVfhJBsTcw0gQ8NcDt7F8=; b=ga27hqcta89KPiE8Tgotj6uPOmIFKZiCgQlGP7dxrletAH+MZsKYhpKTDRK9g0+inA cw4gYLcYJwKxbODE0PJQltEdG0PMLRld3raOqs6UDW/oiWpoBs/bdIXKX+uqkhQOBh/B 4Cu5AFl4w1otLrLl4qhYJkDvyfoRB8N1e3Rj3z/Gj5CFz59oSSuHdPL36/b2CxDDDzjD hO9UDcs5lcZNZRHLOHY5gZuQmkYBvf04SbE9Jx8yEMj35/5gCEsaFDlodRPbJR4LWXza uC4j7fkpkCwrZFF299Htn3Hx/ZoIaCVbHFZCOcblkvj0NipecUYd5pdTZ+Om4J3NzIVW Ba5g== X-Gm-Message-State: ALoCoQmaDBprmnE1NZ2bsBJB7G8Emd5d5cZlmv91UAugClfCoqHce9lSqIqRTT6Kd3obzW3c4TEA X-Received: by 10.66.161.38 with SMTP id xp6mr15106393pab.145.1390580446443; Fri, 24 Jan 2014 08:20:46 -0800 (PST) Received: from localhost ([39.181.43.174]) by mx.google.com with ESMTPSA id xv2sm4459287pbb.39.2014.01.24.08.20.43 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 24 Jan 2014 08:20:45 -0800 (PST) From: Hanjun Guo To: Lv Zheng , Robert Moore Cc: "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, devel@acpica.org, patches@linaro.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, Hanjun Guo Subject: [PATCH 1/2] ACPI / ACPICA: refactor acpi_evaluate_object() to reduce nesting if Date: Sat, 25 Jan 2014 00:20:06 +0800 Message-Id: <1390580407-14525-1-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP acpi_evaluate_object() has nesting if judgement to make code a little bit complicated, refactor it to make things simple. Signed-off-by: Hanjun Guo --- drivers/acpi/acpica/nsxfeval.c | 104 +++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 54 deletions(-) diff --git a/drivers/acpi/acpica/nsxfeval.c b/drivers/acpi/acpica/nsxfeval.c index 1f0c28b..a1b0b88 100644 --- a/drivers/acpi/acpica/nsxfeval.c +++ b/drivers/acpi/acpica/nsxfeval.c @@ -370,68 +370,64 @@ acpi_evaluate_object(acpi_handle handle, * If we are expecting a return value, and all went well above, * copy the return value to an external object. */ - if (return_buffer) { - if (!info->return_object) { - return_buffer->length = 0; - } else { - if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) == - ACPI_DESC_TYPE_NAMED) { - /* - * If we received a NS Node as a return object, this means that - * the object we are evaluating has nothing interesting to - * return (such as a mutex, etc.) We return an error because - * these types are essentially unsupported by this interface. - * We don't check up front because this makes it easier to add - * support for various types at a later date if necessary. - */ - status = AE_TYPE; - info->return_object = NULL; /* No need to delete a NS Node */ - return_buffer->length = 0; - } + if (!return_buffer) + goto out; - if (ACPI_SUCCESS(status)) { + if (!info->return_object) { + return_buffer->length = 0; + goto out; + } - /* Dereference Index and ref_of references */ + if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) == + ACPI_DESC_TYPE_NAMED) { + /* + * If we received a NS Node as a return object, this means that + * the object we are evaluating has nothing interesting to + * return (such as a mutex, etc.) We return an error because + * these types are essentially unsupported by this interface. + * We don't check up front because this makes it easier to add + * support for various types at a later date if necessary. + */ + status = AE_TYPE; + info->return_object = NULL; /* No need to delete a NS Node */ + return_buffer->length = 0; + } - acpi_ns_resolve_references(info); + if (ACPI_FAILURE(status)) + goto out; - /* Get the size of the returned object */ + /* Dereference Index and ref_of references */ - status = - acpi_ut_get_object_size(info->return_object, - &buffer_space_needed); - if (ACPI_SUCCESS(status)) { - - /* Validate/Allocate/Clear caller buffer */ - - status = - acpi_ut_initialize_buffer - (return_buffer, - buffer_space_needed); - if (ACPI_FAILURE(status)) { - /* - * Caller's buffer is too small or a new one can't - * be allocated - */ - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "Needed buffer size %X, %s\n", - (u32) - buffer_space_needed, - acpi_format_exception - (status))); - } else { - /* We have enough space for the object, build it */ - - status = - acpi_ut_copy_iobject_to_eobject - (info->return_object, - return_buffer); - } - } - } + acpi_ns_resolve_references(info); + + /* Get the size of the returned object */ + + status = acpi_ut_get_object_size(info->return_object, + &buffer_space_needed); + if (ACPI_SUCCESS(status)) { + + /* Validate/Allocate/Clear caller buffer */ + + status = acpi_ut_initialize_buffer(return_buffer, + buffer_space_needed); + if (ACPI_FAILURE(status)) { + /* + * Caller's buffer is too small or a new one can't + * be allocated + */ + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "Needed buffer size %X, %s\n", + (u32)buffer_space_needed, + acpi_format_exception(status))); + } else { + /* We have enough space for the object, build it */ + + status = acpi_ut_copy_iobject_to_eobject( + info->return_object, return_buffer); } } +out: if (info->return_object) { /* * Delete the internal return object. NOTE: Interpreter must be