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: 23679 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 778F120307 for ; Fri, 24 Jan 2014 16:20:49 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id gq1sf11829288obb.8 for ; Fri, 24 Jan 2014 08:20:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=NCqnfI5wTa7H0fo+meFR+zcVfhJBsTcw0gQ8NcDt7F8=; b=T76//TS9uF5iid0XAnb+puKW7T37ZSszrevtQrW+WU0hizqZiKdJQBiHP6IsLjzpor eC+e4JOHnNeOC3IjcwP5e/7Fj77Z2eGccu/4P+0zv6i2g/PO8hnNV5n7JyXr/RlW8ZAv rQT9l66xEflhG8WP1DAvpKXTb7psG5rUVxRRqlzmQ2z2JH9VqbeWGHjrLrsxaiL6A3YN g+qa21bqh9iVyKjxwV23Aq7RtTSQpzpfUoCjW5fpxRmkVd6nqF6Dc1XJvod8qipG3hHl BPPVV7ulCMl04H254u6Th8LCLrgi3A6iWIj6FewLPHMgEosxqPECcKA/+VOeNhDQQvKe sHcA== X-Gm-Message-State: ALoCoQknVgR1u610+F+Mt3sreMSBC+gkMyza2euYR+GMUADcjMpF5ANb3IcNrE4rGgmUF7dAup8y X-Received: by 10.182.22.133 with SMTP id d5mr5640787obf.27.1390580448538; Fri, 24 Jan 2014 08:20:48 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.16.145 with SMTP id 17ls653572qgb.58.gmail; Fri, 24 Jan 2014 08:20:48 -0800 (PST) X-Received: by 10.220.161.132 with SMTP id r4mr8050135vcx.29.1390580448408; Fri, 24 Jan 2014 08:20:48 -0800 (PST) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by mx.google.com with ESMTPS id gq1si781246vec.61.2014.01.24.08.20.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 08:20:48 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.50; Received: by mail-vb0-f50.google.com with SMTP id w8so1986367vbj.37 for ; Fri, 24 Jan 2014 08:20:48 -0800 (PST) X-Received: by 10.220.98.204 with SMTP id r12mr46391vcn.48.1390580448317; Fri, 24 Jan 2014 08:20:48 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp114089vcz; Fri, 24 Jan 2014 08:20:47 -0800 (PST) X-Received: by 10.68.194.71 with SMTP id hu7mr15319628pbc.68.1390580447372; Fri, 24 Jan 2014 08:20:47 -0800 (PST) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) by mx.google.com with ESMTPS id x3si1681459pbf.211.2014.01.24.08.20.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 08:20:47 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.53 is neither permitted nor denied by best guess record for domain of hanjun.guo@linaro.org) client-ip=209.85.160.53; Received: by mail-pb0-f53.google.com with SMTP id md12so3402528pbc.26 for ; Fri, 24 Jan 2014 08:20:46 -0800 (PST) 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 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: hanjun.guo@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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