From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: linux-acpi@vger.kernel.org, rafael@kernel.org
Subject: Re: [PATCH v3 5/8] ACPI: property: Switch node property referencing from ifs to a switch
Date: Wed, 25 May 2022 20:30:19 +0300 [thread overview]
Message-ID: <Yo5nq1a7S1RgZg7f@smile.fi.intel.com> (raw)
In-Reply-To: <20220525130123.767410-6-sakari.ailus@linux.intel.com>
On Wed, May 25, 2022 at 04:01:20PM +0300, Sakari Ailus wrote:
> __acpi_node_get_property_reference() uses a series of if () statements for
> testing the same variable. There's soon going to be one more value to be
> tested.
>
> Switch to use switch() instead.
Looks like sanitization over the different parts of the code in this file.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
> drivers/acpi/property.c | 41 ++++++++++++++++++++++-------------------
> 1 file changed, 22 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
> index dd6cce955ee28..a8e8a214a524f 100644
> --- a/drivers/acpi/property.c
> +++ b/drivers/acpi/property.c
> @@ -780,11 +780,9 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
> if (ret)
> return ret == -EINVAL ? -ENOENT : -EINVAL;
>
> - /*
> - * The simplest case is when the value is a single reference. Just
> - * return that reference then.
> - */
> - if (obj->type == ACPI_TYPE_LOCAL_REFERENCE) {
> + switch (obj->type) {
> + case ACPI_TYPE_LOCAL_REFERENCE:
> + /* Plain single reference without arguments. */
> if (index)
> return -ENOENT;
>
> @@ -795,19 +793,21 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
> args->fwnode = acpi_fwnode_handle(device);
> args->nargs = 0;
> return 0;
> + case ACPI_TYPE_PACKAGE:
> + /*
> + * If it is not a single reference, then it is a package of
> + * references followed by number of ints as follows:
> + *
> + * Package () { REF, INT, REF, INT, INT }
> + *
> + * The index argument is then used to determine which reference
> + * the caller wants (along with the arguments).
> + */
> + break;
> + default:
> + return -EINVAL;
> }
>
> - /*
> - * If it is not a single reference, then it is a package of
> - * references followed by number of ints as follows:
> - *
> - * Package () { REF, INT, REF, INT, INT }
> - *
> - * The index argument is then used to determine which reference
> - * the caller wants (along with the arguments).
> - */
> - if (obj->type != ACPI_TYPE_PACKAGE)
> - return -EINVAL;
> if (index >= obj->package.count)
> return -ENOENT;
>
> @@ -815,7 +815,8 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
> end = element + obj->package.count;
>
> while (element < end) {
> - if (element->type == ACPI_TYPE_LOCAL_REFERENCE) {
> + switch (element->type) {
> + case ACPI_TYPE_LOCAL_REFERENCE:
> device = acpi_fetch_acpi_dev(element->reference.handle);
> if (!device)
> return -EINVAL;
> @@ -831,11 +832,13 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
> if (idx == index)
> return 0;
>
> - } else if (element->type == ACPI_TYPE_INTEGER) {
> + break;
> + case ACPI_TYPE_INTEGER:
> if (idx == index)
> return -ENOENT;
> element++;
> - } else {
> + break;
> + default:
> return -EINVAL;
> }
>
> --
> 2.30.2
>
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2022-05-25 17:46 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-25 13:01 [PATCH v3 0/8] ACPI: Buffer property and reference as string support Sakari Ailus
2022-05-25 13:01 ` [PATCH v3 1/8] ACPI: property: Return type of acpi_add_nondev_subnodes() should be bool Sakari Ailus
2022-05-25 17:15 ` Andy Shevchenko
2022-05-25 13:01 ` [PATCH v3 2/8] ACPI: property: Tie data nodes to acpi handles Sakari Ailus
2022-05-25 17:20 ` Andy Shevchenko
2022-05-27 14:35 ` Sakari Ailus
2022-05-26 19:19 ` Rafael J. Wysocki
2022-05-27 9:02 ` Sakari Ailus
2022-05-27 17:04 ` Rafael J. Wysocki
2022-05-27 20:59 ` Sakari Ailus
2022-05-28 13:56 ` Rafael J. Wysocki
2022-05-25 13:01 ` [PATCH v3 3/8] ACPI: property: Use acpi_object_type consistently in property ref parsing Sakari Ailus
2022-05-25 17:23 ` Andy Shevchenko
2022-05-25 13:01 ` [PATCH v3 4/8] ACPI: property: Move property ref argument parsing into a new function Sakari Ailus
2022-05-25 17:28 ` Andy Shevchenko
2022-05-27 14:37 ` Sakari Ailus
2022-05-25 13:01 ` [PATCH v3 5/8] ACPI: property: Switch node property referencing from ifs to a switch Sakari Ailus
2022-05-25 17:30 ` Andy Shevchenko [this message]
2022-05-25 13:01 ` [PATCH v3 6/8] ACPI: property: Unify integer value reading functions Sakari Ailus
2022-05-25 17:14 ` Andy Shevchenko
2022-05-27 15:12 ` Sakari Ailus
2022-05-25 13:01 ` [PATCH v3 7/8] ACPI: property: Add support for parsing buffer property UUID Sakari Ailus
2022-05-25 17:44 ` Andy Shevchenko
2022-05-27 12:43 ` Sakari Ailus
2022-05-25 13:01 ` [PATCH v3 8/8] ACPI: property: Read buffer properties as integers Sakari Ailus
2022-05-25 17:36 ` Andy Shevchenko
2022-05-27 10:01 ` Sakari Ailus
2022-06-09 18:38 ` [PATCH v3 0/8] ACPI: Buffer property and reference as string support 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=Yo5nq1a7S1RgZg7f@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sakari.ailus@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