From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Hans de Goede <hdegoede@redhat.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH v1 1/4] ACPI: utils: Rearrange in acpi_evaluate_reference()
Date: Fri, 08 Dec 2023 21:05:19 +0100 [thread overview]
Message-ID: <4541600.LvFx2qVVIh@kreacher> (raw)
In-Reply-To: <6008018.lOV4Wx5bFT@kreacher>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
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>
---
drivers/acpi/utils.c | 58 +++++++++++++++++++++------------------------------
1 file changed, 24 insertions(+), 34 deletions(-)
Index: linux-pm/drivers/acpi/utils.c
===================================================================
--- linux-pm.orig/drivers/acpi/utils.c
+++ linux-pm/drivers/acpi/utils.c
@@ -335,12 +335,10 @@ acpi_evaluate_reference(acpi_handle hand
struct acpi_object_list *arguments,
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 };
- u32 i = 0;
-
+ union acpi_object *package;
+ acpi_status status;
+ u32 i;
if (!list)
return AE_BAD_PARAMETER;
@@ -353,45 +351,32 @@ acpi_evaluate_reference(acpi_handle hand
package = buffer.pointer;
- if ((buffer.length == 0) || !package) {
- status = AE_BAD_DATA;
- acpi_util_eval_error(handle, pathname, status);
- goto end;
- }
- if (package->type != ACPI_TYPE_PACKAGE) {
- status = AE_BAD_DATA;
- acpi_util_eval_error(handle, pathname, status);
- goto end;
- }
- if (!package->package.count) {
+ if (buffer.length == 0 || !package ||
+ package->type != ACPI_TYPE_PACKAGE || !package->package.count) {
status = AE_BAD_DATA;
- acpi_util_eval_error(handle, pathname, status);
- goto end;
+ goto err;
}
- 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) {
- kfree(package);
- return AE_NO_MEMORY;
+ status = AE_NO_MEMORY;
+ goto err_clear;
}
- list->count = package->package.count;
/* Extract package data. */
for (i = 0; i < list->count; i++) {
-
- element = &(package->package.elements[i]);
+ union acpi_object *element = &(package->package.elements[i]);
if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
status = AE_BAD_DATA;
- acpi_util_eval_error(handle, pathname, status);
- break;
+ goto err_free;
}
if (!element->reference.handle) {
status = AE_NULL_ENTRY;
- acpi_util_eval_error(handle, pathname, status);
- break;
+ goto err_free;
}
/* Get the acpi_handle. */
@@ -399,16 +384,21 @@ acpi_evaluate_reference(acpi_handle hand
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:
kfree(buffer.pointer);
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);
next prev parent reply other threads:[~2023-12-08 20:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-08 20:03 [PATCH v1 0/4] ACPI: utils: Improvements related to struct acpi_handle_list Rafael J. Wysocki
2023-12-08 20:05 ` Rafael J. Wysocki [this message]
2023-12-08 20:06 ` [PATCH v1 2/4] ACPI: utils: Return bool from acpi_evaluate_reference() Rafael J. Wysocki
2023-12-08 20:06 ` [PATCH v1 3/4] ACPI: utils: Refine acpi_handle_list_equal() slightly Rafael J. Wysocki
2023-12-08 20:07 ` [PATCH v1 4/4] ACPI: utils: Fix white space in struct acpi_handle_list definition Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4541600.LvFx2qVVIh@kreacher \
--to=rjw@rjwysocki.net \
--cc=andriy.shevchenko@linux.intel.com \
--cc=hdegoede@redhat.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox