mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 22:21:40 +00:00
ACPI: property: Unify integer value reading functions
Unify functions reading ACPI property integer values into a single macro using C99 _Generic(). Also use size_t for the counter instead of int. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
88af7bbdea
commit
9230441333
@ -908,67 +908,33 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val,
|
#define acpi_copy_property_array_uint(items, val, nval) \
|
||||||
size_t nval)
|
({ \
|
||||||
{
|
typeof(items) __items = items; \
|
||||||
int i;
|
typeof(val) __val = val; \
|
||||||
|
typeof(nval) __nval = nval; \
|
||||||
for (i = 0; i < nval; i++) {
|
size_t i; \
|
||||||
if (items[i].type != ACPI_TYPE_INTEGER)
|
int ret = 0; \
|
||||||
return -EPROTO;
|
\
|
||||||
if (items[i].integer.value > U8_MAX)
|
for (i = 0; i < __nval; i++) { \
|
||||||
return -EOVERFLOW;
|
if (__items[i].type != ACPI_TYPE_INTEGER) { \
|
||||||
|
ret = -EPROTO; \
|
||||||
val[i] = items[i].integer.value;
|
break; \
|
||||||
}
|
} \
|
||||||
return 0;
|
if (__items[i].integer.value > _Generic(__val, \
|
||||||
}
|
u8: U8_MAX, \
|
||||||
|
u16: U16_MAX, \
|
||||||
static int acpi_copy_property_array_u16(const union acpi_object *items,
|
u32: U32_MAX, \
|
||||||
u16 *val, size_t nval)
|
u64: U64_MAX, \
|
||||||
{
|
default: 0U)) { \
|
||||||
int i;
|
ret = -EOVERFLOW; \
|
||||||
|
break; \
|
||||||
for (i = 0; i < nval; i++) {
|
} \
|
||||||
if (items[i].type != ACPI_TYPE_INTEGER)
|
\
|
||||||
return -EPROTO;
|
__val[i] = __items[i].integer.value; \
|
||||||
if (items[i].integer.value > U16_MAX)
|
} \
|
||||||
return -EOVERFLOW;
|
ret; \
|
||||||
|
})
|
||||||
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;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int acpi_copy_property_array_string(const union acpi_object *items,
|
static int acpi_copy_property_array_string(const union acpi_object *items,
|
||||||
char **val, size_t nval)
|
char **val, size_t nval)
|
||||||
@ -1025,16 +991,16 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
|
|||||||
|
|
||||||
switch (proptype) {
|
switch (proptype) {
|
||||||
case DEV_PROP_U8:
|
case DEV_PROP_U8:
|
||||||
ret = acpi_copy_property_array_u8(items, (u8 *)val, nval);
|
ret = acpi_copy_property_array_uint(items, (u8 *)val, nval);
|
||||||
break;
|
break;
|
||||||
case DEV_PROP_U16:
|
case DEV_PROP_U16:
|
||||||
ret = acpi_copy_property_array_u16(items, (u16 *)val, nval);
|
ret = acpi_copy_property_array_uint(items, (u16 *)val, nval);
|
||||||
break;
|
break;
|
||||||
case DEV_PROP_U32:
|
case DEV_PROP_U32:
|
||||||
ret = acpi_copy_property_array_u32(items, (u32 *)val, nval);
|
ret = acpi_copy_property_array_uint(items, (u32 *)val, nval);
|
||||||
break;
|
break;
|
||||||
case DEV_PROP_U64:
|
case DEV_PROP_U64:
|
||||||
ret = acpi_copy_property_array_u64(items, (u64 *)val, nval);
|
ret = acpi_copy_property_array_uint(items, (u64 *)val, nval);
|
||||||
break;
|
break;
|
||||||
case DEV_PROP_STRING:
|
case DEV_PROP_STRING:
|
||||||
ret = acpi_copy_property_array_string(
|
ret = acpi_copy_property_array_string(
|
||||||
|
Loading…
Reference in New Issue
Block a user