From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Len Brown <lenb@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 5/7] ACPI: property: Refactor acpi_data_prop_read_single()
Date: Wed, 10 Feb 2021 13:43:18 +0200 [thread overview]
Message-ID: <20210210114320.3478-5-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20210210114320.3478-1-andriy.shevchenko@linux.intel.com>
Refactor acpi_data_prop_read_single() for less LOCs and better maintenance.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/acpi/property.c | 59 +++++++++++++++++++----------------------
1 file changed, 28 insertions(+), 31 deletions(-)
diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 167338fe9b04..f2386ef32ff1 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -785,47 +785,44 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data,
enum dev_prop_type proptype, void *val)
{
const union acpi_object *obj;
- int ret;
+ int ret = 0;
if (!val)
return -EINVAL;
- if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
+ if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64)
ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
- if (ret)
- return ret;
-
- switch (proptype) {
- case DEV_PROP_U8:
- if (obj->integer.value > U8_MAX)
- return -EOVERFLOW;
- *(u8 *)val = obj->integer.value;
- break;
- case DEV_PROP_U16:
- if (obj->integer.value > U16_MAX)
- return -EOVERFLOW;
- *(u16 *)val = obj->integer.value;
- break;
- case DEV_PROP_U32:
- if (obj->integer.value > U32_MAX)
- return -EOVERFLOW;
- *(u32 *)val = obj->integer.value;
- break;
- default:
- *(u64 *)val = obj->integer.value;
- break;
- }
- } else if (proptype == DEV_PROP_STRING) {
+ else if (proptype == DEV_PROP_STRING)
ret = acpi_data_get_property(data, propname, ACPI_TYPE_STRING, &obj);
- if (ret)
- return ret;
+ if (ret)
+ return ret;
+ switch (proptype) {
+ case DEV_PROP_U8:
+ if (obj->integer.value > U8_MAX)
+ return -EOVERFLOW;
+ *(u8 *)val = obj->integer.value;
+ break;
+ case DEV_PROP_U16:
+ if (obj->integer.value > U16_MAX)
+ return -EOVERFLOW;
+ *(u16 *)val = obj->integer.value;
+ break;
+ case DEV_PROP_U32:
+ if (obj->integer.value > U32_MAX)
+ return -EOVERFLOW;
+ *(u32 *)val = obj->integer.value;
+ break;
+ case DEV_PROP_U64:
+ *(u64 *)val = obj->integer.value;
+ break;
+ case DEV_PROP_STRING:
*(char **)val = obj->string.pointer;
-
return 1;
- } else {
- ret = -EINVAL;
+ default:
+ return -EINVAL;
}
+
return ret;
}
--
2.30.0
next prev parent reply other threads:[~2021-02-10 11:48 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-10 11:43 [PATCH v1 1/7] ACPI: property: Remove dead code Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 2/7] ACPI: property: Make acpi_node_prop_read() static Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 3/7] ACPI: property: Satisfy kernel doc validator (part 1) Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 4/7] ACPI: property: Satisfy kernel doc validator (part 2) Andy Shevchenko
2021-02-10 11:43 ` Andy Shevchenko [this message]
2021-02-10 11:43 ` [PATCH v1 6/7] ACPI: property: Allow to validate a single value Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element Andy Shevchenko
2021-02-10 12:36 ` Rafael J. Wysocki
2021-02-10 13:31 ` Rafael J. Wysocki
2021-02-10 13:48 ` Rafael J. Wysocki
2021-02-10 14:48 ` Andy Shevchenko
2021-02-10 15:01 ` Rafael J. Wysocki
2021-02-10 15:41 ` Andy Shevchenko
2021-02-10 15:44 ` Rafael J. Wysocki
2021-02-11 15:42 ` Andy Shevchenko
2021-02-11 16:39 ` 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=20210210114320.3478-5-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rjw@rjwysocki.net \
/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;
as well as URLs for NNTP newsgroup(s).