From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-acpi@vger.kernel.org
Cc: rafael@kernel.org, andriy.shevchenko@intel.com
Subject: [PATCH 09/11] ACPI: property: Unify integer value reading functions
Date: Fri, 6 May 2022 16:00:23 +0300 [thread overview]
Message-ID: <20220506130025.984026-10-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20220506130025.984026-1-sakari.ailus@linux.intel.com>
Unify functions reading ACPI property integer values into a single macro,
and call that macro to generate the functions for each bit depth.
Also use size_t for the counter instead of int.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/acpi/property.c | 79 +++++++++++------------------------------
1 file changed, 20 insertions(+), 59 deletions(-)
diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 9325a9b2c0543..2205612fd6e98 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -985,67 +985,28 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data,
return ret;
}
-static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val,
- size_t nval)
-{
- int i;
-
- for (i = 0; i < nval; i++) {
- if (items[i].type != ACPI_TYPE_INTEGER)
- return -EPROTO;
- if (items[i].integer.value > U8_MAX)
- return -EOVERFLOW;
-
- val[i] = items[i].integer.value;
- }
- return 0;
-}
-
-static int acpi_copy_property_array_u16(const union acpi_object *items,
- u16 *val, size_t nval)
-{
- int i;
-
- for (i = 0; i < nval; i++) {
- if (items[i].type != ACPI_TYPE_INTEGER)
- return -EPROTO;
- if (items[i].integer.value > U16_MAX)
- return -EOVERFLOW;
-
- val[i] = items[i].integer.value;
- }
- return 0;
-}
-
-static int acpi_copy_property_array_u32(const union acpi_object *items,
- u32 *val, size_t nval)
-{
- int i;
-
- for (i = 0; i < nval; i++) {
- if (items[i].type != ACPI_TYPE_INTEGER)
- return -EPROTO;
- if (items[i].integer.value > U32_MAX)
- return -EOVERFLOW;
-
- val[i] = items[i].integer.value;
+#define DECLARE_ACPI_PROPERTY_COPY(bits) \
+ static int \
+ acpi_copy_property_array_u##bits(const union acpi_object *items, \
+ u##bits *val, size_t nval) \
+ { \
+ size_t i; \
+ \
+ for (i = 0; i < nval; i++) { \
+ if (items[i].type != ACPI_TYPE_INTEGER) \
+ return -EPROTO; \
+ if (items[i].integer.value > U##bits##_MAX) \
+ return -EOVERFLOW; \
+ \
+ val[i] = items[i].integer.value; \
+ } \
+ return 0; \
}
- return 0;
-}
-static int acpi_copy_property_array_u64(const union acpi_object *items,
- u64 *val, size_t nval)
-{
- int i;
-
- for (i = 0; i < nval; i++) {
- if (items[i].type != ACPI_TYPE_INTEGER)
- return -EPROTO;
-
- val[i] = items[i].integer.value;
- }
- return 0;
-}
+DECLARE_ACPI_PROPERTY_COPY(8)
+DECLARE_ACPI_PROPERTY_COPY(16)
+DECLARE_ACPI_PROPERTY_COPY(32)
+DECLARE_ACPI_PROPERTY_COPY(64)
static int acpi_copy_property_array_string(const union acpi_object *items,
char **val, size_t nval)
--
2.30.2
next prev parent reply other threads:[~2022-05-06 12:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-06 13:00 [PATCH 00/11] ACPI: Buffer property and reference as string support Sakari Ailus
2022-05-06 13:00 ` [PATCH 01/11] ACPI: property: Return type of acpi_add_nondev_subnodes() should be bool Sakari Ailus
2022-05-06 13:00 ` [PATCH 02/11] ACPI: acpica: Constify pathname argument for acpi_get_handle() Sakari Ailus
2022-05-17 16:21 ` Rafael J. Wysocki
2022-05-18 16:14 ` Sakari Ailus
2022-05-18 19:07 ` Rafael J. Wysocki
2022-05-18 19:41 ` Sakari Ailus
2022-05-19 18:05 ` Rafael J. Wysocki
2022-05-20 6:13 ` Sakari Ailus
2022-05-20 14:21 ` Shevchenko, Andriy
2022-05-06 13:00 ` [PATCH 03/11] ACPI: property: Tie data nodes to acpi handles Sakari Ailus
2022-05-06 13:00 ` [PATCH 04/11] ACPI: property: Use acpi_object_type consistently in property ref parsing Sakari Ailus
2022-05-06 13:00 ` [PATCH 05/11] ACPI: property: Move property ref argument parsing into a new function Sakari Ailus
2022-05-06 13:00 ` [PATCH 06/11] ACPI: property: Switch node property referencing from ifs to a switch Sakari Ailus
2022-05-06 13:00 ` [PATCH 07/11] ACPI: Initialise device child list early to access data nodes early Sakari Ailus
2022-05-06 13:28 ` Rafael J. Wysocki
2022-05-06 14:08 ` Sakari Ailus
2022-05-06 13:00 ` [PATCH 08/11] ACPI: property: Parse data node string references in properties Sakari Ailus
2022-05-06 13:00 ` Sakari Ailus [this message]
2022-05-06 13:00 ` [PATCH 10/11] ACPI: property: Add support for parsing buffer property UUID Sakari Ailus
2022-05-06 13:00 ` [PATCH 11/11] ACPI: property: Read buffer properties as integers Sakari Ailus
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=20220506130025.984026-10-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=andriy.shevchenko@intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=rafael@kernel.org \
/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